Vite is a modern, lean, and lightning fast development tool made with the developer experience as top priority. Also, according to Evan You, the official recommendation for Vue 3 tooling will be switching from Vue CLI to Vite (reference One Year Into Vue 3 Talk [9:00 - 10:20]) meaning in 2022 Vue CLI will be yesterday's tool. Thus, now is definitely the time for you to start using Vite!
But where do you start? No worries! We've got you covered, with a brand new course all about Vite. Checkout the introductory lesson now for free and read on to get a glimpse into some of the material we cover during the course.
So does learning Vite from top to bottom sound exciting? Of course it does! So here's a sneak peek into some of the material you can expect to learn.
When starting a Vue.js project with Vite there are a number of options depending on your needs. Here are 3 methods that we cover in the course.
npm init vite@latest
- documented in the official Vite docs, provides bare bones Vue.js projectnpm init vue@next
- provides an interactive CL setup similar to Vue CLIAs a modern day build tool Vite has a variety of different responsibilities ranging from how to work with styles to handling ES modules and everything in between. In the course, we cover all such topics including:
new URL
to get public paths@
import aliasThis may seem like a lot to learn but really it's fairly straightforward as Vite does much of the heavy lifting for us, allowing you to stay focused on your actual application.
While Vite shines the most during development with it's super fast cold starts and HMR, it wouldn't be a complete build tool without being able to bundle for production. This is done in a Vite project with the following command.
npm run build
On build, Vite uses the bundler Rollup under the hood to bundle your ES modules into a single main JavaScript file as well as split your async modules into their own chunks ready for use only when they're needed. This is not necessary in development as Vite utilizes native browser support for ES modules, however shipping unbundled ESM in production is still inefficient so Vite performs this traditional bundle step for you.
Environment variables are another useful feature often used for supporting different data sources depending on your application environment and for keeping secrets safe. Vite, of course, supports them as well.
You can access environment variables in Vite projects with
import.meta.env
You can set environment variables like you would in a typical node environment, hosting platform interface, or in any of the special files supported by Vite.
.env # loaded in all cases
.env.local # loaded in all cases, ignored by git
.env.[mode] # only loaded in specified mode
.env.[mode].local # only loaded in specified mode, ignored by git
Vite also helps protect you from accidentally exposing secret environment variables to the client by requiring a prefix VITE_
on any variable to be included in the bundled application.
Next, since Vue CLI has been the official recommendation for Vue for quite some time, there are many folks with projects that began with Vue CLI, are managed with Vue CLI, and are built/developed with Webpack. To get up to snuff with the latest tooling and benefit from the super fast development experience of Vite many will want to migrate their Vue CLI powered projects to Vite.
While each Vue CLI project is different depending on the included dependencies and chosen approaches there are some standard steps that all developers will need to take to migrate their projects. These 9 steps will get you a long way into the migration and might even be all you need.
In the course, as well as this dedicated blog post, we go into the details of each step.
Finally, depending on how often you're jumping between projects or spinning up new ones, there are some steps you can take to make Vite more reusable across those projects.
Strategies include:
During the course, we go over each strategy in detail and by the end of it you'll have your own custom template wired up with TailwindCSS, ESLint, Prettier, Vue Router, and the @
import alias as well as a custom simple markdown to Vue component plugin.
Vite is the future of tooling for Vue development. As such, you should be prepared to use it. Not only that though, I guarantee you that within just a few short days of using Vite you'll find yourself waiting less and coding more, with less mental jolts and an overall better development flow. Let us help you get started with Vite with a Vue School Subscription today and access to the comprehensive course: Rapid Development with Vite!
Our goal is to be the number one source of Vue.js knowledge for all skill levels. We offer the knowledge of our industry leaders through awesome video courses for a ridiculously low price.
More than 200.000 users have already joined us. You are welcome too!
© All rights reserved. Made with ❤️ by BitterBrains, Inc.