-
Notifications
You must be signed in to change notification settings - Fork 5
/
plugin.remove-assets.js
40 lines (37 loc) · 1.09 KB
/
plugin.remove-assets.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
/**
* @typedef { import('webpack').Compiler } Compiler
*/
/**
* Remove assets from complidation.
*/
class RemoveAssetsPlugin {
/**
* @param {object} options - plugin options
*/
constructor(options) {
this.options = { ...options };
}
/**
* Apply plugin to compliler.
* @param {Compiler} compiler - webpack complier object
*/
apply(compiler) {
compiler.hooks.compilation.tap('RemoveAssetsPlugin', (compilation) => {
compilation.hooks.processAssets.tap(
{
name: 'RemoveAssetsPlugin',
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
},
(assets) => {
const pattern = this.options.test;
Object.keys(assets)
.filter((name) => pattern.test(name))
.forEach((name) => {
compilation.deleteAsset(name);
});
}
);
});
}
}
module.exports = RemoveAssetsPlugin;