Webpack 4 - 如何配置最小化? [英] Webpack 4 - How to configure minimize?

查看:31
本文介绍了Webpack 4 - 如何配置最小化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Webpack 4 附带以下声明:

Webpack 4 comes with the following statement:

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

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

很公平,但我找不到有关配置在后台运行的 UglifyJsPlugin 实例的任何信息,例如更改缓存目录.可以这样做吗?

Fair enough, but I cannot find any information about configuring the UglifyJsPlugin instance running under the hood, for example to change the cache directory. Can this be done?

推荐答案

无法修改默认配置.

不过,您可以使用 optimization.minimizer 设置来实例化您自己的 UglifyJsPlugin.使用 4.0,即使 mode 设置为 'production'(例如,4.1.1 不再需要),我们也使用此示例获取源映射:

You can use the optimization.minimizer setting to instantiate your own UglifyJsPlugin, however. Using 4.0 we used this example to get source maps even when mode is set to 'production' for example (no longer necessary as of 4.1.1):

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

module.exports = {
  optimization: {
    minimizer: [
      // we specify a custom UglifyJsPlugin here to get source maps in production
      new UglifyJsPlugin({
        cache: true,
        parallel: true,
        uglifyOptions: {
          compress: false,
          ecma: 6,
          mangle: true
        },
        sourceMap: true
      })
    ]
  }
};

这篇关于Webpack 4 - 如何配置最小化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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