create-vite is a CLI tool for quickly scaffolding Vite projects with popular frontend frameworks. It provides interactive prompts to choose frameworks like Vue, React, Preact, Lit, Svelte, Solid, and Qwik, with support for both JavaScript and TypeScript variants.
npm create vite@latest or npm install -g create-vitecreate-vite is a CLI-only tool designed to be executed via command line. It does not export any public APIs for programmatic use. The package is intended to be run using package managers' create commands:
npm create vite@latest
yarn create vite
pnpm create vite
bun create viteInteractive mode (prompts for all options):
npm create vite@latest
# or
yarn create vite
# or
pnpm create vite
# or
bun create viteSpecify project name:
npm create vite@latest my-vue-appSpecify template directly:
npm create vite@latest my-vue-app -- --template vueUse current directory:
npm create vite@latest .create-vite is built around several key components:
create-vite provides two binary commands for project scaffolding:
# Main command
create-vite [directory] [options]
# Short alias
cva [directory] [options]interface CLIArguments {
/** Template name to use */
template?: string;
/** Show help message */
help?: boolean;
/** Overwrite existing files without prompting */
overwrite?: boolean;
/** Project directory (positional argument) */
_: string[];
}Available CLI Options:
-t, --template <name> - Specify template name-h, --help - Show help message--overwrite - Overwrite existing files without promptinginterface Framework {
/** Internal framework name */
name: string;
/** Display name for UI */
display: string;
/** Color function for terminal output */
color: ColorFunc;
/** Available variants for this framework */
variants: FrameworkVariant[];
}
interface FrameworkVariant {
/** Internal variant name */
name: string;
/** Display name for UI */
display: string;
/** Color function for terminal output */
color: ColorFunc;
/** Custom command to run instead of built-in template */
customCommand?: string;
}
type ColorFunc = (str: string | number) => string;
interface PkgInfo {
/** Package manager name (npm, yarn, pnpm, bun) */
name: string;
/** Package manager version */
version: string;
}create-vite includes built-in templates for popular frontend frameworks:
// All available templates (extracted from framework variants)
const TEMPLATES = [
// Vanilla
"vanilla-ts", "vanilla",
// Vue
"vue-ts", "vue",
// React (includes SWC variants)
"react-ts", "react-swc-ts", "react", "react-swc",
// Preact
"preact-ts", "preact",
// Lit
"lit-ts", "lit",
// Svelte
"svelte-ts", "svelte",
// Solid
"solid-ts", "solid",
// Qwik
"qwik-ts", "qwik"
];Each template corresponds to a template-{name} directory containing:
template-vanilla, template-react, etc.template-vanilla-ts, template-react-ts, etc.react-swc, react-swc-ts) are dynamically created by modifying base React templatescreate-vite also provides options for frameworks that use external scaffolding tools:
// Custom command variants (sample from source)
const CUSTOM_COMMANDS = {
// Vue ecosystem
"custom-create-vue": "npm create vue@latest TARGET_DIR",
"custom-nuxt": "npm exec nuxi init TARGET_DIR",
// React ecosystem
"custom-react-router": "npm create react-router@latest TARGET_DIR",
"custom-tanstack-router": "npm create -- tsrouter-app@latest TARGET_DIR --framework React --interactive",
"redwoodsdk-standard": "npm exec degit redwoodjs/sdk/starters/standard TARGET_DIR",
"rsc": "npm exec degit vitejs/vite-plugin-react/packages/plugin-rsc/examples/starter TARGET_DIR",
// Other frameworks
"custom-angular": "npm exec @angular/cli@latest new TARGET_DIR",
"custom-analog": "npm create analog@latest TARGET_DIR",
"custom-svelte-kit": "npm exec sv create TARGET_DIR",
"custom-qwik-city": "npm create qwik@latest basic TARGET_DIR",
"custom-create-preact": "npm create preact@latest TARGET_DIR",
"marko-run": "npm create -- marko@latest --name TARGET_DIR",
// Community options
"create-vite-extra": "npm create vite-extra@latest TARGET_DIR",
"create-electron-vite": "npm create electron-vite@latest TARGET_DIR"
};These commands are automatically adapted for different package managers (yarn, pnpm, bun) using the getFullCustomCommand function.
# Start interactive mode
npm create vite@latest
# Follow prompts:
# ✔ Project name: my-app
# ✔ Select a framework: Vue
# ✔ Select a variant: TypeScript# Create React TypeScript project
npm create vite@latest my-react-app -- --template react-ts
# Create Vue project in current directory
npm create vite@latest . -- --template vue
# Create Svelte project with overwrite
npm create vite@latest my-svelte-app -- --template svelte --overwrite# npm 7+ (extra double-dash needed)
npm create vite@latest my-app -- --template vue-ts
# yarn
yarn create vite my-app --template vue-ts
# pnpm
pnpm create vite my-app --template vue-ts
# bun
bun create vite my-app --template vue-tscreate-vite handles various error scenarios with user-friendly prompts:
--template specifies a non-existent template, shows available options and prompts for selectionCancel operation - Exits without changesRemove existing files and continue - Calls emptyDir() to clear directoryIgnore files and continue - Proceeds without clearingfs.mkdirSync(root, { recursive: true }) to ensure parent directories exist/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/toValidPackageName() converts invalid names to valid formatspawn.sync() with stdio: 'inherit' for real-time outputprompts.cancel('Operation cancelled') to exit cleanlyEach template directory (template-*) contains:
package.json - Template package configurationREADME.md - Template-specific documentationindex.html - Main HTML filesrc/ - Source code directorypublic/ - Public assets directory_gitignore - Git ignore file (renamed to .gitignore)vite.config.js, tsconfig.json)create-vite includes several utility functions for internal processing:
/**
* Formats target directory by trimming and removing trailing slashes
* @param targetDir - The target directory path
* @returns Formatted directory path
*/
function formatTargetDir(targetDir: string): string;
/**
* Validates if a string is a valid npm package name
* @param projectName - The project name to validate
* @returns True if valid package name
*/
function isValidPackageName(projectName: string): boolean;
/**
* Converts a string to a valid npm package name
* @param projectName - The project name to convert
* @returns Valid package name
*/
function toValidPackageName(projectName: string): string;
/**
* Extracts package manager info from npm user agent string
* @param userAgent - The npm_config_user_agent environment variable
* @returns Package manager info or undefined
*/
function pkgFromUserAgent(userAgent?: string): PkgInfo | undefined;
/**
* Converts custom commands to work with different package managers
* @param customCommand - The base custom command
* @param pkgInfo - Package manager information
* @returns Adapted command for the specific package manager
*/
function getFullCustomCommand(customCommand: string, pkgInfo?: PkgInfo): string;Some framework variants use custom commands instead of built-in templates. When selected, these options will execute external scaffolding tools.
The getFullCustomCommand function automatically adapts commands for different package managers:
// Command adaptation examples:
// npm create vue@latest → yarn create vue
// npm exec nuxi init → pnpm dlx nuxi init
// npm create qwik@latest → bun x create-qwik@latestAdaptation rules:
yarn create, pnpm create, bun x create-yarn dlx, pnpm dlx, bun x