Skip to content

Vite Cheatsheet

Next-generation frontend build tool with instant server start.

01

Getting Started

Create

Scaffold projects with templates.

vite
# npm create vite@latest my-app -- --template vue
# npm create vite@latest my-app -- --template react-ts

Config

Vite config with plugins.

vite
// vite.config.ts
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [vue()],
  server: { port: 3000 },
});

Dev/Build

Three main commands.

vite
# vite        # dev server
# vite build  # production build
# vite preview # preview build
02

Features

Plugins

Plugins extend Vite functionality.

vite
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

export default defineConfig({
  plugins: [react()],
});

Env Variables

VITE_ prefix exposes env vars to client.

vite
import.meta.env.VITE_API_URL

// .env
VITE_API_URL=https://api.example.com

Proxy

Proxy API requests during development.

vite
server: {
  proxy: {
    "/api": "http://localhost:8080",
  },
}

Was this helpful?