vue項目打包壓縮

vue項目打包壓縮

vue-cli-service build --report 打包完成會產生report.html 通過這個文件可以得知項目體積以及個個依賴大小,打包完成後開啓nginx壓縮

安裝壓縮包 npm i compression-webpack-plugin -D

vue.config.js裏配置

configureWebpack: config => {

if (process.env.NODE_ENV === 'production') {

return {

plugins: [ new CompressionPlugin({

test: /.js$|.html$|\css|.jpg$|.png/, // 匹配文件名

threshold: 10240, // 對超過10k的文件進行壓縮

deleteOriginalAssets: true // 是否刪除原文件

})]

}

}

},

nginx 裏面配置

location / {

root html\web;

index index.html;

gzip_static on; #靜態壓縮

}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章