-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (31 loc) · 1.19 KB
/
index.js
File metadata and controls
34 lines (31 loc) · 1.19 KB
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
const { RawSource } = require('webpack-sources');
exports.WebpackRemovePlugin = class WebpackRemovePlugin {
constructor(opts, ext) {
this.opts = opts;
this.ext = ext || [];
}
apply(compiler) {
compiler.plugin('emit', (comp, callback) => {
let assets = comp.assets;
let keys = Object.keys(assets);
keys.forEach((key) => {
if (this.ext.includes(key.substr(key.lastIndexOf('.')))) {
let asset = assets[key];
let content = asset.source();
let start;
while ((start = content.indexOf(this.opts.start)) !== -1) {
const pos = content.indexOf(this.opts.end);
if (pos !== -1) {
content = content.slice(0, start) + content.slice(pos + this.opts.end.length);
}
else {
start = -1;
}
}
assets[key] = new RawSource(content);
}
})
callback();
})
}
};