mirror of
https://github.com/tiennm99/loto.git
synced 2026-10-11 03:13:40 +00:00
35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
/**
|
|
* SvelteKit `paths.base` resolution, shared between `svelte.config.js`
|
|
* (page routing / prerendering) and `vite.config.js` (PWA precache
|
|
* manifest). Both consumers MUST agree on the base or the service
|
|
* worker's `additionalManifestEntries` end up origin-rooted while the
|
|
* app itself serves under a sub-path (e.g. GitHub Pages `/loto`),
|
|
* causing every precached URL to 404 and the SW install to fail.
|
|
*
|
|
* Resolution order:
|
|
* 1. NEXT_BASE_PATH — explicit override (escape hatch)
|
|
* 2. codeserver dev → /absproxy/{port}
|
|
* 3. BUILD_PROFILE=gh → /loto
|
|
* 4. default (local dev / generic static host) → ""
|
|
*
|
|
* @module base-path
|
|
*/
|
|
import { loadEnv } from "vite";
|
|
|
|
/** @returns {string} */
|
|
export function resolveBase() {
|
|
if (process.env.NEXT_BASE_PATH != null) return process.env.NEXT_BASE_PATH;
|
|
if (process.env.VITE_DEV_PROFILE === "codeserver") {
|
|
// .env.local lives outside process.env at config-eval time; loadEnv reads it.
|
|
const env = loadEnv(
|
|
process.env.NODE_ENV ?? "development",
|
|
process.cwd(),
|
|
"",
|
|
);
|
|
const port = env.CODESERVER_PORT ?? "3000";
|
|
return `/absproxy/${port}`;
|
|
}
|
|
if (process.env.BUILD_PROFILE === "gh") return "/loto";
|
|
return "";
|
|
}
|