Vite
”Next Generation Frontend Tooling”
Vite has two main parts:
- A dev server to run code in a non-production environment
- runs local webserver
- watches TypeScript source files and re-transpiles as needed
- uses optimizations like Hot Module Replacement (HMR).
- A build command to bundle code for deployment to production
- uses rollup to optimize code and assets
In CS349 - User Interfaces, we only use the dev server part.
Create a Vite Project
- Vite has templates to setup a project for different frameworks
Create project with Vanilla TypeScript template (for example)
npm create vite@latest
npm create
initializes a project directory using a “create” packagevite
in this context means thecreate-vite
package@latest
just means “use latest version” ofcreate-vite
package
Or provide the project name and template directly:
npm create vite@latest <project> -- --template vanilla-ts
Go under the newly created project folder and run the following
npm install
Run Vite dev server
npm run dev
Examine Vite project structure
- index.html, especially
<script type = "module"...
- src/ directory
Show how to trim down to minimal project:
- simplify
index.html
- remove CSS file
- remove vite SVG
- etc…