Throw if unrecognized bundler when getting BASE_URL for mocks

This commit is contained in:
Joseph Garrone
2024-02-10 20:40:41 +01:00
parent ef5e4fccd3
commit 334ec1870a

View File

@ -2,9 +2,12 @@ import { assert } from "tsafe/assert";
/**
* WARNING: Internal use only!!
* THIS DOES NOT WORK IN KEYCLOAK! It's only for resolving mock assets.
* This is just a way to know what's the base url that works
* both in webpack and vite.
* THIS DOES NOT WORK IN KEYCLOAK! It's only for resolving mock assets.
* You can see this as a polyfill that return `import.meta.env.BASE_URL` when in Vite
* and when in Webpack returns the base url in the same format as vite does meaning
* "/" if hosted at root or "/foo/" when hosted under a subpath (always start and ends with a "/").
*/
export const BASE_URL = (() => {
vite: {
@ -37,5 +40,5 @@ export const BASE_URL = (() => {
return BASE_URL === "" ? "/" : `${BASE_URL}/`;
}
return "/";
throw new Error("Bundler not supported");
})();