The React application uses Vite as the bundler and react-router-dom for routing. The project shows a blank white screen with no visible errors when running in development mode.
- Avoid unnecessary exclusions of packages from Vite’s optimization unless specifically required and documented.
- Clear Vite’s cache (
node_modules/.vite) and reinstall dependencies after changing the config.
-
npm run buildornpx vite buildtriggers the production build process:- Compiles, optimizes, and outputs static files in the
dist/folder. npx vite buildruns the build directly without relying on an npm script, useful for quick testing or debugging.
- Compiles, optimizes, and outputs static files in the
-
npm run previewserves the production build locally for testing. -
When deploying a Single Page Application (SPA) using
BrowserRouter, configure your web server to redirect all requests toindex.htmlto ensure proper client-side routing. -
Alternatively, use
HashRouterto avoid server-side routing configuration.
| Action | Command | Notes |
|---|---|---|
| Start development server | npm run dev |
Runs dev server with hot module replacement |
| Build production bundle | npm run build |
Creates optimized static files in dist/ |
| Build without npm script | npx vite build |
Equivalent to npm run build without script |
| Preview production build | npm run preview |
Locally serves the production build |