Quasar and Vite - Frontend Application Development at Light Speed
Published: 2022-03-14 19:50:22


This week notes the accomplishment of a major milestone in Quasar's roadmap. The integration of Vite as a driver of the Quasar CLI, and as a much better alternative to the slower and more complicated Webpack based CLI. 

## Quick Introduction Video 

{% embed  https://www.youtube.com/watch?v=tql0omvnoXg %}


## Why Vite?
If you haven't heard about Vite yet and why it is so good, Vite has the following main selling points:

(from the [Vite docs](https://vitejs.dev/))
> A dev server that provides rich feature enhancements over native ES modules, for example extremely fast Hot Module Replacement (HMR).
>
> A build command that bundles your code with Rollup, pre-configured to output highly optimized static assets for production.

In other words, the main goal Evan You (creator of Vue) had for creating Vite (pronounced like veet) was to majorly improve the developer experience. He saw that the current process of bundling and then loading the application into the browser and developing with Hot-Module-Replacement (HMR) could be improved upon with the new ES Module resolution system available in all browsers. 

That is the TLDR version. [If you'd like, you can also read the much more technical reasons.](https://vitejs.dev/guide/why.html#slow-server-start) 

Bottom line, the avoidance of the bundling or packing step for the initial build, also during HMR, saves a ton of time, even with the smallest of projects (see below). But, this advantage is especially noticeable, once your project gets even remotely bigger.


#### Initial Loading of a new Quasar project with Webpack

![](https://i.imgur.com/u76c6Sg.gif)



#### Initial Loading of a new Quasar project with Vite

![](https://i.imgur.com/qZOPsVv.gif)


Ok. The difference with an initial project isn't so predominant, but it is there. Think about this though. Once your project starts growing, the Vite-based CLI's performance in building your app stays about the same or will only slow a little for the initial startup. The Webpack performance will degrade much worse as your project size grows. In other words, what you see here as the initial startup speed is about what you'll have for any size project. On top of that, any updates from HMR will be instantaneous with Vite. With Webpack, this performance also degrades with the size of your project.

It was clear to the team instantly, when Vite came out, that Quasar would need to integrate it. So, it wasn't a matter of "If", but rather "When?". It was just a matter of time, dev availability with Razvan and our prerogatives for it to happen. Our first major goal was to get Quasar onto Vue 3. That happened last year. All the while, Vite was getting better and more stable. And this year, Quasar now has a Vite based CLI. 

How cool is that? 🤩 

### Getting Started

If you'd like to just get started with Vite in a new project, all you have to do is run...

```bash
$ yarn create quasar
# or:
$ npm init quasar
```

**Note:** The command `quasar create` is no longer usable for a Quasar project with the new CLI (>1.3.0). 

***NOTE2: the Vite CLI was still in BETA at the time this article was published. So, it is not production ready, if it is still in beta or RC status!!!***

While running the command above, the creation process will pose question to you for the project creation. Answer the questions as best you can. Hit enter for the defaults (except for the Vite CLI), if you are uncertain what to answer. Once the creation process is done, navigate to the newly created project folder and run...

```bash
$ quasar dev
```

And off you go.. with Lightning fast development at your fingertips!!! 


### Migration

Maybe you have a Quasar project and wish to move it to the new Vite CLI. If that is the case, then let's get you up to.....Vite, [with the official migration guide.](https://quasar.dev/quasar-cli-vite/convert-to-quasar-cli-with-vite)

Roughly, the migration guide takes you through the following steps:

1. Create a new project with the newest version of the (global) Quasar CLI
2. Copy specific folders into the new project from your old project, also doing some small edits on specific files.
3. Update the `quasar.config.js` file notice it's changes from `quasar-conf.js`) with the new settings, should you need them.
4. Update `package.json` to remove the `browserlist` entry (if you want). It is no longer valid and not needed, at least for Vite. 
5. Delete a folder for SSR and move another. 
6. For PWA, you'll need to move your manifest to `quasar.config.js`
7. If you are using BEX mode, you'll also need to port over your manifest files manually. 

So, not too much work necessary to get a much better DX. 

Again, more details can be found in the [migration guide](https://quasar.dev/quasar-cli-vite/convert-to-quasar-cli-with-vite).

### That's it!

Let us know in the comments about what you think! Is Vite with Quasar awesome or what?

Keep in touch with Quasar news. 

[Quasar on Twitter](https://twitter.quasar.dev/)
[Quasar on Facebook](https://facebook.quasar.dev/)
[Quasar on Discord](https://chat.quasar.dev/)
[Quasar on Github](https://github.com/quasarframework)