Skip to main content

Command Palette

Search for a command to run...

Introduction to Vite: The Next Generation Frontend Tooling

Let's learn about Vite tool and why it is a developer's favourite these days!

Updated
Introduction to Vite: The Next Generation Frontend Tooling
V

I'm a solutions engineer lead, GitHub Star, Director of WomenDevsSG, and co founder of ragTech. I work at the intersection of tech, systems, and leadership, and this blog is where I share my journey through all three. Expect honest reflections, real experiences, and thoughts that are still forming rather than polished career advice.

As a React developer, using Create React App to start new projects and run them can be a pain. Firstly, it is slow to install all the 140MB dependencies when creating a new app. Next, it uses Webpack to bundle the code each time new changes are made. Hence, the larger the app gets, the longer it will take to rebuild the app to reflect changes.

In this article, let me introduce you to Vite, the next generation frontend tooling. At the end of this article, you will learn what are the key features of Vite and how you can easily set up your React Apps with it.

What is Vite and why use it?

Some of you may have heard of Vite before, but what exactly does it do?

Faster server starts

It is essentially a solution to long server starts by serving code over native ES modules. Most tools we have seen like webpack, Rollup and Parcel will hit a performance bottleneck as the application gets larger. It can become quite slow to start the dev server, which can make it frustrating for developers.

This is because those tools are bundle-based, meaning the code has to be completely bundled first in order to start the server.

bundle.png

So you can imagine that for large-scale applications, this can be an issue that impedes developer productivity.

Vite, on the other hand, uses native ES modules (ESM) to serve the code. According to their documentation, this means:

Letting the browser take over part of the job of a bundler. 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.

Source: Vite documentation

native.png

Faster Updates

Some bundlers like webpack support Hot Module Replacement (HMR). This is when a running application reflects only the changes made, without having to reload the full page. However, as the application gets larger, HMR does take longer, making the page update slower.

Vite also solves this problem as HMR is performed over native ESM. This means that HMR will continue updating the page fast, regardless of the app's size.

Using Vite: Setup a React App

Now that we've learned why Vite is a powerful tool that solves common web development challenges, let's start using it!

In this example, I will show you how to setup a React app using Vite. After this, you will no longer have to experience the slowness with Create React App.

Step 1: Create Vite Project

First, run the command to create a Vite project:

npm create vite@latest

You will then be asked to name your project like so:

terminal.png

Next, select the 'React' framework for this example:

image.png

And you're done! It's almost an instant process, isn't it?

Alternatively...

You can simply create a new React app without going through the options using this command:

npm create vite my-vite-react-app --template react

And yes, don't worry. The app itself has the same structure as what you would expect if you have used Create React App.

app.png

Step 2: Run & Start the server

Finally, install the dependencies we need and start the app with the following command:

npm install && npm run dev

react.png

Conclusion

There we have it! Thanks for reading! I hope you have found this article useful in understanding what Vite is, why it is used and how to use it.

For more information, do check out the links below to learn more about Vite and its capabilities. Please share this article and give a like if you have enjoyed the read. Cheers!


More Reading/References

D

Amazing read! Thanks for sharing this 👍 I was just thinking about reading on Vite and this helps!

Another great and clear article Victoria Lo! 🤗

12
A

Really explained the topic really well! Thanks for the valuable article, keep it going💪

1
S

Such an elegant writing Victoria, Cheers! It was great to learn about vite

2
T
Tùng Vũ3y ago

Nice!

Thanks for the introduction to vite, i just tried it with vuejs framework, reactjs i haven't tried it yet. May I ask if there is a way to combine the power of Vite + the SEO capabilities of Nextjs?

M

I really wondered what makes Vite different and this article explained it really well. Thanks Victoria Lo

2
A

Awesome I was just thinking about writing an article on Vite!

Another good one Victoria Lo 😄

1
P

Thanks for giving some good reasons to try this, it does indeed speed things up and keeps them simple. Thanks!

2
V

Thanks for reading Peter 😊

C

Nice!

Have you also tried migrating an existing webpack react app to Vite? I really want to give it a try, but it seems like such a pain to move over.

4
U

It's honestly pretty easy to move to Vite. It isn't hectic. And if you get stuck, their community is very active on their Discord server

F

Same question I wanted to ask

V

Yes Chris Bongers! I have, thanks to this article by Nilanth. It's really easy~ :)

2
N
Nilanth3y ago

Victoria Lo Thanks. 👍

1

Super Newbie Web Dev

Part 5 of 49

Let's be honest. We all started from level 0. There's no shame in that. Here's the series for the newbies~ Hope you can learn and feel free to ask a lot of questions! Check my other series: Random project to build

Up next

How to Use State Machines in Your Apps

What is a state machine? A finite state machine is mathematical model of computation, often used to design algorithms. It describes the behaviour of a system, which is defined in one single state at a time from a finite number of possible states. For...