← Back to React Course | Chapter 1: Environment Setup & Tooling | Lesson 5 of 10

Vite से App बनाना

Vite React projects बनाने के लिए एक faster, lighter machine है, एक modern power tool किसी पुराने की जगह लेने जैसा।
Syntax
markup
npm create vite@latest app-name -- --template react
cd app-name
npm install
npm run dev

Vite इतना Popular क्यों है

Vite एक build tool है जो dev server almost instantly start करता है और आपके file save करने पर browser को milliseconds में update करता है, क्योंकि यह आपकी source files को native ES modules के through directly serve करता है पहले से सब कुछ bundle करने के बजाय जैसे older tools करते हैं।

Note: एक नया Vite + React project scaffold करने के लिए npm create vite@latest my-app -- --template react run करें।
Warning: Vite का instant dev-server startup इसका मतलब नहीं कि production build bundling skip करती है -- npm run build असली users के लिए अब भी सब कुछ bundle करता है।

उदाहरण: Why Vite Is Popular

bash
$ npm create vite@latest my-app -- --template react
$ npm run dev
  ready in 180ms

⚠️ Run this in your own terminal or Node.js environment.

Vite की Project Structure

एक Vite + React project में project root पर एक index.html है (public/ के अंदर नहीं, CRA के विपरीत), entry point के रूप में main.jsx के साथ एक src/ folder, और build settings के लिए एक vite.config.js file।

Note: main.jsx वह जगह है जहां ReactDOM.createRoot आपके App component को render करता है, CRA के index.js को mirror करते हुए।
Warning: Vite का index.html project root पर रहना (src/ या public/ के अंदर नहीं) Create React App से आने वाले developers को surprise करता है।

उदाहरण: Vite's Project Structure

bash
$ ls -R my-app
my-app:
index.html  node_modules  package.json  public  src  vite.config.js

my-app/public:
vite.svg

my-app/src:
App.css  App.jsx  assets  index.css  main.jsx

⚠️ Run this in your own terminal or Node.js environment.

Vite के साथ Run और Build करना

npm run dev Vite का development server start करता है; npm run build एक optimized production bundle एक dist/ folder में बनाता है, deploy करने के लिए ready।

Note: deploy करने से पहले early issues पकड़ने के लिए npm run preview से locally एक production build preview करें।
Warning: dist/ built folder के बजाय directly src/ folder deploy करना काम नहीं करेगा -- browsers को compiled output चाहिए।

उदाहरण: Running and Building with Vite

bash
npm run dev    # local dev server
npm run build  # bundles into dist/

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. npm create vite@latest run करते समय React template select करना भूल जाना।
  2. Create React App जैसी exact file structure की उम्मीद करना -- Vite के defaults थोड़े अलग हैं।
  3. एक Vite project clone करने के बाद npm run dev से पहले npm install न run करना।
चैप्टर सारांश
  • Vite एक fast, modern build tool है जो अब एक React project शुरू करने का recommended तरीका है।
  • यह development के दौरान near-instant server start और hot reload के लिए native ES modules उपयोग करता है।
  • npm create vite@latest एक template picker के साथ एक नया project scaffold करता है।
  • npm run dev dev server start करता है; npm run build production bundle बनाता है।
ब्राउज़र सपोर्ट

Generated app सभी modern evergreen browsers को support करता है; Vite का dev server खुद सिर्फ development के दौरान browser में native ES module support पर depend करता है।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.