Creating and opening a React.js project using Vite involves a few simple steps. Here's a quick guide:
-
Install Node.js: Ensure that you have Node.js installed on your system. If not, you can download and install it from Node.js official website.
-
Install Vite: Open your terminal or command prompt, and run the following command to globally install Vite:
npm install -g create-vite
-
Create a New React Project with Vite: Run the following command to create a new React project. Replace
my-react-project
with your desired project name:create-vite my-react-project --template react
-
Navigate to Your Project Directory: Change to the directory of your new project:
cd my-react-project
-
Install Dependencies: Install the necessary dependencies by running:
npm install
-
Start the Development Server: To start the development server, run:
npm run dev
This command will start the local development server and usually opens your new React application in your default web browser automatically. If it doesn't, you can manually open it by visiting
http://localhost:3000
in your browser. -
Building for Production: When you're ready to build your project for production, run:
npm run build
This command will create a
dist
folder in your project directory, containing all the optimized files ready for deployment. -
Previewing the Production Build: To preview your production build locally, you can run:
npm run preview