Learn how to generate optimized production builds of your customizations.
Build your project for deployment:
npm run build
That’s it. Your optimized files will be available in the dist/ directory.
During the build, Vite automatically performs:
Vite automatically clears the dist/ directory before generating new files.
Development Code:
Production Output:
Readable code becomes compact and optimized.
npm run build
Example Output:
ls -lh dist/
You should see:
dashboard.jsdashboard.cssmanifest.jsonassets/Test locally before deployment:
npm run preview
This starts a local server that simulates production.
http://localhost:4173
Located in vite.config.js:
build: { sourcemap: true }
⚠ Do not enable source maps in public production releases.
| Feature | Development | Production |
|---|---|---|
| HMR | ✅ | ❌ |
| File Size | Large | Optimized |
| Performance | Lower | High |
| Debugging | Easy | Limited |
| Use Case | Development | Live Site |
| Scenario | WordPress Loads |
|---|---|
| Dev server running | Files from localhost:8080 |
| Dev server stopped | Files from dist/ |
dist/)npm install --save-dev rollup-plugin-visualizer
import { visualizer } from 'rollup-plugin-visualizer';
plugins: [visualizer({ open: true, gzipSize: true })]
const HeavyComponent = lazy(() => import('./HeavyComponent'));
<Suspense fallback={}>
npm dedupe
Avoid large unnecessary libraries.
npm installdist/Before going live:
Build
npm run build
Preview
npm run preview
Check Output
ls -lh dist/