踩坑记录:注意 terser-webpack-plugin": "^4.2.3" 对应着webpack4及版本一下的,5点多版本的对应webpack5,版本不对会报ERROR TypeError: Cannot read property 'javascript' of undefined
1.安装三方包
npm install terser-webpack-plugin2.在vue.config.js中配置
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {configureWebpack: {optimization: {minimize: true,//为了不影响dev时的构建速度minimizer: [new TerserPlugin({parallel: true,//使用多进程并发运行以提高构建速度 Boolean|Number 默认值: true terserOptions: {compress: {drop_console: true,//移除所有console相关代码;drop_debugger: true,//移除自动断点功能;pure_funcs: ["console.log", "console.error"],//配置移除指定的指令,如console.log,alert等},format: {comments: false,//删除注释},},extractComments: false,//是否将注释剥离到单独的文件中})]}}
}