Webpack V4:使用Webpack&删除console.logs丑化 [英] Webpack V4: Remove console.logs with Webpack & Uglify

查看:131
本文介绍了Webpack V4:使用Webpack&删除console.logs丑化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此答案以前就像一个咒语:

This answer worked like a charm previously:

https:// stackoverflow.com/a/41041580/3894981

但是,由于Webpack v4不再起作用。从那以后它抛出:

However, since Webpack v4 it doesn't work anymore. Since then it throws:


错误:webpack.optimize.UglifyJsPlugin已被删除,请改用
config.optimization.minimize 。

Error: webpack.optimize.UglifyJsPlugin has been removed, please use config.optimization.minimize instead.

要使它在Webpack v4中工作,需要什么?

我尝试使用以下方法没有运气:

I've tried using the following without luck:

const uglifyJsPlugin = require('uglifyjs-webpack-plugin');

if (process.argv.indexOf('-p') !== -1) {
  // compress and remove console statements. Only add this plugin in production
  // as even if drop_console is set to false, other options may be set to true
  config.plugins.push(new uglifyJsPlugin({
    compress: {
      'drop_console': true
    }
  }));
}


推荐答案

在config.plugins中,您是否尝试过将其放入config.optimization.minimizer中?

You're still putting it in config.plugins, have you tried putting it in config.optimization.minimizer?

const UglifyJSPlugin = require('uglifyjs-webpack-plugin')

...

optimization: {
  minimizer: [
    new UglifyJSPlugin({
      uglifyOptions: {
        compress: {
          drop_console: true,
        }
      }
    })
  ]
}

这篇关于Webpack V4:使用Webpack&删除console.logs丑化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