vite

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Vite

Vite

When to use

使用场景

  • User asks how to set up or run a Vite project.
  • User needs Vite configuration guidance (
    vite.config.*
    ).
  • User needs plugin authoring, HMR, or JS API usage.
  • User needs environment variables or modes behavior.
  • 用户询问如何搭建或运行Vite项目。
  • 用户需要Vite配置指导(
    vite.config.*
    )。
  • 用户需要插件开发、HMR或JS API使用相关指导。
  • 用户需要环境变量或模式行为相关说明。

Quick navigation

快速导航

  • Getting started: references/getting-started.md
  • Philosophy and rationale: references/philosophy.md, references/why-vite.md
  • Features: references/features.md
  • CLI: references/cli.md
  • Plugins (usage): references/using-plugins.md
  • Plugin API: references/api-plugin.md
  • HMR API: references/api-hmr.md
  • JavaScript API: references/api-javascript.md
  • Config reference: references/config.md
  • Dependency optimization: references/dep-pre-bundling.md
  • Assets: references/assets.md
  • Build: references/build.md
  • Static deploy: references/static-deploy.md
  • Env & modes: references/env-and-mode.md
  • SSR: references/ssr.md
  • Backend integration: references/backend-integration.md
  • Troubleshooting: references/troubleshooting.md
  • Performance: references/performance.md
  • Rolldown: references/rolldown.md
  • Migration: references/migration.md
  • Breaking changes: references/breaking-changes.md
  • Environment API: references/api-environment.md
  • Environment instances: references/api-environment-instances.md
  • Env plugins: references/api-environment-plugins.md
  • Env frameworks: references/api-environment-frameworks.md
  • Env runtimes: references/api-environment-runtimes.md
  • 入门指南:references/getting-started.md
  • 设计理念与原理:references/philosophy.md, references/why-vite.md
  • 功能特性:references/features.md
  • 命令行工具:references/cli.md
  • 插件(使用):references/using-plugins.md
  • 插件API:references/api-plugin.md
  • HMR API:references/api-hmr.md
  • JavaScript API:references/api-javascript.md
  • 配置参考:references/config.md
  • 依赖优化:references/dep-pre-bundling.md
  • 资源处理:references/assets.md
  • 构建:references/build.md
  • 静态部署:references/static-deploy.md
  • 环境与模式:references/env-and-mode.md
  • 服务端渲染:references/ssr.md
  • 后端集成:references/backend-integration.md
  • 故障排查:references/troubleshooting.md
  • 性能优化:references/performance.md
  • Rolldown:references/rolldown.md
  • 迁移指南:references/migration.md
  • 重大变更:references/breaking-changes.md
  • Environment API:references/api-environment.md
  • Environment实例:references/api-environment-instances.md
  • Env插件:references/api-environment-plugins.md
  • Env框架:references/api-environment-frameworks.md
  • Env运行时:references/api-environment-runtimes.md

Core rules

核心规则

  • Prefer minimal configuration; extend only as needed.
  • Keep
    index.html
    as a first-class entry point when using Vite defaults.
  • Treat dev server settings and build settings separately.
  • Document mode-dependent behavior for env variables and
    define
    .
  • Use
    future
    config to opt-in to deprecation warnings before migration.
  • 优先使用极简配置;仅在必要时进行扩展。
  • 使用Vite默认配置时,将
    index.html
    作为一等入口文件。
  • 区分开发服务器设置与构建设置。
  • 记录环境变量和
    define
    的模式相关行为。
  • 使用
    future
    配置在迁移前启用弃用警告。

Recipes

实践方案

  • Scaffold a project with
    npm create vite@latest
    .
  • Configure aliases, server options, and build outputs in
    vite.config.*
    .
  • Load
    .env
    values into config with
    loadEnv
    when config needs them.
  • Add plugins with
    plugins: []
    and define
    apply
    or
    enforce
    when needed.
  • Use HMR APIs for fine-grained updates when plugin or framework needs it.
  • Use
    optimizeDeps.include/exclude
    when deps aren't discovered on startup.
  • Use
    build.rollupOptions.input
    for multi-page apps.
  • Enable deprecation warnings:
    future: { removeSsrLoadModule: 'warn' }
    .
  • Use
    hotUpdate
    hook instead of
    handleHotUpdate
    for environment-aware HMR.
  • Use
    this.environment
    instead of
    options.ssr
    in plugin hooks.
  • 使用
    npm create vite@latest
    搭建项目。
  • vite.config.*
    中配置别名、服务器选项和构建输出。
  • 当配置需要时,使用
    loadEnv
    .env
    中的值加载到配置中。
  • 使用
    plugins: []
    添加插件,并在必要时定义
    apply
    enforce
  • 当插件或框架需要时,使用HMR API进行细粒度更新。
  • 当启动时未检测到依赖项时,使用
    optimizeDeps.include/exclude
  • 针对多页面应用使用
    build.rollupOptions.input
  • 启用弃用警告:
    future: { removeSsrLoadModule: 'warn' }
  • 针对感知环境的HMR,使用
    hotUpdate
    钩子而非
    handleHotUpdate
  • 在插件钩子中使用
    this.environment
    而非
    options.ssr

Prohibitions

禁止事项

  • Do not copy large verbatim chunks from vendor docs.
  • Do not assume framework-specific behavior without verifying.
  • 不要直接复制供应商文档中的大段内容。
  • 不要在未验证的情况下假设框架特定行为。

Links

相关链接