js项目生产环境中移除 console

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
  ],
};

相关推荐

  1. js项目生产环境 console

    2024-07-13 08:26:04       24 阅读
  2. conda环境

    2024-07-13 08:26:04       55 阅读
  3. js子元素

    2024-07-13 08:26:04       36 阅读
  4. Jupyter Notebook之anaconda环境

    2024-07-13 08:26:04       53 阅读
  5. 从字符串星号

    2024-07-13 08:26:04       56 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-13 08:26:04       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-13 08:26:04       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-13 08:26:04       57 阅读
  4. Python语言-面向对象

    2024-07-13 08:26:04       68 阅读

热门阅读

  1. uniapp微信小程序授权登录实现

    2024-07-13 08:26:04       23 阅读
  2. 版本发布 | IvorySQL 3.3 发版

    2024-07-13 08:26:04       26 阅读
  3. 【分布式系统】Ceph对象存储系统之RGW接口

    2024-07-13 08:26:04       27 阅读
  4. 浅谈PostCSS

    2024-07-13 08:26:04       26 阅读
  5. AI学习指南机器学习篇-层次聚类的优缺点

    2024-07-13 08:26:04       23 阅读
  6. 一文学会鉴别“套壳”ChatGPT模型

    2024-07-13 08:26:04       28 阅读
  7. MPPT概念

    2024-07-13 08:26:04       25 阅读
  8. Python MySQL 教程

    2024-07-13 08:26:04       29 阅读
  9. 数据湖仓一体(二) 安装kafka

    2024-07-13 08:26:04       25 阅读
  10. Kafka Rebalance详解

    2024-07-13 08:26:04       30 阅读
  11. python:使用openpyxl模块处理excel

    2024-07-13 08:26:04       24 阅读