环境
"nuxt": "^2.15.7"
安装
yarn add babel-plugin-transform-remove-console --save-dev
or
npm install babel-plugin-transform-remove-console --save-dev
配置(nuxt.config.js 文件)
因为需要判断环境 所以需要在头部声明变量使用插件
let plugins_removeConsole = []
if (process.env.NODE_ENV === 'production') {
console.log(process.env.NODE_ENV);
plugins_removeConsole.push(["transform-remove-console", { "exclude": ["error", "warn"] }])
}
export default {
build: {
analyze: true,
babel: {
plugins: [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
],
...plugins_removeConsole
]
},
},
}
无需对环境进行判断 直接引用
export default {
build: {
analyze: true,
babel: {
plugins: [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
],
["transform-remove-console", { "exclude": ["error", "warn"] }]
]
},
},
}