Export polyfill of process.env.PUBLIC_URL

This commit is contained in:
Joseph Garrone 2024-02-09 17:52:26 +01:00
parent 1f79a8f7dc
commit 217439d673

13
src/PUBLIC_URL.ts Normal file
View File

@ -0,0 +1,13 @@
import { nameOfTheGlobal, basenameOfTheKeycloakifyResourcesDir } from "keycloakify/bin/constants";
/**
* This is an equivalent of process.env.PUBLIC_URL thay you can use in Webpack projects.
* This works both in your main app and in your Keycloak theme.
*/
export const PUBLIC_URL = (() => {
const kcContext = (window as any)[nameOfTheGlobal];
return kcContext === undefined || process.env.NODE_ENV === "development"
? process.env.PUBLIC_URL
: `${kcContext.url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}`;
})();