-
Notifications
You must be signed in to change notification settings - Fork 94
/
index.js
40 lines (35 loc) · 786 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* UglifyJS webpack block.
*
* @see https://github.com/webpack-contrib/uglifyjs-webpack-plugin
*/
const webpackMerge = require('webpack-merge')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
module.exports = uglify
/**
* @param {object} [options] UglifyJS options
* @return {Function}
*/
function uglify(options = {}) {
options = webpackMerge(
{
parallel: true,
cache: true,
uglifyOptions: {
compress: {
warnings: false
}
}
},
options
)
const postHook = (context, util) => {
const plugin = new UglifyJSPlugin(options)
return util.merge({
optimization: {
minimizer: [plugin]
}
})
}
return Object.assign(() => prevConfig => prevConfig, { post: postHook })
}