-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
30 lines (27 loc) · 883 Bytes
/
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
var ModuleFilenameHelpers = require('webpack/lib/ModuleFilenameHelpers');
var ExternalModule = require('webpack/lib/ExternalModule');
function ExternalsPlugin(opts) {
this.opts = opts;
}
ExternalsPlugin.prototype.apply = function(compiler) {
var opts = this.opts;
compiler.plugin('normal-module-factory', function(nmf) {
nmf.plugin('factory', function(factory) {
return function(data, callback) {
factory(data, function(err, module) {
if (err) {
return callback(err);
}
if (ModuleFilenameHelpers.matchObject(opts, module.resource)) {
return callback(null, new ExternalModule(
data.request,
opts.type || compiler.options.output.libraryTarget
));
}
callback(null, module);
});
};
});
});
};
module.exports = ExternalsPlugin;