Fix lazy loading of css chunks #141
This commit is contained in:
parent
69ef47daf8
commit
0eb4ab85b3
@ -16,9 +16,8 @@ export function replaceImportsFromStaticInJsCode(params: { jsCode: string; urlOr
|
||||
|
||||
const { jsCode, urlOrigin } = params;
|
||||
|
||||
const fixedJsCode = jsCode
|
||||
.replace(
|
||||
/([a-zA-Z]+)\.([a-zA-Z]+)=function\(([a-zA-Z]+)\){return"static\/js\/"/g,
|
||||
const getReplaceArgs = (language: "js" | "css"): Parameters<typeof String.prototype.replace> => [
|
||||
new RegExp(`([a-zA-Z]+)\\.([a-zA-Z]+)=function\\(([a-zA-Z]+)\\){return"static\\/${language}\\/"`, "g"),
|
||||
(...[, n, u, e]) => `
|
||||
${n}[(function(){
|
||||
${
|
||||
@ -38,8 +37,12 @@ export function replaceImportsFromStaticInJsCode(params: { jsCode: string; urlOr
|
||||
`
|
||||
}
|
||||
return "${u}";
|
||||
})()] = function(${e}) { return "${urlOrigin === undefined ? "/build/" : ""}static/js/"`,
|
||||
)
|
||||
})()] = function(${e}) { return "${urlOrigin === undefined ? "/build/" : ""}static/${language}/"`,
|
||||
];
|
||||
|
||||
const fixedJsCode = jsCode
|
||||
.replace(...getReplaceArgs("js"))
|
||||
.replace(...getReplaceArgs("css"))
|
||||
.replace(/([a-zA-Z]+\.[a-zA-Z]+)\+"static\//g, (...[, group]) =>
|
||||
urlOrigin === undefined
|
||||
? `window.${ftlValuesGlobalName}.url.resourcesPath + "/build/static/`
|
||||
|
@ -35,6 +35,12 @@ import { assetIsSameCode } from "../tools/assertIsSameCode";
|
||||
922: "be170a73"
|
||||
} [e] + ".chunk.js"
|
||||
}
|
||||
|
||||
t.miniCssF=function(e){return"static/css/"+e+"."+{
|
||||
164:"dcfd7749",
|
||||
908:"67c9ed2c"
|
||||
}[e]+".chunk.css"
|
||||
}
|
||||
`;
|
||||
|
||||
{
|
||||
@ -69,6 +75,20 @@ import { assetIsSameCode } from "../tools/assertIsSameCode";
|
||||
922: "be170a73"
|
||||
} [e] + ".chunk.js"
|
||||
}
|
||||
|
||||
t[(function (){
|
||||
Object.defineProperty(t, "p", {
|
||||
get: function() { return window.kcContext.url.resourcesPath; },
|
||||
set: function (){}
|
||||
});
|
||||
return "miniCssF";
|
||||
})()] = function(e) {
|
||||
return "/build/static/css/" + e + "." + {
|
||||
164:"dcfd7749",
|
||||
908:"67c9ed2c"
|
||||
} [e] + ".chunk.css"
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
assetIsSameCode(fixedJsCode, fixedJsCodeExpected);
|
||||
@ -107,6 +127,20 @@ import { assetIsSameCode } from "../tools/assertIsSameCode";
|
||||
922: "be170a73"
|
||||
} [e] + ".chunk.js"
|
||||
}
|
||||
|
||||
t[(function (){
|
||||
var p= "";
|
||||
Object.defineProperty(t, "p", {
|
||||
get: function() { return ("kcContext" in window ? "https://demo-app.keycloakify.dev" : "") + p; },
|
||||
set: function (value){ p = value; }
|
||||
});
|
||||
return "miniCssF";
|
||||
})()] = function(e) {
|
||||
return "static/css/" + e + "." + {
|
||||
164:"dcfd7749",
|
||||
908:"67c9ed2c"
|
||||
} [e] + ".chunk.css"
|
||||
}
|
||||
`;
|
||||
|
||||
assetIsSameCode(fixedJsCode, fixedJsCodeExpected);
|
||||
|
Loading…
x
Reference in New Issue
Block a user