Fix routing for vite prefix on dev vs build #319
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes the bad change I made in #317 where the build output was fixed, but
pnpm run dev
stopped working.The explanation for behavior is as follows
/@vite/...
,/@id/...
,/src/...
, etc.base = '/admin/'
globally, every module request during dev showed up as/admin/@id/__x00__virtual:react-router/....
Because those paths no longer start with/@id/
, Vite never sees them;the request falls through to the React Router/Hono layer.
“No route matches /admin/app/tailwind.css”
and HMR stops working. You get this exact failure: CSS 404s and broken runtime modules./admin
work in dev we’d have to wrap the entire dev server behind a proxy that strips the prefix before Vite sees it, or fork the Vite dev server to recognize prefixed paths. That’s doable but involves substantial custom middleware; the official Vite docs explicitly note that base only affects the build output.By contrast, production and pnpm preview are fine with the prefix because they serve the built bundle (where every asset already carries
/admin
). So the workable compromise is:command === 'build'
, so the production bundle ships with /admin./
so Vite’s middleware can catch/@id
,/@fs
, etc., and HMR keeps working.Docs links:
This time I actually tested dev :)