webpack-contrib/uglifyjs-webpack-plugin

exclude node_modules don't work as expected

mancioshell opened this issue · 3 comments

  • Operating System: Windows 10
  • Node Version: v8.11.3
  • NPM Version: 5.6.0
  • webpack Version: 4.20.2
  • uglifyjs-webpack-plugin Version: v2.0.1

Expected Behavior

I would like to exclude node_modules from minification, adding exclude property

Actual Behavior

Plugin ignores this configuration and minify node_modules

Code

  optimization: {
    minimizer: [
      new UglifyJsPlugin({ 
         exclude: /\/node_modules/
     })
    ],
    splitChunks: {
      cacheGroups: {       
        // Custom common chunk
        bundle: {
          name: 'commons',
          chunks: 'initial',
          minChunks: 2
        },
        // Customer vendor
        vendors: {
          chunks: 'all',
          name: 'vendors',
          test: /[\\/]node_modules[\\/](?!sogei-uikit).*[\\/]/          
        }
      },
    },
  },  

@mancioshell plugin works with chunk, chunk contains your code and require/import code, it is impossible disable uglification for module (from node_modules) into chunk. If you want to disable uglification for vendors you should use exclude: 'vendors'.

@evilebottnawi thank you for your response. Sorry, my fault but maybe the documentation is not so clear. In the exclude docs i have read files to exclude, not chunks :

exclude

Type: String|RegExp|Array<String|RegExp> Default: undefined

Files to exclude.

Thank you so much.

@mancioshell in webpack you can include/exclude/test only files in plugins, not modules, it is for all plugins. Also here written Files (not modules). Feel free to send a PR if you know how better we can write about this.