forked from shakyShane/entry-wrap-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (24 loc) · 992 Bytes
/
index.js
File metadata and controls
27 lines (24 loc) · 992 Bytes
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
var ConcatSource = require('webpack-sources/lib/ConcatSource');
var ModuleFilenameHelpers = require('webpack/lib/ModuleFilenameHelpers');
function EntryWrap(before, after, options) {
this.options = options || {};
this.before = before;
this.after = after;
}
module.exports = EntryWrap;
EntryWrap.prototype.apply = function(compiler) {
var options = this.options;
var before = this.before;
var after = this.after;
compiler.plugin('compilation', function(compilation) {
compilation.plugin('optimize-chunk-assets', function(chunks, callback) {
chunks.forEach(function(chunk) {
if(!chunk.isInitial()) return;
chunk.files.filter(ModuleFilenameHelpers.matchObject.bind(undefined, options)).forEach(function(file) {
compilation.assets[file] = new ConcatSource(before, '\n', compilation.assets[file], '\n', after);
});
});
callback();
});
});
};