Copies the multi-page demo app (Providers → Packages → Comparison flow) with Zustand basket state, URL sync, and per-slice Vite build config. All pages render correctly on React 19 + MUI v7 with zero code changes needed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
18 lines
756 B
TypeScript
18 lines
756 B
TypeScript
/**
|
|
* Resolve a public-asset path against Vite's base URL.
|
|
*
|
|
* In dev `import.meta.env.BASE_URL === '/'`, so `assetUrl('/images/foo.png')`
|
|
* returns `/images/foo.png` unchanged. In production the build sets base to
|
|
* `/arrangement/` (or whatever `--mode <slice>` was passed), and the same
|
|
* call returns `/arrangement/images/foo.png` so the bundled assets resolve
|
|
* correctly under the slice subpath.
|
|
*
|
|
* Always pass leading-slash paths — they're relative to the publicDir root.
|
|
*/
|
|
export const assetUrl = (path: string): string => {
|
|
const base = import.meta.env.BASE_URL;
|
|
const cleanBase = base.endsWith('/') ? base.slice(0, -1) : base;
|
|
const cleanPath = path.startsWith('/') ? path : `/${path}`;
|
|
return `${cleanBase}${cleanPath}`;
|
|
};
|