Remove console.logs with Webpack & Uglify

前端 未结 8 1446
谎友^
谎友^ 2020-11-28 23:59

I am trying to remove console.logs with Webpack\'s Uglify plugin but it seems that Uglify plugin that comes bundled with Webpack doesn\'t have that option, its

8条回答
  •  野性不改
    2020-11-29 00:12

    this is what I've done to remove alert() and console.log() from my codes. global_defs => replace alerts with console.log then drop_console removes all console.logs and now nothing shows up in my browser console

         new UglifyJsPlugin({
          uglifyOptions: {
            compress: {
              global_defs: {
                "@alert": "console.log",
              },
              drop_console: true
            }
          }
        }),
    

    plugin versions:

    "webpack":3.12.0,
    "webpack-cli": "^3.0.3",
    "uglifyjs-webpack-plugin": "^1.2.5",
    

    Right now uglifyjs-webpack-plugin v1.2.6 has been released and I used latest documentations for this one, So I suppose there wont be any problem with latest plugin too.

提交回复
热议问题