Skip to content

Commit f156ede

Browse files
author
Marc-André Rivet
committed
plugin - distinguish local from remote script resources
1 parent c71955e commit f156ede

File tree

1 file changed

+28
-9
lines changed
  • @plotly/webpack-dash-dynamic-import/src

1 file changed

+28
-9
lines changed

Diff for: @plotly/webpack-dash-dynamic-import/src/index.js

+28-9
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,25 @@ function getFingerprint() {
1111
}
1212

1313
const resolveImportSource = () => `\
14+
const getCurrentScript = function() {
15+
let script = document.currentScript;
16+
if (!script) {
17+
/* Shim for IE11 and below */
18+
/* Do not take into account async scripts and inline scripts */
19+
const scripts = Array.from(document.getElementsByTagName('script')).filter(function(s) { return !s.async && !s.text && !s.textContent; });
20+
script = scripts.slice(-1)[0];
21+
}
22+
23+
return script;
24+
};
25+
26+
const isLocalScript = function(script) {
27+
return /\/_dash-components-suite\//.test(script.src);
28+
};
29+
1430
Object.defineProperty(__webpack_require__, 'p', {
1531
get: (function () {
16-
let script = document.currentScript;
17-
if (!script) {
18-
/* Shim for IE11 and below */
19-
/* Do not take into account async scripts and inline scripts */
20-
const scripts = Array.from(document.getElementsByTagName('script')).filter(function(s) { return !s.async && !s.text && !s.textContent; });
21-
script = scripts.slice(-1)[0];
22-
}
32+
let script = getCurrentScript();
2333
2434
var url = script.src.split('/').slice(0, -1).join('/') + '/';
2535
@@ -31,14 +41,23 @@ Object.defineProperty(__webpack_require__, 'p', {
3141
3242
const __jsonpScriptSrc__ = jsonpScriptSrc;
3343
jsonpScriptSrc = function(chunkId) {
34-
const srcFragments = __jsonpScriptSrc__(chunkId).split('/');
44+
let script = getCurrentScript();
45+
let isLocal = isLocalScript(script);
46+
47+
let src = __jsonpScriptSrc__(chunkId);
48+
49+
if(!isLocal) {
50+
return src;
51+
}
52+
53+
const srcFragments = src.split('/');
3554
const fileFragments = srcFragments.slice(-1)[0].split('.');
3655
3756
fileFragments.splice(1, 0, ${getFingerprint()});
3857
srcFragments.splice(-1, 1, fileFragments.join('.'))
3958
4059
return srcFragments.join('/');
41-
}
60+
};
4261
`
4362

4463
class WebpackDashDynamicImport {

0 commit comments

Comments
 (0)