1、安装UglifyJsPlugin:
npm install UglifyJsPlugin --save -dev
2、在vue.config.js中引入:
// 代码压缩
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
3、在configureWebpack中配置:
configureWebpack: {// 代码压缩plugins: [new UglifyJsPlugin({uglifyOptions: {//生产环境自动删除consolecompress: {drop_debugger: true,drop_console: true,pure_funcs: ['console.log']}},sourceMap: false,parallel: true})]
}
压缩代码完毕!