Fix PUBLIC_URL typing
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import { nameOfTheGlobal, basenameOfTheKeycloakifyResourcesDir } from "keycloakify/bin/constants";
|
import { nameOfTheGlobal, basenameOfTheKeycloakifyResourcesDir } from "keycloakify/bin/constants";
|
||||||
|
import { assert } from "tsafe/assert";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is an equivalent of process.env.PUBLIC_URL thay you can use in Webpack projects.
|
* This is an equivalent of process.env.PUBLIC_URL thay you can use in Webpack projects.
|
||||||
@ -7,7 +8,14 @@ import { nameOfTheGlobal, basenameOfTheKeycloakifyResourcesDir } from "keycloaki
|
|||||||
export const PUBLIC_URL = (() => {
|
export const PUBLIC_URL = (() => {
|
||||||
const kcContext = (window as any)[nameOfTheGlobal];
|
const kcContext = (window as any)[nameOfTheGlobal];
|
||||||
|
|
||||||
return kcContext === undefined || process.env.NODE_ENV === "development"
|
if (kcContext === undefined || process.env.NODE_ENV === "development") {
|
||||||
? process.env.PUBLIC_URL
|
assert(
|
||||||
: `${kcContext.url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}`;
|
process.env.PUBLIC_URL !== undefined,
|
||||||
|
`If you use keycloakify/PUBLIC_URL you should be in Webpack and thus process.env.PUBLIC_URL should be defined`
|
||||||
|
);
|
||||||
|
|
||||||
|
return process.env.PUBLIC_URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${kcContext.url.resourcesPath}/${basenameOfTheKeycloakifyResourcesDir}`;
|
||||||
})();
|
})();
|
||||||
|
Reference in New Issue
Block a user