Kickstart your ReactJS project with Vite, Yarn, and TypeScript + SWC for lightning-fast builds and type-safe code. This setup ensures a smooth development experience, faster compilation, and better maintainability—perfect for both small and large-scale applications!
Install Node.js
Make sure you have Node.js version 14.18 or higher installed. You can download it from Node.js Official Website.
Install Yarn
Run the following command to install Yarn globally:
npm install --global yarn
Verify the installation
To ensure Yarn is installed correctly, check the version:
yarn --version
Open your terminal and run the following command:
yarn create vite
You will be prompted to enter a project name. Enter your desired name (e.g., my-react-app
) and press Enter.
Next, you will be asked to choose a framework. Use the arrow keys to select React and press Enter.
When prompted to choose a variant, select TypeScript + SWC
. This is highly recommended for several reasons:
TypeScript adds static typing to your project, helping you catch errors during development and improving code maintainability, especially in large projects.
SWC (Speedy Web Compiler) is a super-fast JavaScript and TypeScript compiler that significantly reduces build time compared to the default TypeScript compiler.
By combining TypeScript with SWC, you get the benefits of type safety and faster builds, resulting in a smoother and more efficient development experience.
Once the project is created, navigate to the project directory using:
cd my-react-app
Run the following command to install all necessary dependencies:
yarn
After installing the dependencies, start the Vite development server by running:
yarn dev
You’ll see an output similar to:
VITE vX.X.X ready in X ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
Open your browser and go to http://localhost:5173/
to see your React application running.
Use Visual Studio Code or your favorite editor to open the project folder. You can start editing the files in the src
directory:
src/main.tsx
: The entry point of your React application.
src/App.tsx
: The main component where you can start building your application.
When your application is ready for deployment, you can build it for production by running:
yarn build
This will create an optimized build in the dist
folder.
To preview the production build locally, run:
yarn preview
This will start a local server that serves the built files.
Fast Development:
Vite is known for its lightning-fast development server, thanks to its efficient module handling system.
TypeScript + SWC for Better Performance:
TypeScript improves code quality and makes your project easier to maintain by adding static type checking.
SWC compiles TypeScript much faster than the default TypeScript compiler, especially in large projects.
Yarn for Dependency Management:
Yarn is faster and more reliable than npm in handling dependencies, especially in monorepos or projects with complex dependencies.
By following this guide and choosing TypeScript + SWC, you’re setting up a modern ReactJS project with fast build times and better code reliability. This setup is ideal for both small and large-scale applications, ensuring a smoother development workflow and easier future maintenance.
If you need further assistance, feel free to reach out!
The complete source code for this project is available on GitHub