Converting from Create React App to Vite

Tram Ho

Introduce

Create React App (CRA)

Is a set of development tools for your React application. It will be suitable for beginners because you do not need to care about the installation of tools that need to be integrated into the project. However, CRA also has limitations in terms of speed and performance

ViteJS

It is a tool to help programmers develop applications faster and cleaner

=> In the past time, Vite has also confirmed the value it brings, so it is used by leading programmers and with a large community of support. In this article, I will not show the pros / cons of each type, but I will guide you to move your project from CRA to Vite.

Start

1. In the package.json file:

2. Run npm install or yarn to download new libraries

3. Move index.html file from public/index.html => index.html in root project folder

4. In the file index.html remove %PUBLIC_URL%

5. In the file index.html edit the path pointing to the file index.jsx

6. Create config file vite.config.js

7. Create an absolute path

  • In vite.config.js

8. In the .env file change REACT_APP_ => VITE_

Environment variable setting

Use

9. In Typescript projects it is necessary to create the file vite-env.d.ts in the src . folder

Thus, the transition from CRA to Vite has been completed. You guys start yarn to see the speed of running the server as well as when building to see the benefits of ViteJS. In the next article, I will update a few versions of ViteJs to see what upgrades it has. As well as a performance comparison between ViteJS and Webpack

Share the news now

Source : Viblo