UglifyJsPlugin options.exclude does not work?

When using the UglifyJsPlugin within my webpack build I get a large list of errors from my bower_components dependencies. It looks to me (from here: https://github.com/webpack/webpack/blob/master/lib/optimize/UglifyJsPlugin.js#L43) that I should be able to use something like this

new webpack.optimize.UglifyJsPlugin({
  exclude: [
    /bower_components\//
  ]
})

which continues to throw out a massive list of errors, leading me to believe they are still being parsed.

Author: Fantashit

5 thoughts on “UglifyJsPlugin options.exclude does not work?

  1. I’ve realized that in my case the reason that this is happening is that by the time the code gets to my UglifyJsPlugin it has already been concatenated into a single file (by the name of formly.min.js). I need to figure out a way to uglify before it concats…

  2. My solution was to use the uglify-loader and use exclude: /\.test\.js/i. This is not ideal for actually uglifying all the code because it works at the module level, but I’m just interested in my code working uglified under test. My actual distributable still uses UglifyJsPlugin so this workaround worked well for me.

  3. It’s working as expected, which is processing your generated chunks rather than source files. If you want to ignore only a few modules, extract them into a separate chunk and exclude that one from UglifyJsPlugin.

  4. Thanks! I was able to run this against my chunk name, and it did work. All I had to do was to put the UglifyJS plugin declaration in there twice. Once for the main bundle files excluding this particular one and another declaration for this particular one with mangle: false. I appreciate the help 👍.

Comments are closed.