ag-grid is proud to partner with webpack

UglifyjsWebpackPlugin

<p>This plugin uses <a href="https://github.com/mishoo/UglifyJS2/tree/harmony">UglifyJS v3 </a><a href="https://npmjs.com/package/uglify-es">(`uglify-es`)</a> to minify your JavaScript<p>

ℹ️ webpack contains the same plugin under webpack.optimize.UglifyJsPlugin. The documentation is valid apart from the installation instructions

Install

npm i -D uglifyjs-webpack-plugin

Usage

webpack.config.js

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

module.exports = {
  plugins: [
    new UglifyJSPlugin()
  ]
}

Options

⚠️ The following options are for the latest beta version. If you would like to see the options for the latest built-in version of the plugin in webpack, see the v0.4.6 docs.

Name
Type
Default
Description
Name
test
Type
{RegExp|Array<RegExp>}
Default
/\.js$/i
Description
Test to match files against
Name
include
Type
{RegExp|Array<RegExp>}
Default
undefined
Description
Files to include
Name
exclude
Type
{RegExp|Array<RegExp>}
Default
undefined
Description
Files to exclude
Name
parallel
Type
{Boolean|Object}
Default
false
Description
Use multi-process parallel running and file cache to improve the build speed
Name
sourceMap
Type
{Boolean}
Default
false
Description
Use source maps to map error message locations to modules (This slows down the compilation) ⚠️ cheap-source-map options don't work with this plugin
Name
uglifyOptions
Type
{Object}
Default
Description
uglify Options
Name
extractComments
Type
`{Boolean|RegExp\
Default
Function<(node, comment) -> {Boolean|Object}>}`
Description
false
Whether comments shall be extracted to a separate file, (see details (webpack >= 2.3.0)
Name
warningsFilter
Type
{Function(source) -> {Boolean}}
Default
undefined
Description
Allow to filter uglify warnings

test

webpack.config.js

[
  new UglifyJSPlugin({
    test: /\.js($&#124;\?)/i
  })
]

include

webpack.config.js

[
  new UglifyJSPlugin({
    include: /\/includes/
  })
]

exclude

webpack.config.js

[
  new UglifyJSPlugin({
    exclude: /\/excludes/
  })
]

parallel

webpack.config.js

[
  new UglifyJSPlugin({
    parallel: true
  })
]
Name
Type
Default
Description
Name
cache
Type
{Boolean}
Default
node_modules/.cache/uglifyjs-webpack-plugin
Description
Enable file caching
Name
workers
Type
{Boolean|Number}
Default
os.cpus().length - 1
Description
Number of concurrent runs, default is the maximum

webpack.config.js

[
  new UglifyJSPlugin({
    parallel: {
      cache: true,
      workers: 2 // for e.g
    }
  })
]

ℹ️ Parallelization can speedup your build significantly and is therefore highly recommended

sourceMap

webpack.config.js

[
  new UglifyJSPlugin({
    sourceMap: true
  })
]

⚠️ cheap-source-map options don't work with this plugin

uglifyOptions

Name
Type
Default
Description
Name
ie8
Type
{Boolean}
Default
false
Description
Enable IE8 Support
Name
ecma
Type
{Number}
Default
undefined
Description
Supported ECMAScript Version (5, 6, 7 or 8). Affects parse, compress && output options
Name
Type
{Object}
Default
{}
Description
Additional Parse Options
Name
Type
{Boolean|Object}
Default
true
Description
Enable Name Mangling (See Mangle Properties for advanced setups, use with ⚠️)
Name
Type
{Object}
Default
{}
Description
Additional Output Options (The defaults are optimized for best compression)
Name
Type
{Boolean|Object}
Default
true
Description
Additional Compress Options
Name
warnings
Type
{Boolean}
Default
false
Description
Display Warnings

webpack.config.js

[
  new UglifyJSPlugin({
    uglifyOptions: {
      ie8: false,
      ecma: 8,
      parse: {...options},
      mangle: {
        ...options,
        properties: {
          // mangle property options
        }
      },
      output: {
        comments: false,
        beautify: false,
        ...options
      },
      compress: {...options},
      warnings: false
    }
  })
]

extractComments

{Boolean}

All comments that normally would be preserved by the comments option will be moved to a separate file. If the original file is named foo.js, then the comments will be stored to foo.js.LICENSE

{RegExp|String} or {Function<(node, comment) -> {Boolean}>}

All comments that match the given expression (resp. are evaluated to true by the function) will be extracted to the separate file. The comments option specifies whether the comment will be preserved, i.e. it is possible to preserve some comments (e.g. annotations) while extracting others or even preserving comments that have been extracted.

{Object}

Name
Type
Default
Description
Name
condition
Type
{Regex|Function}
Default
``
Description
Regular Expression or function (see previous point)
Name
filename
Type
{String|Function}
Default
compilation.assets[file]
Description
The file where the extracted comments will be stored. Can be either a {String} or a {Function<(string) -> {String}>}, which will be given the original filename. Default is to append the suffix .LICENSE to the original filename
Name
banner
Type
`{Boolean|String\
Default
Function}`
Description
/*! For license information please see ${filename}.js.LICENSE */
The banner text that points to the extracted file and will be added on top of the original file. Can be false (no banner), a {String}, or a {Function<(string) -> {String} that will be called with the filename where extracted comments have been stored. Will be wrapped into comment

warningsFilter

webpack.config.js

[
  new UglifyJsPlugin({
    warningsFilter: (src) => true
  })
]

Maintainers


      Steven Hargrove


      Juho Vepsäläinen


      Joshua Wiens


      Michael Ciniawsky


      Alexander Krasnoyarov