使用 babel-plugin-transform-remove-console 插件
参考 https://forum.vuejs.org/t/remove-console-logs-from-production-buils/39327
安装依赖库
$ npm install babel-plugin-transform-remove-console --save-dev
如果使用的是 vue-cli 3,修改 babel.config.js 配置
const removeConsolePlugin = []
if(process.env.NODE_ENV === 'production') {
removeConsolePlugin.push("transform-remove-console")
}
module.exports = {
presets: [
'@vue/app'
],
plugins: removeConsolePlugin
}
本文介绍了如何在使用 Vue CLI 3 构建的项目中,通过 babel-plugin-transform-remove-console 插件移除生产环境中的 console.log 以优化性能。步骤包括安装依赖并配置 .babelrc 文件以根据环境切换插件启用状态。
1488

被折叠的 条评论
为什么被折叠?



