Vite - The Next Generation Frontend Tooling

Rate this content
Bookmark

How will we build web apps in the future? Let's learn how esbuild and bundlers like Vite built on top of it work to see how it can speed up our dev workflows.

Devlin Duldulao
Devlin Duldulao
21 min
25 Oct, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

VIT is a build tool that solves the problem of slow feedback loop speed by leveraging native support for ES modules in modern browsers. It allows you to write code as native ES modules and handles the parsing and serving of modules for you. VIT supports JavaScript, CSS, SAS, React, TypeScript, and TSX out of the box. It also allows for quick migration from CRA to VIT and can be used as a middleware in an existing Node.js server to enable server-side rendering.

Available in Español

1. Introduction to VIT Build Tool

Short description:

VIT is a build tool created by Evan Mew, the creator of VJS. It has two major parts: a dev server and a build commander. The dev server enhances native ES modules and provides fast modular placement, while the build commander bundles code in ES build during development and roll up in production. VIT solves the problem of slow feedback loop speed by leveraging the native support for ES modules in modern browsers. It allows you to write code as native ES modules and handles the parsing and serving of modules for you. VIT also serves as the entry point for VIT projects and can be extended using plugins.

So first of all, I'd like to thank React Advanced London for having me. So what is VIT? VIT is a French word, it means fast. It is a build tool created by Evan Mew, the creator of VJS. But VIT is a framework agnostic tool. I want you to think of VIT as these two things here. You can see a server and a bundler. So here, this build tool, VIT has two major parts. It's a dev server here, and a build commander you can also call as pre-configured bundler.

So the dev server provides rich feature enhancements over native ES modules, extremely fast hat modular placement, for instance, while the command bundles your code in ES build in development and roll up in production. And what else I can say about ES build? While it does dependency pre-bundling while roll up does some pre-configuration to output highly optimized static assets for production.

So the problem that we are trying to solve is the feedback loop speed during development. If you use React, especially in a large project, you probably noticed that hot module placement takes sometimes two, three, four, five, no depending on your machine, and you have to change your Webpack, config, JS, or enable caching, etc., just editing a single file. You may have to wait a few seconds for four things to update on the screen. This problem is due to the need for bundling. There's no way for the browser to actually support modularized code. That's the reason we have browserify, Webpack, Parcel, etc., so that modularized code can become one single file that can be run in the browser. We all know that most modern browsers natively support ES modules. This means that during development there's a large chunk of work that we no longer need to do because the browser can now handle them natively. In VIT, you're going to write your code as native ES modules. And VIT will take these ES modules and then parse the file and look for your import statements and then send HTTP requests for each module to the dev server. So the dev server just serves these modules as it's a very fast parsing. Yeah. So what else? So index HTML here is the entry point in VIT projects, not main.js that you'll often see in webpack projects. So think of it again as a dev server. Okay. So putting this all together VIT provides you with an extremely fast and lean development experience. Talking about plugins, VIT can be extended using plugins, which are based on Rollout's plugin interface. You'll see more about plugins in a bit. So to start VIT, can you send PM yarn, PM PM. Here's the commands you can use.

2. VIT Build Tool Demo

Short description:

You can choose React, Vue, Preact, or vanilla VIT. We don't have Angular yet. Let's do a demo with vanilla VIT, then vanilla VIT-to-React. If we have time, we can migrate from CRI to React-Vite. We can try it here, VIT-demo. Install the VIT package and create an index file. Use the dev command to run the application on port 3000 and the preview command to compare the dev and production environment on port 5000. Check out the Node modules, including CS build, roll-up, and post-CSS.

And you can choose React, Vue, Preact, or vanilla VIT. Unfortunately, we don't have Angular here yet. Probably next year, because Angular has this very unique configuration, their build pipeline, build tool.

Yeah, let's do a demo here. So we're going to try vanilla VIT, then vanilla VIT-to-React. And if we have more time, we can do migrating from CRI to React-Vite. So yeah, we can try it here, say, VIT-demo.

