Production Build बनाना
In this page:
Development Mode Production-Ready क्यों नहीं है
Development server (npm run dev) runtime speed से ज़्यादा fast rebuilds और helpful warnings/error messages को prioritize करता है, जो चाहिए वास्तविक users को उससे इसे noticeably slower और larger बनाते हुए।
एक production build इस dev-only overhead को strip करता है और minification जैसे real optimizations apply करता है।
- Development mode आपकी coding के दौरान iteration speed के लिए optimized है
- Production mode आपके USERS के experience के लिए optimized है।
उदाहरण: Dev Server vs. Production Build Output
$ npm run dev
VITE v5.0.0 ready in 320 ms
➜ Local: http://localhost:5173/
# unminified, includes dev warnings, rebuilds instantly on save
$ npm run build
vite v5.0.0 building for production...
✓ 34 modules transformed.
dist/assets/index-4f3a2b1c.js 142.31 kB │ gzip: 45.62 kB
# minified, dev warnings stripped, optimized for users
⚠️ Run this in your own terminal or Node.js environment.
Build Process Actually क्या करता है
Build command run करना आपके सारे JavaScript/CSS को optimized files में bundle करता है, इन्हें minify करता है (whitespace हटाते और variable names shorten करते हुए), और अक्सर faster initial loading के लिए code को छोटे chunks में split करता है — सब मिलकर एक static output folder (dist या build) produce करते हुए serving के लिए ready।
उदाहरण: Running the Build Command
$ npm run build
vite v5.0.0 building for production...
✓ 34 modules transformed.
dist/index.html 0.46 kB
dist/assets/index-4f3a2b1c.js 142.31 kB │ gzip: 45.62 kB
dist/assets/index-9c8d7e6f.css 3.21 kB │ gzip: 1.10 kB
$ ls dist
assets index.html
⚠️ Run this in your own terminal or Node.js environment.
Production Build को Locally Preview करना
Deploy करने से पहले, actually production build को locally run करना और click through करना important है, क्योंकि कुछ bugs सिर्फ optimized/minified version में दिखते हैं, more forgiving development server में नहीं।
Vite का 'vite preview' command exactly इसी purpose के लिए locally built output serve करता है।
उदाहरण: Previewing the Build Locally
$ npm run build
✓ built in 1.2s
$ npm run preview
➜ Local: http://localhost:4173/
⚠️ Run this in your own terminal or Node.js environment.
- Development server (npm run dev) deploy करना एक real production build के बजाय — dev servers slower हैं और real users के लिए नहीं बने।
- Deploy करने से पहले actual production build locally test न करना, build-specific bugs miss करते हुए जो dev mode में नहीं दिखते।
- यह भूल जाना कि environment-specific configuration (जैसे API URLs) को production build के लिए correctly set होना चाहिए, development defaults के रूप में नहीं छोड़ा जाना चाहिए।
- एक production build real users के लिए आपके app का code compile, minify, और optimize करता है, development server के विपरीत।
- 'npm run build' (Vite/Create React App convention) optimized files का एक static folder generate करता है deploy करने के लिए ready।
- Deploy करने से पहले हमेशा actual production build locally test करें (जैसे 'vite preview' के through)।
- Production builds development-only warnings strip करते हैं और optimizations enable करते हैं जो apps को meaningfully faster बनाते हैं।
Build-tool feature — आपके app को already जो चाहिए उससे parे कोई specific React version requirement नहीं।
Chapter Quiz — Complete all 13 topics to unlock
0/13 topics done
Complete these topics first:
- Why Performance Matters
- Optimizing with React.memo
- Avoiding Unnecessary Re-renders
- Using the React Profiler
- Analyzing Bundle Size
- Image Optimization Techniques
- React as a PWA
- Creating a Production Build
- Environment Variables in React
- Deploying to Netlify
- Deploying to Vercel
- Basic CI/CD for React Apps
- SEO Basics for React SPAs