生产环境配置:
1.压缩代码:
// 代码压缩
uglifyjs-webpack-plugin
2.压缩js
compression-webpack-plugin
3.压缩css
compression-webpack-plugin
4.压缩图片
image-webpack-loader
5.去除console
config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
6.去除debugger
config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true
7.开启gzip
compression-webpack-plugin
8.配置cdn
9.公共代码抽离
10.使用cdn的vue.min.js
11.去除map文件
productionSourceMap设置为false
安装插件:
1.代码压缩:
npm install uglifyjs-webpack-plugin --save-dev
1.压缩图片插件:
npm install image-webpack-loader -D 依赖 npm install gifsicle -D
2.gzip压缩:
npm i webpack-image-compression