Skip to content

Commit

Permalink
fix(loader): better resourceUrl resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Oct 3, 2019
1 parent 0c933a4 commit f56eeb4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/compiler/component-lazy/generate-lazy-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ function getLegacyLoader(config: d.Config) {
var scriptElm = doc.createElement('script');
scriptElm.setAttribute('type', 'module');
scriptElm.src = url + '/${namespace}.esm.js';
doc.head.appendChild(scriptElm);
warn.push(scriptElm.outerHTML);
scriptElm.setAttribute('data-stencil-namespace', '${namespace}');
doc.head.appendChild(scriptElm);
scriptElm = doc.createElement('script');
scriptElm.setAttribute('nomodule', '');
scriptElm.src = url + '/${namespace}.js';
warn.push(scriptElm.outerHTML);
scriptElm.setAttribute('data-stencil-namespace', '${namespace}');
doc.head.appendChild(scriptElm);
Expand Down
17 changes: 7 additions & 10 deletions src/compiler/component-lazy/generate-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,17 @@ async function getSystemLoader(config: d.Config, corePath: string, includePolyfi
(function () {
var doc = document;
var currentScript = doc.currentScript;
// Safari 10 support type="module" but still download and executes the nomodule script
if (!currentScript || !currentScript.hasAttribute('nomodule') || !('onbeforeload' in currentScript)) {
${polyfills}
var scriptElm = doc.querySelector('script[data-stencil-namespace="${config.fsNamespace}"]');
if (!scriptElm) {
var allScripts = doc.querySelectorAll('script');
for (var x = allScripts.length - 1; x >= 0; x--) {
scriptElm = allScripts[x];
if (scriptElm.src || scriptElm.hasAttribute('data-resources-url')) {
break;
}
}
}
// Figure out currentScript (for IE11, since it does not support currentScript)
var regex = /\\/${config.fsNamespace}(\\.esm)?\\.js($|\\?|#)/;
var scriptElm = currentScript || Array.from(doc.querySelectorAll('script')).find(function(s) {
return regex.test(s.src) || s.getAttribute('data-stencil-namespace') === "${config.fsNamespace}";
});
var resourcesUrl = scriptElm ? scriptElm.getAttribute('data-resources-url') || scriptElm.src : '';
var start = function() {
Expand Down

0 comments on commit f56eeb4

Please sign in to comment.