Loading...
Loading...
Compare original and translation side by side
Configure, migrate, and debug Vite 8 projects with the repo's preferred Vite-native patterns.
使用仓库推荐的Vite原生模式来配置、迁移和调试Vite 8项目。
| Metric | Without Skill | With Skill |
|---|---|---|
| Migration Time | ~120 min | ~40 min |
| Common Config Errors | 6+ | 0 |
| Token Usage | High (trial/error) | Low (known patterns) |
| 指标 | 未使用本技能 | 使用本技能 |
|---|---|---|
| 迁移时间 | ~120分钟 | ~40分钟 |
| 常见配置错误 | 6+ | 0 |
| Token 消耗 | 高(反复试错) | 低(采用成熟模式) |
rollupOptionsrolldownOptionsesbuildoxcssrhandleHotUpdatehotUpdatessrLoadModulerollupOptionsrolldownOptionsesbuildoxcssrhandleHotUpdatehotUpdatessrLoadModule// vite.config.ts
import { defineConfig } from 'vite';
export default defineConfig({
server: {
port: 5173,
},
build: {
target: 'baseline-widely-available',
rolldownOptions: {
output: {
manualChunks: undefined,
},
},
},
});defineConfig// vite.config.ts
import { defineConfig } from 'vite';
export default defineConfig({
server: {
port: 5173,
},
build: {
target: 'baseline-widely-available',
rolldownOptions: {
output: {
manualChunks: undefined,
},
},
},
});defineConfigimport type { Plugin } from 'vite';
export function inspectEnvironment(): Plugin {
return {
name: 'inspect-environment',
configEnvironment(name) {
if (name === 'ssr') {
return {
resolve: {
conditions: ['node'],
},
};
}
},
};
}import type { Plugin } from 'vite';
export function inspectEnvironment(): Plugin {
return {
name: 'inspect-environment',
configEnvironment(name) {
if (name === 'ssr') {
return {
resolve: {
conditions: ['node'],
},
};
}
},
};
}vite dev
vite build
vite build --ssr src/entry-server.ts
vite previewvite dev
vite build
vite build --ssr src/entry-server.ts
vite previewvite.config.tsdefineConfigbuild.rolldownOptionsbuild.rollupOptionsoxcesbuildtransformresolveIddefineConfigvite.config.tsbuild.rolldownOptionsbuild.rollupOptionsoxcesbuildtransformresolveIdrollupOptionsesbuildhandleHotUpdatessr.noExternalrollupOptionsesbuildhandleHotUpdatessr.noExternalexport default defineConfig({
build: {
rollupOptions: {
external: ['react'],
},
},
esbuild: {
jsxInject: "import React from 'react'",
},
});export default defineConfig({
build: {
rolldownOptions: {
external: ['react'],
},
},
oxc: {
jsxInject: "import React from 'react'",
},
});export default function plugin() {
return {
name: 'old-hmr',
handleHotUpdate(ctx) {
return ctx.modules;
},
};
}export default function plugin() {
return {
name: 'env-hmr',
hotUpdate(ctx) {
return ctx.modules;
},
};
}hotUpdatehandleHotUpdateexport default defineConfig({
build: {
rollupOptions: {
external: ['react'],
},
},
esbuild: {
jsxInject: "import React from 'react'",
},
});export default defineConfig({
build: {
rolldownOptions: {
external: ['react'],
},
},
oxc: {
jsxInject: "import React from 'react'",
},
});export default function plugin() {
return {
name: 'old-hmr',
handleHotUpdate(ctx) {
return ctx.modules;
},
};
}export default function plugin() {
return {
name: 'env-hmr',
hotUpdate(ctx) {
return ctx.modules;
},
};
}hotUpdatehandleHotUpdate| Issue | Root Cause | Solution |
|---|---|---|
| Config migration stalls | Old Rollup/esbuild settings copied forward | Migrate to |
| Plugin logic breaks in non-standard runtimes | Plugin assumes only client/SSR | Use named |
| HMR customization feels brittle | Legacy HMR hook carried forward | Prefer |
| SSR dependency crashes | Externalization assumptions are wrong | Review |
| Dev/build behavior diverges | Config ignores Vite 8's unified engine model | Validate both |
| Plugin performance drops | Too much JS-side hook work | Add hook filters and narrower matching |
| Cold starts are sluggish | Heavy hot paths are not warmed and import graph is noisy | Review |
| 问题 | 根本原因 | 解决方案 |
|---|---|---|
| 配置迁移停滞 | 旧的Rollup/esbuild设置被直接沿用 | 迁移至 |
| 插件逻辑在非标准运行时中失效 | 插件仅假设存在客户端/SSR两种环境 | 使用命名 |
| HMR定制不稳定 | 沿用旧版HMR钩子 | 优先使用 |
| SSR依赖崩溃 | 外部化假设错误 | 检查 |
| 开发/构建行为不一致 | 配置忽略Vite 8的统一引擎模型 | 在Rolldown下验证 |
| 插件性能下降 | JS端钩子工作负载过大 | 添加钩子过滤器和更精确的匹配规则 |
| 冷启动缓慢 | 核心热路径未预热且导入图杂乱 | 检查 |
references/core-config-reference.mdreferences/plugin-environment-reference.mdreferences/build-ssr-migration-reference.mdreferences/performance-devserver-reference.mdreferences/README.mdreferences/core-config-reference.mdreferences/plugin-environment-reference.mdreferences/build-ssr-migration-reference.mdreferences/performance-devserver-reference.mdreferences/README.mdimport { defineConfig } from 'vite';
export default defineConfig({
build: {
target: 'baseline-widely-available',
rolldownOptions: {
output: {
chunkFileNames: 'assets/[name]-[hash].js',
},
},
},
oxc: {
jsxInject: "import React from 'react'",
},
environments: {
ssr: {
resolve: {
conditions: ['node'],
},
},
},
css: {
lightningcss: {},
},
});build.rolldownOptionsoxcenvironmentscss.lightningcssserver.warmupimport { defineConfig } from 'vite';
export default defineConfig({
build: {
target: 'baseline-widely-available',
rolldownOptions: {
output: {
chunkFileNames: 'assets/[name]-[hash].js',
},
},
},
oxc: {
jsxInject: "import React from 'react'",
},
environments: {
ssr: {
resolve: {
conditions: ['node'],
},
},
},
css: {
lightningcss: {},
},
});build.rolldownOptionsoxcenvironmentscss.lightningcssserver.warmupmy-app/
├── src/
├── index.html
├── vite.config.ts
├── package.json
└── tsconfig.jsonmy-app/
├── src/
├── index.html
├── vite.config.ts
├── package.json
└── tsconfig.jsonimport type { Plugin } from 'vite';
export function envAwarePlugin(): Plugin {
return {
name: 'env-aware-plugin',
transform: {
filter: {
id: /\.(ts|tsx)$/,
},
handler(code, id) {
return {
code,
map: null,
};
},
},
configEnvironment(name) {
if (name === 'ssr') {
return {
resolve: {
conditions: ['node'],
},
};
}
},
};
}import type { Plugin } from 'vite';
export function envAwarePlugin(): Plugin {
return {
name: 'env-aware-plugin',
transform: {
filter: {
id: /\.(ts|tsx)$/,
},
handler(code, id) {
return {
code,
map: null,
};
},
},
configEnvironment(name) {
if (name === 'ssr') {
return {
resolve: {
conditions: ['node'],
},
};
}
},
};
}vite build
vite build --ssr src/entry-server.ts
vite previewvite build
vite build --ssr src/entry-server.ts
vite preview// Pseudocode sketch
const mod = await moduleRunner.import('/src/entry-server.ts');// 伪代码示例
const mod = await moduleRunner.import('/src/entry-server.ts');| Package | Version | Purpose |
|---|---|---|
| ^8 | Build tool, dev server, plugin host |
| >=20.19 or >=22.12 | Required Vite 8 runtime |
| 包 | 版本 | 用途 |
|---|---|---|
| ^8 | 构建工具、开发服务器、插件宿主 |
| >=20.19 或 >=22.12 | Vite 8所需的运行时环境 |
| Package | Version | Purpose |
|---|---|---|
| latest | Typed |
| framework plugin packages | latest | React/Vue/Svelte/etc integrations |
| 包 | 版本 | 用途 |
|---|---|---|
| 最新版 | 类型化的 |
| 框架插件包 | 最新版 | React/Vue/Svelte等框架集成 |
build: {
rolldownOptions: {},
}
oxc: {}build: {
rolldownOptions: {},
}
oxc: {}environmentsthis.environmentssr.noExternalenvironmentsthis.environmentssr.noExternalvitevite.config.tsrollupOptionsesbuildvitevite.config.tsrollupOptionsesbuild