一、babel-plugin-transform-remove-console
1.先下载
npm install babel-plugin-transform-remove-console --save-dev
2. 在 babel.consig.js 中配置
if (process.env.NODE_ENV === "production" || process.env.NODE_ENV === "sit") {
plugins.push("transform-remove-console");
}
二、terser-webpack-plugin
1.先下载
npm install terser-webpack-plugin --save-dev
2. vue.config.js 中引入
const TerserPlugin = require("terser-webpack-plugin");
config.plugins.push(
//去掉打包之后的打印
new TerserPlugin({
terserOptions: {
ecma: undefined,
warnings: false,
parse: {},
compress: {
drop_console: true,
drop_debugger: false,
pure_funcs: ["console.log"], // 移除console
},
},
})
);