webpack-contrib / uglifyjs-webpack-plugin

[deprecated] UglifyJS Plugin
MIT License
1.38k stars 179 forks source link

exclude node_modules don't work as expected #366

Closed mancioshell closed 6 years ago

mancioshell commented 6 years ago

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).*[\\/]/          
        }
      },
    },
  },  
alexander-akait commented 6 years ago

@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'.

mancioshell commented 6 years ago

@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.

alexander-akait commented 6 years ago

@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.