Context

A Vite 8 app built with base: '/my-app/' to deploy as a GitHub Pages project site. vite preview showed a blank page: the HTML and CSS loaded, but the hashed entry JS came back 404.

Insight

A blank page from vite preview after setting base doesn’t mean the build is broken. Check with a plain static server before you debug the config.

  • curl got 200 for the same JS URL. The 404 only appeared when the request carried Sec-Fetch-Dest: script, which browsers send for module scripts. I didn’t track down the cause inside Vite.
  • The same dist/ served from a plain static server loaded every asset with no console errors. The real GitHub Pages deploy worked too.

Reproduce

Terminal window
curl -s -o /dev/null -w "%{http_code}\n" http://localhost:4173/my-app/assets/index-<hash>.js
# 200
curl -s -o /dev/null -w "%{http_code}\n" -H 'Sec-Fetch-Dest: script' http://localhost:4173/my-app/assets/index-<hash>.js
# 404

Check a subpath build instead

Put dist/ in a folder named after the base path and serve its parent:

8000/my-app/
mkdir -p /tmp/pages-root
cp -R dist /tmp/pages-root/my-app
cd /tmp/pages-root && python3 -m http.server 8000