Netlify पर Deploy करना
In this page:
# public/_redirects
/* /index.html 200
Basic Netlify Deployment Setup
एक Git repository को Netlify से connect करना और एक build command (जैसे npm run build) plus एक publish directory (जैसे dist) specify करना — usually इतना ही काफी है। Netlify हर push पर अपने आप आपका app build और deploy करता है, बिना manual server setup के।
उदाहरण: Deploying to Netlify from the CLI
$ npm install -g netlify-cli
$ netlify login
$ netlify init
? Build command: npm run build
? Directory to deploy: dist
$ netlify deploy --prod
⚠️ Run this in your own terminal or Node.js environment.
Redirects से Client-Side Routing Fix करना
एक React Router app के पास सिर्फ ONE असली HTML file होती है (index.html) — बाकी सारे pages client-side पर JavaScript से render होते हैं।
Netlify को यह बताए बिना, /about जैसा एक page सीधे load करना या refresh करना एक असली 404 return करता है, क्योंकि server पर कोई असली /about file मौजूद नहीं। एक redirect rule इसे हमेशा index.html serve करके और React Router को control लेने देकर fix करता है।
उदाहरण: The _redirects File
$ cat public/_redirects
/* /index.html 200
⚠️ Run this in your own terminal or Node.js environment.
Netlify पर Environment Variables Set करना
Local .env files कभी Netlify पर upload नहीं होती (वे typically gitignored होती हैं) — production environment variables को Netlify की अपनी site settings dashboard में अलग से configure करना होता है, ताकि production build में सही values build process के दौरान बेक हो जाएं।
उदाहरण: Setting a Netlify Environment Variable
$ netlify env:set VITE_API_URL https://api.example.com
Set environment variable VITE_API_URL with value https://api.example.com
⚠️ Run this in your own terminal or Node.js environment.
- गलत build command या publish directory set करना, जिससे Netlify एक empty या broken site serve करता है।
- Client-side routing (React Router) के लिए एक redirect rule configure करना भूल जाना, जो homepage के अलावा किसी भी direct page load पर 404 का कारण बनता है।
- Netlify के dashboard में production environment variables set न करना, deployed app को ज़रूरी config के बिना छोड़ना।
- Netlify एक popular static-hosting platform है, जो एक React app का production build deploy करने के लिए well-suited है।
- Deployment को typically सिर्फ एक build command (
npm run build) और output folder (distयाbuild) चाहिए। - Direct page loads/refreshes पर client-side routing काम करने के लिए एक redirect rule (
netlify.tomlया एक_redirectsfile से) चाहिए। - Environment variables को Netlify के अपने dashboard में configure करना होता है, आपकी local
.envfiles से अलग।
कोई React-version restriction नहीं — एक hosting/deployment workflow है, कोई code feature नहीं।
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