-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathindex.js
33 lines (29 loc) · 1.09 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
const resolveImportSource = `\
Object.defineProperty(__webpack_require__, 'p', {
get: (function () {
let script = document.currentScript;
if (!script) {
/* Shim for IE11 and below */
/* Do not take into account async scripts and inline scripts */
const scripts = Array.from(document.getElementsByTagName('script')).filter(function(s) { return !s.async && !s.text && !s.textContent; });
script = scripts.slice(-1)[0];
}
var url = script.src.split('/').slice(0, -1).join('/') + '/';
return function() {
return url;
};
})()
});`
class WebpackDashDynamicImport {
apply(compiler) {
compiler.hooks.compilation.tap('WebpackDashDynamicImport', compilation => {
compilation.mainTemplate.hooks.requireExtensions.tap('WebpackDashDynamicImport > RequireExtensions', (source, chunk, hash) => {
return [
source,
resolveImportSource
]
});
});
}
}
module.exports = WebpackDashDynamicImport;