-
Notifications
You must be signed in to change notification settings - Fork 34
/
index.js
48 lines (40 loc) · 1.28 KB
/
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
41
42
43
44
45
46
47
48
const uglifier = require("./lib/uglifier");
function sourceMapError(lib) {
return `You should not pass options.${lib}.sourceMap, did you mean options.sourceMap?`;
}
function ParallelUglifyPlugin(options) {
if (options.uglifyJS && options.terser) {
throw new TypeError(
"You cannot use both uglifyJS and terser for the same plugin."
);
}
if (options.uglifyJS && options.uglifyJS.sourceMap) {
throw new TypeError(sourceMapError("uglifyJS"));
}
if (options.terser && options.terser.sourceMap) {
throw new TypeError(sourceMapError("terser"));
}
this.options = options;
if (!(this.options.uglifyJS || this.options.terser)) {
this.options.uglifyJS = {};
}
}
ParallelUglifyPlugin.prototype.apply = function apply(compiler) {
compiler.hooks.compilation.tap("ParallelUglifyPlugin", (compilation) => {
compilation.hooks.processAssets.tapAsync(
{
name: "ParallelUglifyPlugin",
stage: compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
},
(chunks, callback) => {
uglifier.processAssets(compilation, this.options).then(() => {
callback();
});
}
);
});
compiler.hooks.done.tap("ParallelUglifyPlugin", () => {
uglifier.pruneCache(this.options);
});
};
module.exports = ParallelUglifyPlugin;