Okay, close this. Now, maybe we can run npm init and start adding the VIT package. So yeah, here, npm install DashDev-save-vit. So while waiting for that, we can create an index file here. That's the entry point. And checkout, say, here. Yeah, see here, VIT 2.6.2. Let's remove the sample script here. Let's change it to, say, dev. This is GitHub Copilot helping me. And build or building the VIT project. Probably here, preview or bit preview. So what are these? Dev 2. Run your VIT project on a dev environment here. VIT build for building. That will create this. So dev, by the way, will run the application on port 3000. And then we can preview the build using this preview command here, which will run on port 5000. So basically, this is letting you preview your project in production. So you can compare the dev and production environment of your application or version of your application. And yeah, let's check out the Node modules here. See here, we have the CS build, roll-up, bit of post-CSS. So here, post-CSS.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Vite: Rethinking Frontend Tooling
JSNation Live 2021JSNation Live 2021
31 min
Vite: Rethinking Frontend Tooling
Top Content
Vite is a new build tool that intends to provide a leaner, faster, and more friction-less workflow for building modern web apps. This talk will dive into the project's background, rationale, technical details and design decisions: what problem does it solve, what makes it fast, and how does it fit into the JS tooling landscape.
Welcome to Nuxt 3
Vue.js London Live 2021Vue.js London Live 2021
29 min
Welcome to Nuxt 3
Top Content
Explain about NuxtJS codebase refactor and challenges facing to implement Vue 3, Vite and other packages.
pnpm – a Fast, Disk Space Efficient Package Manager for JavaScript
DevOps.js Conf 2022DevOps.js Conf 2022
31 min
pnpm – a Fast, Disk Space Efficient Package Manager for JavaScript
You will learn about one of the most popular package managers for JavaScript and its advantages over npm and Yarn.A brief history of JavaScript package managersThe isolated node_modules structure created pnpmWhat makes pnpm so fastWhat makes pnpm disk space efficientMonorepo supportManaging Node.js versions with pnpm
The Inner Workings of Vite Build
DevOps.js Conf 2022DevOps.js Conf 2022
31 min
The Inner Workings of Vite Build
Vite unbundled ESM dev server and fast HMR are game-changing for DX. But Vite also shines when building your production applications.This talk will dive into how the main pieces fit together to bundle and minify your code:Vite build as an opinionated Rollup setup.How esbuild is used as a fast TS and JSX transpile and a minifier.The production plugins pipeline.Modern frameworks (Nuxt, SvelteKit, Astro, among others) have chosen Vite, augmenting the DX and optimizations for their target use case.We'll discover Vite as a polished and extendable toolkit to craft optimized modern apps.
The Eternal Sunshine of the Zero Build Pipeline
React Finland 2021React Finland 2021
36 min
The Eternal Sunshine of the Zero Build Pipeline
For many years, we have migrated all our devtools to Node.js for the sake of simplicity: a common language (JS/TS), a large ecosystem (NPM), and a powerful engine. In the meantime, we moved a lot of computation tasks to the client-side thanks to PWA and JavaScript Hegemony.
So we made Webapps for years, developing with awesome reactive frameworks and bundling a lot of dependencies. We progressively moved from our simplicity to complex apps toolchains. We've become the new Java-like ecosystem. It sucks.
It's 2021, we've got a lot of new technologies to sustain our Users eXperience. It's time to have a break and rethink our tools rather than going faster and faster in the same direction. It's time to redesign the Developer eXperience. It's time for a bundle-free dev environment. It's time to embrace a new frontend building philosophy, still with our lovely JavaScript.
Introducing Snowpack, Vite, Astro, and other Bare Modules tools concepts!
Yarn 4 - Modern Package Management
JSNation 2022JSNation 2022
28 min
Yarn 4 - Modern Package Management
Top Content
Yarn 4 is the next major release of your favourite JavaScript package manager, with a focus on performance, security, and developer experience. All through this talk we'll go over its new features, major changes, and share our long-term plans for the project.If you only heard about Yarn without trying it yet, if you're not sure why people make such a fuss over package managers, if you wonder how your package manager can make your work simpler and safer, this is the perfect talk for you!