在babel.config.js文件中添加’transform-remove-console’
全局使用(开发,发布都使用)
module.exports = {
"presets": [
"@vue/app"
],
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
],
'transform-remove-console'
]
}
在发布阶段使用babel-plugin-transform-remove-console
//这是项目发布阶段需要用到的babel插件
const prodPlugins = [];
if (process.env.NODE_ENV === 'production') {
prodPlugins.push('transform-remove-console')
}
module.exports = {
"presets": [
"@vue/app"
],
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
],
//展开运算符,在一个数组中插入另一个数组
//发布产品时的插件数组
...prodPlugins,
]
}
在项目构建过程中,通过在babel.config.js配置'babel-plugin-transform-remove-console'插件,可以有效地移除console.log()等警告。该插件支持全局使用,适用于开发和发布的不同阶段,尤其在发布阶段,能确保生产环境中无console.log()输出。
1490

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



