我使用的是VUE CLI 3,我需要从构建的产品中删除console.log和代码注释。这是我的特塞尔设置:
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语句,并显示代码注释(<!-- -->)。我需要改变什么才能移除它们?
发布于 2019-10-10 11:16:13
首先:确保正确配置特塞尔:
terserOptions: {
ecma: 6,
compress: { drop_console: true },
output: { comments: false, beautify: false }
}npm run serve
通常是以下方面的捷径:
vue-cli-service
vue-cli-service --help
Usage: vue-cli-service <command> [options]
Commands:
serve start development server
build build for production
inspect inspect internal webpack config
lint lint and fix source files因此,当您的工作流是上面提到的npm run build -> cd dist -> npm run serve时,您实际上是在启动开发服务器,它不应用Terser。
为了运行生产构建,您可以使用任何能够提供静态内容的网路伺服器:
NodeJs示例:
npm install -g serve
serve -s dist或
npm install -g node-static
static disthttps://stackoverflow.com/questions/58307891
复制相似问题