🚀 Getting started with Vite
Tags: vite, javascript, vue, tutorial
Published: 2024-03-01 21:46:15

Vite. Vite? Yes! But... what is Vite? Well, Vite is the next generation frontend tooling. It's a build tool that aims to provide a faster and leaner development experience for modern web projects. Come with me and let's explore Vite together. Who knows? Maybe you'll find it interesting and useful for your next project 😉

### What is Vite?

First, let's learn a bit of history, because you know what they say: "Those who don't know history are doomed to repeat it" 📖 Vite is a French word that means "fast". It's pronounced like "veet". The name is a reference to the tool's main selling point: speed. Vite was created by Evan You, the creator of Vue.js, and it's designed to be a build tool that is the next generation in frontend development. If you try Vite, forget about slow builds and waiting for your project to compile. Vite is fast, really fast. It's so fast that it feels like you're working with a framework that has a built-in server. It's like, hmm well... magic! 🎩✨

### Why Vite?

For starters, Vite was designed to solve a problem that many frontend developers face: slow builds. When you're working on a project, you want to see the changes you make in real-time. You don't want to wait for your project to compile every time you make a change. 

![tom cat painting a dog house](https://media.tenor.com/40A4taEpX78AAAAM/tom-and-jerry-preparing.gif)

Even Tom Cat knows that waiting is not fun. Vite addresses slow build times by providing a highly efficient development server that significantly speeds up the feedback loop for developers. It achieves this by using native ES modules in the browser, which allows for on-demand file serving and transformation, and by pre-bundling dependencies with esbuild, which is much faster than traditional JavaScript-based bundlers. This approach not only accelerates the development process, but also reduces the time developers spend waiting for changes to be reflected in the browser, making it feel very responsive.

![combined chunks, kind of like Lego blocks, illustrated to create all different kinds of applications from the same set of modules](https://hacks.mozilla.org/files/2018/03/02_module_scope_04.png)

Like the above illustration from Mozilla(see https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/) shows, breaking up the code into smaller chunks is possible with the ability to export and import variables between modules. This allows Vite to serve your code as-is, without having to bundle it into a single file. Comparing to tools like Webpack, which has to bundle your code into a single file before serving it, this is a huge performance improvement, and it's one of the main reasons why Vite is so fast.

### Vite vs Webpack vs Snowpack

To get a better picture into the whole JavaScript bundler landscape, let's compare Vite with Webpack and Snowpack. Webpack is a popular JavaScript bundler that has been around for a while. It's powerful and flexible, but it can be slow, especially for large projects, the more they grow and the more packages you are using. Snowpack is a newer JavaScript bundler that is designed to be fast and lightweight. It's similar to Vite in that it uses native ES modules in the browser, but it's not as feature-rich as Vite. Vite, on the other hand, is designed to be fast, feature-rich, and highly optimized for Vue.js projects. It's also designed to be extensible, so you can use it with other frameworks and libraries as well. 

![vuejs prettier vite code snippet gif](https://blog.vueschool.io/wp-content/uploads/2021/07/prettier-eslint-battle.gif)

In short, Vite is probably the best choice for Vue.js projects, but it's also a great choice for other modern web projects. Still not convinced? Let's take a look at some of the features that make Vite stand out.

### Features

Let's break down some of the features that make Vite stand out:

- **Fast Builds**: Vite is designed to be fast. It uses native ES modules in the browser, which allows for on-demand file serving and transformation, and it pre-bundles dependencies with `esbuild`, which is much faster than traditional JavaScript-based bundlers. This makes Vite feel very responsive and accelerates the development process.

- **Hot Module Replacement (HMR)**: Vite supports HMR out of the box, which means that you can see the changes you make in real-time without having to refresh the page. This makes the development process much more efficient and enjoyable.

- **Highly Optimized for Vue.js**: Vite is designed to be highly optimized for Vue.js projects. It leverages Vue's reactivity system to provide a fast and efficient development experience for Vue developers.

- **Extensible**: Vite is designed to be extensible, so you can use it with other frameworks and libraries as well. This makes it a great choice for modern web projects, not just Vue.js projects.

- **Built-in Features**: Vite comes with built-in features like TypeScript support, CSS preprocessing, and more. This makes it easy to get started with Vite and reduces the need for additional configuration.

### Getting Started

If this article has opened your appetite for Vite, you can get started by installing it with `npm` or `yarn`. To install Vite with npm, run the following command:

```bash
npm init vite@latest my-vite-project
```

To install Vite with `yarn`, run the following command:

```bash
yarn create vite my-vite-project
```

Once you've installed Vite, you can start your project by running the following commands:

```bash
cd my-vite-project
npm install
npm run dev
```

This will start the Vite development server and open your project in the browser. You can start making changes to your project and see the changes in real-time. It's that easy!

![mindblown](https://media0.giphy.com/media/3o8dFn5CXJlCV9ZEsg/200w.gif?cid=6c09b952i7k0unptoifdqdz33dixjkr703z5iyq2jpuwo20p&ep=v1_gifs_search&rid=200w.gif&ct=g)

### Conclusion

I hope this article has given you a good overview of Vite and why it's worth considering for your next project. As a quick recap, Vite is a fast, feature-rich, and highly optimized build tool that provides a faster and leaner development experience for modern web projects. It's designed to be highly efficient and responsive, and it comes with built-in features like TypeScript support, CSS preprocessing, and more. If you're looking for a modern build tool that is fast, feature-rich, and highly optimized for Vue.js projects, Vite is definitely worth considering. Give it a try and see for yourself!🚀

### Resources

- [Vite](https://vitejs.dev/)
- [Vite on GitHub](https://github.com/vitejs/vite)
- [Vite on Twitter](https://twitter.com/vite_js)
- [Vite on Reddit](https://www.reddit.com/r/vitejs/)
- [Vite on Discord](https://chat.vitejs.dev/)

### 🙋‍♂️ About the Author

I'm a frontend developer and technical writer based in Portugal. I'm passionate about software engineering 👨‍💻, and I love to explore new tools in my day-to-day. You can find me on [GitHub](github.com/bcostaaa01). If you have any questions or feedback, feel free to reach out! 🚀