优化 Vue 项目时,只在发布阶段移除所有的 console._

开发一个 Vue 项目时,大多数情况都会使用 console.log() 来在控制台打印数据或结果,方面编写程序,但是项目发布上线时是不用打印任何数据或结果的,这时就必须得把项目中所有的 console.log() 移除,对于这个下面给出了一种方法。


 

一、安装移除的插件

npm install babel-plugin-transform-remove-console --save-dev

 

二、配置文件

1、打开 babel.config.js 文件

2、添加以下配置代码

//项目只在发布阶段需要移除的 babel 插件文件配置
const prodplugins = [];
if(process.env.MODE_ENV === 'production'){
    prodplugins.push('transform-remove-console')
};

module.exports = {
    plugins:[
        //发布产品时的插件数组
        ...prodplugins
    ]
}

 

posted @ 2022-05-03 16:01  CodeFan*  阅读(39)  评论(0编辑  收藏  举报