Deploying React AppsEntry 6 of 11
Building for Production
The build command compiles, bundles, minifies, and tree-shakes the app into static files ready to deploy.
Notes
- Vite:
npm run buildoutputs todist/(Create React App usedbuild/). - Output:
index.html, plus hashed JS/CSS files inassets/(e.g.index-a1b2c3.js). Lazy-loaded pages appear as separate chunks. - Hashed file names let hosts cache assets forever; a new build produces new names.
npm run previewserves the production build locally for a final check.- Development-only code (React's dev warnings, StrictMode double effects) is removed.
What / Why / When
- What
Production-optimized output.
- Why
Far smaller and faster than the dev server.
- When
Before every deploy.
Code compare
npm run build # → dist/npm run preview # test the build locallyng build # production is the default configurationAngular's build also enforces budgets (angular.json) and warns when bundles grow too large.
Quick reference
| Task | React (Vite) | Angular |
|---|---|---|
| Build | npm run build | ng build |
| Output | dist/ | dist/<project>/browser/ |
| Preview locally | npm run preview | npx http-server dist/<project>/browser |
| Bundle limits | Plugins (e.g. rollup-plugin-visualizer) | Built-in budgets |