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; #靜態壓縮
}