Skip to content

Commit

Permalink
Prevent minification of nextDefineUri
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed May 7, 2021
1 parent f40810a commit 63b992c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/client-bundle-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ export default function (inputOptions, outputOptions, resolveFileUrl) {
const inlineDefines = [
...allModules.map(
(item) =>
`nextDefineUri=location.origin+${resolveFileUrl(item)};${
`self.nextDefineUri=location.origin+${resolveFileUrl(item)};${
item.code
}`,
),
'nextDefineUri=""',
'self.nextDefineUri=""',
];

return JSON.stringify(inlineDefines.join(''));
Expand Down
12 changes: 5 additions & 7 deletions lib/omt.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
* limitations under the License.
*/

var nextDefineUri;

// If the loader is already loaded, just stop.
if (!self.<%- amdFunctionName %>) {
let registry = {};
Expand All @@ -25,7 +23,7 @@ if (!self.<%- amdFunctionName %>) {
fetch(uri)
.then(resp => resp.text())
.then(code => {
nextDefineUri = uri;
self.nextDefineUri = uri;
eval(code);
})
<% } else { %>
Expand All @@ -36,7 +34,7 @@ if (!self.<%- amdFunctionName %>) {
script.onload = resolve;
document.head.appendChild(script);
} else {
nextDefineUri = uri;
self.nextDefineUri = uri;
importScripts(uri);
resolve();
}
Expand All @@ -53,7 +51,7 @@ if (!self.<%- amdFunctionName %>) {
};

self.<%- amdFunctionName %> = (depsNames, factory) => {
const uri = nextDefineUri || ("document" in self ? document.currentScript.src : "") || location.href;
const uri = self.nextDefineUri || ("document" in self ? document.currentScript.src : "") || location.href;
if (registry[uri]) {
// Module is already loading or loaded.
return;
Expand All @@ -65,9 +63,9 @@ if (!self.<%- amdFunctionName %>) {
exports,
require
};
registry[uri] = Promise.all(depsNames.map(
registry[uri] = Promise.resolve().then(() => Promise.all(depsNames.map(
depName => specialDeps[depName] || require(depName)
)).then(deps => {
))).then(deps => {
factory(...deps);
return exports;
});
Expand Down

0 comments on commit 63b992c

Please sign in to comment.