This plugin uses UglifyJS v3 (uglify-es
) to minify your JavaScript
ℹ️
webpack =< v3.0.0
currently containsv0.4.6
of this plugin underwebpack.optimize.UglifyJsPlugin
as an alias. For usage of the latest version (v1.0.0
), please follow the instructions below. Aliasingv1.0.0
aswebpack.optimize.UglifyJsPlugin
is scheduled forwebpack v4.0.0
npm i -D uglifyjs-webpack-plugin
webpack.config.js
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
module.exports = {
plugins: [
new UglifyJsPlugin()
]
}
test
{RegExp|Array<RegExp>}
/\.js$/i
include
{RegExp|Array<RegExp>}
undefined
include
exclude
{RegExp|Array<RegExp>}
undefined
exclude
cache
{Boolean|String}
false
parallel
{Boolean|Number}
false
sourceMap
{Boolean}
false
cheap-source-map
options don't work with this plugin
extractComments
{Boolean|RegExp|Function<(node, comment) -> {Boolean|Object}>}
false
webpack >= 2.3.0
)
warningsFilter
{Function(source) -> {Boolean}}
() => true
##
webpack.config.js
[
new UglifyJsPlugin({
test: /\.js($|\?)/i
})
]
include
webpack.config.js
[
new UglifyJsPlugin({
include: /\/includes/
})
]
exclude
webpack.config.js
[
new UglifyJsPlugin({
exclude: /\/excludes/
})
]
cache
{Boolean}
webpack.config.js
[
new UglifyJsPlugin({
cache: true
})
]
Enable file caching.
Default path to cache directory: node_modules/.cache/uglifyjs-webpack-plugin
.
{String}
webpack.config.js
[
new UglifyJsPlugin({
cache: 'path/to/cache'
})
]
Path to cache directory.
parallel
{Boolean}
webpack.config.js
[
new UglifyJsPlugin({
parallel: true
})
]
Enable parallelization.
Default number of concurrent runs: os.cpus().length - 1
.
{Number}
webpack.config.js
[
new UglifyJsPlugin({
parallel: 4
})
]
Number of concurrent runs.
ℹ️ 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
ie8
{Boolean}
false
ecma
{Number}
undefined
5
, 6
, 7
or 8
). Affects parse
, compress
&& output
options
{Boolean|Object}
true
{Object}
{}
warnings
{Boolean}
false
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}
condition
{Regex|Function}
filename
{String|Function}
${file}.LICENSE
{String}
or a {Function<(string) -> {String}>}
, which will be given the original filename. Default is to append the suffix .LICENSE
to the original filename
banner
{Boolean|String|Function}
/*! For license information please see ${filename}.js.LICENSE */
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
})
]
|
|
|
|
|