优化——在执行build命令期间移除所有的console
插件:bal-plugin-transfrom-remove-console’
官网:https://www.npmjs.com/package/babel-plugin-transform-remove-console
1、安装:npm install babel-plugin-transform-remove-console --save-dev
2、在babel.config.js的plugins中配置"transform-remove-console"
plugins: [
[
'component',
{
libraryName: 'element-ui',
styleLibraryName: 'theme-chalk'
}
],
'transform-remove-console'
]
3、在项目开发阶段移除会影响开发,因此设置只在发布阶段移除
// 这是项目发布阶段需要用到的babel插件
const prodPlugins = []
if (process.env.NODE_ENV === 'production') {
prodPlugins.push('transform-remove-console')
}
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
],
plugins: [
[
'component',
{
libraryName: 'element-ui',
styleLibraryName: 'theme-chalk'
}
],
...prodPlugins
]
}