一、在 build 命令执行期间移除所有的 console
- 通过
npm install babel-plugin-transform-remove-console --save-dev命令下载工具包 - 在项目的
babel.config.js文件中,在plugins中,添加"transform-remove-console",代码如下:
module.exports = {
presets: ["@vue/app"],
plugins: [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
],
// 在 build 阶段清除所有的 console
"transform-remove-console"
]
}
二、 只在生产发布阶段移除所有的 console
- 通过
npm install babel-plugin-transform-remove-console --save-dev命令下载工具包 - 在项目的
babel.config.js文件中,定义prodPlugins数组,默认为空。如果属于production正式生产环境,程序最终发布后所需要的参数配置,一般不会产生太多无用的日志记录,那么就可以将"transform-remove-console"添加到prodPlugins数组中,代码如下:
// 项目发布阶段需要用到的 babel 插件
const prodPlugins = []
if (process.env.NODE_ENV === 'production') {
prodPlugins.push("transform-remove-console")
}
- 在项目的
babel.config.js文件中,在plugins中,使用prodPlugins,代码如下:
module.exports = {
presets: ["@vue/app"],
plugins: [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
],
// 发布产品时候的插件数组
...prodPlugins
]
}
版权声明:本文为weixin_42614080原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。