Show how to import from public/

This commit is contained in:
Joseph Garrone 2024-01-11 15:06:43 +01:00
parent 0735f23464
commit 7a3589610c
6 changed files with 41 additions and 0 deletions

31
src/PUBLIC_URL.ts Normal file
View file

@ -0,0 +1,31 @@
import { kcContext as kcLoginThemeContext } from "keycloak-theme/login/kcContext";
import { kcContext as kcAccountThemeContext } from "keycloak-theme/login/kcContext";
/**
* If you need to use process.env.PUBLIC_URL, use this variable instead.
* If you can, import your assets using the import statement.
*
* See: https://docs.keycloakify.dev/importing-assets#importing-custom-assets
*/
export const PUBLIC_URL = (()=>{
const kcContext = (()=>{
if( kcLoginThemeContext !== undefined ){
return kcLoginThemeContext;
}
if( kcAccountThemeContext !== undefined ){
return kcLoginThemeContext
}
return undefined;
})();
return (kcContext === undefined || process.env.NODE_ENV === "development")
? process.env.PUBLIC_URL
: `${kcContext.url.resourcesPath}/build`;
})();