-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
43 lines (29 loc) · 1.34 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
var IndexHtmlSource = require('./IndexHtmlSource');
function IndexHtmlPlugin(source, target) {
this.apply = function apply(compiler) {
compiler.plugin('this-compilation', function (compilation) {
compilation.plugin('additional-chunk-assets', function additionalChunkAssets() {
var sourceChunk = this.namedChunks[source];
var sourceModule = sourceChunk.origins[0].module;
var filePath = this.getPath(target, {chunk: sourceChunk});
this.additionalChunkAssets.push(filePath);
this.assets[filePath] = new IndexHtmlSource(sourceModule, sourceChunk, this);
sourceChunk.files.push(filePath);
});
});
compiler.plugin('emit', function emit(compilation, callback) {
Object.keys(compilation.assets).forEach(function (file) {
var targetFile = file;
var queryStringIdx = targetFile.indexOf('?');
if (queryStringIdx >= 0) {
targetFile = targetFile.substr(0, queryStringIdx);
}
if (targetFile === source + '.js' || targetFile === source + '.js.map') {
delete compilation.assets[file];
}
});
callback();
});
};
}
module.exports = IndexHtmlPlugin;