当前位置: 首页> 财经> 访谈 > js项目生产环境中移除 console

js项目生产环境中移除 console

时间:2025/7/11 17:42:17来源:https://blog.csdn.net/qq_39460057/article/details/136744188 浏览次数:1次

1、terser-webpack-plugin
webpack 构建的项目中安装使用
安装:
npm install terser-webpack-plugin --save-dev
配置
在webpack.config.js文件中

new TerserPlugin({terserOptions: {output: {comments: false, // 去除注释},warnings: false, // 去除黄色警告,compress: {drop_console: true,drop_debugger: true, // 特定情况需要利用debugger防止调试pure_funcs: ['console.log'], // 移除console.log 避免console.error},},
}),

2、
babel-plugin-transform-remove-console
安装
npm install babel-plugin-transform-remove-console --save-dev
在babel.config.js文件中加入配置

module.exports = {plugins: ['transform-remove-console',],
};

如果只想在生产环境中使用,可以改成:

const prodPlugins = [];
if (process.en.NODE_ENV === 'production') {prodPlugins.push('transform-remove-console');
}
module.exports = {plugins: [...prodPlugins],
};
关键字:js项目生产环境中移除 console

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: