A First Look at Vite
Published:
Vite is a frontend build tool and open source project created by Evan You that increases development speed and serves native ES modules with ESBuild & Rollup.
Outline
All of this project’s code can be found in the First Look monorepo on my GitHub.
Introduction
Vite (French word for “fast”, pronounced /vit/
, rhymes with “street”) is a frontend build tool and open source project created by Evan You on April 20, 2020 in between his second and third viewing of Dazed and Confused. Vite 2.0 was officially released on February 16, 2021 and aims to provide a faster and leaner development experience for modern web projects. It consists of two parts:
- A dev server with Hot Module Replacement (HMR) that serves your source files over native ES modules
- A build command that bundles your code with Rollup, pre-configured to output highly optimized static assets for production
Create a Project from Scratch
Create HTML Entry File
Install Vite Dependency
Add Dev Script
Open package.json
and add the follow script.
Start Development Server
Open localhost:3000.
Don’t forget the <title>
.
We can import modules directly inside our <script>
tags thanks to ES Modules.
We are trying to import main.js
but we haven’t created it yet. This will cause the server to display one of the most aesthetically pleasing error messages you will ever see.
Create JavaScript Entry File
Console log a message to your dude.
Create CSS Stylesheet
You only get one color so make it count.
Create a Single Page App that Renders a Root Component
Cause it’s the only thing they ever taught you.
If we look back at localhost:3000
we will see our blank canvas. Alternatively known as “the only thing your website does” for people with JavaScript turned off.
We will paint the canvas with our imperative DOM manipulations just as Elder Resig instructed.
And that’s the whole website, that’ll be $10,000 dollars.
Create Vue App
Huh, what’s that? You came here expecting a Vue site? What gave you that idea?
It’s from the creator of Vue, it starts with a V, and it was used as literally a drop in replacement for the word Vue in VitePress. I’m sure that’s all just a coincidence.
Initialize Project
Output:
Start the development server.
Project Structure
Our package.json
includes scripts for starting the development server, building for production, and serving local previews of production builds.
App Vue Component
HelloWorld Component
Modify the components.
Deploy to Netlify
Create a netlify.toml
file to define the build command and publish directory for the static assets.
Connect to your Git provider.
Select the repository.
Go to site settings to create custom domain name.
Pick a domain name.
Check the build time for bragging rights.
Open ajcwebdev-vite.netlify.app
to see the deployed site.