DEV Community

loading...

Get Faster Creating React Project with Vite

Moch Farras Fauzan
a living human being who interested into computer stuffs and always share what he learn.
・Updated on ・2 min read

I am new in react and also still learning how to use react. I'm using create-react-app to make react project. The first thing that I notice whenever I created react project with create-react-app are;

  1. The time it took to make a single project .
  2. The time it took to start the project.

But all that changed when I got to know ViteJs

What is ViteJs?

According to vite website, Vite is a French word that means "Fast". So, vite is a build tool that aims to provide a faster and leaner development experience for modern web projects. ViteJs is made by the creator of VueJS.

Why using Vite?

When starting the project server, a bundler-based build setup has seek to your application and build entire application before it can be served.

Vite improves the time that dev server took by dividing the modules in an application into two categories:

  1. Dependencies, Vite pre-bundles dependencies using esbuild. Esbuild is written in Go and pre-bundles dependencies 10-100x faster than JavaScript-based bundlers.

  2. Source code often contains non-javascript like JSX, CSS, or React components that used to be edited very often. Vite only needs to transform and serve source code on demand, as the browser requests it. Code behind conditional dynamic imports is only processed if actually used on the current screen.

Performance between Vite vs create-react-app

To do this testing, I measure the time that both of them took to create and launch react project. And here is the difference between both of them.
image
As you can see the result has significant difference. Either create project or launch project, Vite has a better performance.

How to create react with Vite

To make react project with Vite is very simple. All you need to do is follow this instruction.

  1. npm init vite@latest
  2. Enter project name and select framework (in this case I use React) image
  3. Then select react variant (I choose react) image
  4. Go to your project app folder and enter npm install command. Your project will be ready within a minute.

So that's it what I could share. I'm truly sorry if my English is not good because it isn't my mother tongue. But I keep learning English to make it better. Writing blog also my learning method to improve my English. So if you have any feedback related to the content or to my English, feel free to share!

References
Vite 2.0 Crash Course by codeSTACKr
Vitejs and React by Roberto Butti
Getting Started by Vite

Discussion (0)