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; #静态压缩

}

 

 

posted @ 2021-12-12 15:04  王小美丶  阅读(1093)  评论(0编辑  收藏  举报