UNPKG

981 BJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.RuntimePublicPath = RuntimePublicPath;
7function RuntimePublicPath(options) {
8 this.options = options;
9}
10RuntimePublicPath.prototype.apply = function (compiler) {
11 var runtimePublicPathStr = this.options && this.options.runtimePublicPath;
12 if (!runtimePublicPathStr) {
13 console.error('RuntimePublicPath: no option.runtimePublicPath is specified. This plugin will do nothing.');
14 return;
15 }
16 compiler.plugin('this-compilation', function (compilation) {
17 compilation.mainTemplate.plugin('require-extensions', function (source, chunk, hash) {
18 var buf = [];
19 buf.push(source);
20 buf.push('');
21 buf.push('// Dynamic assets path override ');
22 buf.push('var e=' + this.requireFn + '.e;');
23 buf.push(this.requireFn + '.e = function requireEnsure(chunkId) {' + runtimePublicPathStr + ';return e(chunkId);} ');
24 return this.asString(buf);
25 });
26 });
27};
\No newline at end of file