JSPM

  • Created
  • Published
  • Downloads 639777
  • Score
    100M100P100Q203451F
  • License MIT

UglifyJS plugin for webpack

Package Exports

  • uglifyjs-webpack-plugin

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (uglifyjs-webpack-plugin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

build status bitHound Score codecov

UglifyJS Webpack Plugin

This plugin uses UglifyJS to minify your JavaScript. It is the same plugin as in Webpack core (webpack.optimize.UglifyJSPlugin) except it has been decoupled from it. This allows you to control the version of UglifyJS you are using.

Note that webpack contains the same plugin under webpack.optimize.UglifyJsPlugin. This is a standalone version for those that want to control the version of UglifyJS. The documentation is valid apart from the installation instructions in that case.

Usage

First, install the plugin:

yarn add uglifyjs-webpack-plugin --dev

..or if you insist on using npm instead of the more advanced Yarn:

npm install uglifyjs-webpack-plugin --save-dev

Important! The plugin has a peer dependency to uglify-js, so in order to use the plugin, also uglify-js has to be installed. The currently (2017/1/25) available uglify-js npm packages, however, do not support minification of ES6 code. In order to support ES6, an ES6-capable, a.k.a. harmony, version of UglifyJS has to be provided.

If your minification target is ES6:

yarn add git://github.com/mishoo/UglifyJS2#harmony --dev

If your minification target is ES5:

yarn add uglify-js --dev

Then configure as follows:

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

module.exports = {
  entry: {...},
  output: {...},
  module: {...},
  plugins: [
    new UglifyJSPlugin()
  ]
};

And, that's it!

Options

This plugin supports UglifyJS features as discussed below:

Property Type Default Description
compress boolean, object true See UglifyJS documentation.
mangle boolean, object true See below.
beautify boolean false Beautify output.
output An object providing options for UglifyJS OutputStream Lower level access to UglifyJS output.
comments boolean, RegExp, function(astNode, comment) -> boolean Defaults to preserving comments containing /*!, /**!, @preserve or @license. Comment related configuration.
sourceMap boolean false Use SourceMaps to map error message locations to modules. This slows down the compilation.
test RegExp, Array /.js($|?)/i Test to match files against.
include RegExp, Array Test only include files.
exclude RegExp, Array Files to exclude from testing.

Mangling

mangle.props (boolean|object) - Passing true or an object enables and provides options for UglifyJS property mangling - see UglifyJS documentation for mangleProperties for options.

Note: the UglifyJS docs warn that you will probably break your source if you use property mangling, so if you aren’t sure why you’d need this feature, you most likely shouldn’t be using it! You can tweak the behavior as below:

new UglifyJsPlugin({
  mangle: {
    // Skip mangling these
    except: ['$super', '$', 'exports', 'require']
  }
})

License

MIT.