To create a React app using Vite, follow these steps:
Install Node.js (version 16 or higher recommended) if not already installed.
Open your terminal and run the following command to scaffold a new React project with Vite:
npm create vite@latest my-react-app --template reactReplace
my-react-appwith your desired project name.Navigate into the project directory:
cd my-react-appInstall the project dependencies:
npm installStart the development server:
npm run devOpen your browser and go to
http://localhost:5173to view your new React app.
Key Features of Vite:
Instant Server Start: Uses native ES modules for near-instant startup.
Fast Hot Module Replacement (HMR): Changes appear in the browser almost immediately.
Optimized Production Builds: Uses Rollup for efficient bundling.
For a TypeScript version, use the react-ts template instead:
npm create vite@latest my-react-app --template react-tsI was able to do this using a single file build plugin called viteSingleFile.
Just add it to the plugins in vite.config.js|ts file:
export default defineConfig({
plugins: [react(), viteSingleFile()]
})
Answer from Asen Tolsuzov on Stack Overflow