【发布时间】:2020-02-07 00:17:32
【问题描述】:
我正在使用 VUE CLI 3,我需要从构建的产品中删除 console.log 和 code cmets。这是我的Terser 设置:
webpack.config.js 在 src 文件夹中
module.exports = {
mode: 'production',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
ecma: undefined,
warnings: false,
parse: {},
compress: {drop_debugger},
mangle: true, // Note `mangle.properties` is `false` by default.
module: false,
output: null,
toplevel: false,
nameCache: null,
ie8: false,
keep_classnames: undefined,
keep_fnames: false,
safari10: false,
},
}),
],
},
};
我的生产工作流程:运行npm run build -> cd dist -> npm run serve
生产版本仍会输出所有 console.log 语句并显示代码 cmets (<!-- -->)。
我需要更改哪些内容才能删除它们?
【问题讨论】:
-
尝试:terserOptions: { ecma: 6, compress: { drop_console: true }, 输出: { cmets: false, beautify: false } }
-
@JeffProd 刚刚尝试过,但我收到了相同的结果。 console.log 和 cmets 在输出中仍然可见。有什么想法吗?
-
npm run serve 运行开发构建,不是吗? Terser 仅适用于生产版本。
-
@madflow 这可以解释很多。我正在 dist 构建上运行 npm run build -> npm run serve。在分发之前测试 dist 构建的正确命令是什么? (npm run build 正在设置 生产模式 对吗?)
-
答案如下:)
标签: vue.js webpack build vue-cli-3 terser