-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathindex.js
76 lines (59 loc) · 2.07 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const fs = require('fs');
function getFingerprint() {
const package = fs.readFileSync('./package.json');
const packageJson = JSON.parse(package);
const timestamp = Math.round(Date.now() / 1000);
const version = packageJson.version.replace(/[.]/g, '_');
return `"v${version}m${timestamp}"`;
}
const resolveImportSource = () => `\
const getCurrentScript = 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];
}
return script;
};
const isLocalScript = function(script) {
return /\/_dash-components-suite\//.test(script.src);
};
Object.defineProperty(__webpack_require__, 'p', {
get: (function () {
let script = getCurrentScript();
var url = script.src.split('/').slice(0, -1).join('/') + '/';
return function() {
return url;
};
})()
});
const __jsonpScriptSrc__ = jsonpScriptSrc;
jsonpScriptSrc = function(chunkId) {
let script = getCurrentScript();
let isLocal = isLocalScript(script);
let src = __jsonpScriptSrc__(chunkId);
if(!isLocal) {
return src;
}
const srcFragments = src.split('/');
const fileFragments = srcFragments.slice(-1)[0].split('.');
fileFragments.splice(1, 0, ${getFingerprint()});
srcFragments.splice(-1, 1, fileFragments.join('.'))
return srcFragments.join('/');
};
`
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;