-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (37 loc) · 1.37 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
Object.defineProperty(exports, "__esModule", { value: true });
var download = require('download');
var RemoteIncludePlugin = /** @class */ (function () {
function RemoteIncludePlugin(options) {
this.options = [];
this.options = options instanceof Array
? options
: [options];
}
/**
* @param compiler
*/
RemoteIncludePlugin.prototype.apply = function (compiler) {
var _this = this;
compiler.hooks.emit.tapAsync({ name: 'RemoteIncludePlugin', context: true }, function (context, compilation, callback) {
var count = _this.options.length;
var downloadFiles = function (option) {
download(option.url).then(function (data) {
compilation.assets[option.filepath] = {
size: function () { return data.length; },
source: function () { return data; }
};
count--;
if (count === 0) {
callback();
}
}).catch(function (error) {
compilation.errors.push(new Error(error));
callback();
});
};
_this.options.forEach(downloadFiles);
});
};
return RemoteIncludePlugin;
}());
module.exports = RemoteIncludePlugin;