Webpack 4: include UglifyJsPlugin under the production mode

Do you want to request a feature or report a bug?

A feature.

What is the current behavior?

mode: 'production' in webpack 4 doesn’t enable the minificator. The code with mode: 'production' comes out not fully ready for production.

What is the expected behavior?

mode: 'production' in webpack 4 enables the minificator (the UglifyJsPlugin).

If this is a feature request, what is motivation or use case for changing the behavior?

I was testing the mode switch in webpack 4, and what surprised me was that the UglifyJsPlugin is not enabled in the production mode by default.

My expectations were like “I write mode: 'production', specify entry, output, a couple of loaders, and it just works.” Without minification, the production mode feels half-baked or incomplete – I still have to add additional plugins to make it work.

Would it make sense to enable the UglifyJsPlugin in production? We’ll have to make the plugin disableable (for folks that use other minifiers), so probably it would make sense to add an optimization.minimize: true/false option that enables/disables it. Because this plugin has options, we could either allow passing them into optimization.minimize:

module.exports = {
  optimization: {
    minimize: {
      sourceMap: true,
    },
  },
};

or create a separate field for them (e.g. optimization.minimizeOptions).

Author: Fantashit

2 thoughts on “Webpack 4: include UglifyJsPlugin under the production mode

  1. uglifyjs-webpack-plugin v1.0.0 landed on the next (#5940) but isn’t released yet (webpack v4.0.0-alpha.0). +1 to not included it as a direct dependency anymore (alias) and instead handle it in a different way via mode somehow.

    webpack.config.js

    const config = {
       mode: process.env.NODE_ENV || 'development'
       plugins: this.mode === 'production' 
         ? [
           ...plugins,
           new UglifyJSPlugin() || new BabelMinifyPlugin() || ClosurePlugin()
         ]
         : [ ...plugins ] 
    }

Comments are closed.