Skip to content

Commit

Permalink
Support for React.lazy() #141 πŸŽ‰
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Jul 29, 2022
1 parent ff2fb0d commit b116f22
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
24 changes: 24 additions & 0 deletions src/bin/build-keycloak-theme/replaceImportFromStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,35 @@ 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,
(...[, n, u, e]) => `
${n}[(function(){
${
urlOrigin === undefined
? `
Object.defineProperty(${n}, "p", {
get: function() { return window.${ftlValuesGlobalName}.url.resourcesPath; },
set: function (){}
});
`
: `
var p= "";
Object.defineProperty(${n}, "p", {
get: function() { return ("${ftlValuesGlobalName}" in window ? "${urlOrigin}" : "") + p; },
set: function (value){ p = value;}
});
`
}
return "${u}";
})()] = function(${e}) { return "${urlOrigin === undefined ? "/build/" : ""}static/js/"`,
)
.replace(/([a-zA-Z]+\.[a-zA-Z]+)\+"static\//g, (...[, group]) =>
urlOrigin === undefined
? `window.${ftlValuesGlobalName}.url.resourcesPath + "/build/static/`
: `("${ftlValuesGlobalName}" in window ? "${urlOrigin}" : "") + ${group} + "static/`,
)
//TODO: Write a test case for this
.replace(/".chunk.css",([a-zA-Z])+=([a-zA-Z]+\.[a-zA-Z]+)\+([a-zA-Z]+),/, (...[, group1, group2, group3]) =>
urlOrigin === undefined
? `".chunk.css",${group1} = window.${ftlValuesGlobalName}.url.resourcesPath + "/build/" + ${group3},`
Expand Down
30 changes: 15 additions & 15 deletions src/test/bin/replaceImportFromStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@ import { assetIsSameCode } from "../tools/assertIsSameCode";
}[e] + ".chunk.js"
}
function f2() {
function sameAsF() {
return a.p+"static/js/" + ({}[e] || e) + "." + {
3: "0664cdc0"
}[e] + ".chunk.js"
}
n.u = function(e) {
return "static/js/" + e + "." + {
n.u=function(e){return"static/js/" + e + "." + {
147: "6c5cee76",
787: "8da10fcf",
922: "be170a73"
} [e] + ".chunk.js"
}
`;

{
Expand All @@ -52,17 +50,19 @@ import { assetIsSameCode } from "../tools/assertIsSameCode";
}[e] + ".chunk.js"
}
function f2() {
function sameAsF() {
return window.kcContext.url.resourcesPath + "/build/static/js/" + ({}[e] || e) + "." + {
3: "0664cdc0"
}[e] + ".chunk.js"
}
n.u = function(e) {
n[(function (){
Object.defineProperty(n, "p", {
get: function() { return window.kcContext.url.resourcesPath; },
set: function (){}
});
return "u";
})()] = function(e) {
return "/build/static/js/" + e + "." + {
147: "6c5cee76",
787: "8da10fcf",
Expand All @@ -87,20 +87,20 @@ import { assetIsSameCode } from "../tools/assertIsSameCode";
}[e] + ".chunk.js"
}
function f2() {
function sameAsF() {
return ("kcContext" in window ? "https://demo-app.keycloakify.dev" : "") + a.p + "static/js/" + ({}[e] || e) + "." + {
3: "0664cdc0"
}[e] + ".chunk.js"
}
n.u = function(e) {
{
var p= "";
Object.defineProperty(n, "p", {
get: function() { return ("kcContext" in window ? "https://demo-app.keycloakify.dev" : "") + p; },
set: function (value){ p = value;}
});
}
n[(function (){
var p= "";
Object.defineProperty(n, "p", {
get: function() { return ("kcContext" in window ? "https://demo-app.keycloakify.dev" : "") + p; },
set: function (value){ p = value; }
});
return "u";
})()] = function(e) {
return "static/js/" + e + "." + {
147: "6c5cee76",
787: "8da10fcf",
Expand Down

0 comments on commit b116f22

Please sign in to comment.