migrate-to-vinext
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMigrate Next.js to vinext
将Next.js迁移至vinext
vinext reimplements the Next.js API surface on Vite. Existing , , and work as-is — migration is a package swap, config generation, and ESM conversion. No changes to application code required.
app/pages/next.config.jsvinext 在Vite上重新实现了Next.js的API接口。现有的、目录以及文件可直接使用——迁移仅需替换依赖包、生成配置文件并转换为ESM格式,无需修改应用代码。
app/pages/next.config.jsFIRST: Verify Next.js Project
第一步:验证Next.js项目
Confirm is in or in . If not found, STOP — this skill does not apply.
nextdependenciesdevDependenciespackage.jsonDetect the package manager from the lockfile:
| Lockfile | Manager | Install | Uninstall |
|---|---|---|---|
| pnpm | | |
| yarn | | |
| bun | | |
| npm | | |
Detect the router: if an directory exists at root or under , it's App Router. If only exists, it's Pages Router. Both can coexist.
app/src/pages/确认的或中包含。如果未找到,请停止操作——本技能不适用当前项目。
package.jsondependenciesdevDependenciesnext通过锁文件检测包管理器:
| 锁文件 | 管理器 | 安装命令 | 卸载命令 |
|---|---|---|---|
| pnpm | | |
| yarn | | |
| bun | | |
| npm | | |
检测路由类型:如果根目录或目录下存在文件夹,则为App Router;如果仅存在文件夹,则为Pages Router。两种路由类型可以共存。
src/app/pages/Quick Reference
快速参考
| Command | Purpose |
|---|---|
| Scan project for compatibility issues, produce scored report |
| Automated migration — installs deps, generates config, converts to ESM |
| Development server with HMR |
| Production build (multi-environment for App Router) |
| Local production server |
| Build and deploy to Cloudflare Workers |
| 命令 | 用途 |
|---|---|
| 扫描项目兼容性问题,生成评分报告 |
| 自动化迁移——安装依赖、生成配置、转换为ESM格式 |
| 带有HMR的开发服务器 |
| 生产环境构建(为App Router支持多环境) |
| 本地生产环境服务器 |
| 构建并部署至Cloudflare Workers |
Phase 1: Check Compatibility
阶段1:兼容性检查
Run (install vinext first if needed via ). Review the scored report. If critical incompatibilities exist, inform the user before proceeding.
vinext checknpx vinext checkSee references/compatibility.md for supported/unsupported features and ecosystem library status.
运行(如果需要,可先通过安装vinext)。查看评分报告。如果存在严重兼容性问题,请在继续操作前告知用户。
vinext checknpx vinext check查看references/compatibility.md了解支持/不支持的功能以及生态库状态。
Phase 2: Automated Migration (Recommended)
阶段2:自动化迁移(推荐)
Run . This command:
vinext init- Runs for a compatibility report
vinext check - Installs as a devDependency (and
vitefor App Router)@vitejs/plugin-rsc - Adds to package.json
"type": "module" - Renames CJS config files (e.g., →
postcss.config.js) to avoid ESM conflicts.cjs - Adds and
dev:vinextscripts to package.jsonbuild:vinext - Generates a minimal
vite.config.ts
This is non-destructive — the existing Next.js setup continues to work alongside vinext. Use the script to test before fully switching over.
dev:vinextIf succeeds, skip to Phase 4 (Verify). If it fails or the user prefers manual control, continue to Phase 3.
vinext init运行。该命令会执行以下操作:
vinext init- 运行生成兼容性报告
vinext check - 安装作为开发依赖(如果是App Router,还会安装
vite)@vitejs/plugin-rsc - 向中添加
package.json"type": "module" - 重命名CJS配置文件(例如→
postcss.config.js)以避免ESM冲突.cjs - 向中添加
package.json和dev:vinext脚本build:vinext - 生成极简版
vite.config.ts
此操作不会破坏原有配置——现有的Next.js设置可与vinext共存。在完全切换前,可使用脚本进行测试。
dev:vinext如果执行成功,可直接跳至阶段4(验证)。如果执行失败或用户希望手动控制,请继续阶段3。
vinext initPhase 3: Manual Migration
阶段3:手动迁移
Use this as a fallback when doesn't work or the user wants full control.
vinext init当无法工作或用户希望完全掌控迁移过程时,可使用此备选方案。
vinext init3a. Replace packages
3a:替换依赖包
bash
undefinedbash
undefinedExample with npm:
npm示例:
npm uninstall next
npm install vinext
npm install -D vite
npm uninstall next
npm install vinext
npm install -D vite
App Router only:
仅App Router需要:
npm install -D @vitejs/plugin-rsc
undefinednpm install -D @vitejs/plugin-rsc
undefined3b. Update scripts
3b:更新脚本
Replace all commands in scripts:
nextpackage.json| Before | After | Notes |
|---|---|---|
| | Dev server with HMR |
| | Production build |
| | Local production server |
| | Delegates to eslint/oxlint |
Preserve flags: → .
next dev --port 3001vinext dev --port 3001替换脚本中所有命令:
package.jsonnext| 原命令 | 新命令 | 说明 |
|---|---|---|
| | 带有HMR的开发服务器 |
| | 生产环境构建 |
| | 本地生产环境服务器 |
| | 委托给eslint/oxlint执行 |
保留命令参数: → 。
next dev --port 3001vinext dev --port 30013c. Convert to ESM
3c:转换为ESM格式
Add to package.json. Rename any CJS config files:
"type": "module"- →
postcss.config.jspostcss.config.cjs - →
tailwind.config.jstailwind.config.cjs - Any other config that uses
.jsmodule.exports
向中添加。重命名所有CJS配置文件:
package.json"type": "module"- →
postcss.config.jspostcss.config.cjs - →
tailwind.config.jstailwind.config.cjs - 其他使用的
module.exports配置文件.js
3d. Generate vite.config.ts
3d:生成vite.config.ts
See references/config-examples.md for config variants per router and deployment target.
Pages Router (minimal):
ts
import vinext from "vinext";
import { defineConfig } from "vite";
export default defineConfig({ plugins: [vinext()] });App Router (minimal):
ts
import vinext from "vinext";
import { defineConfig } from "vite";
export default defineConfig({ plugins: [vinext()] });vinext auto-registers for App Router when the option is not explicitly . No manual RSC plugin config needed for local development.
@vitejs/plugin-rscrscfalse查看references/config-examples.md获取不同路由类型和部署目标的配置示例。
Pages Router(极简版):
ts
import vinext from "vinext";
import { defineConfig } from "vite";
export default defineConfig({ plugins: [vinext()] });App Router(极简版):
ts
import vinext from "vinext";
import { defineConfig } from "vite";
export default defineConfig({ plugins: [vinext()] });当选项未显式设置为时,vinext会自动为App Router注册。本地开发无需手动配置RSC插件。
rscfalse@vitejs/plugin-rscPhase 4: Cloudflare Deployment (Optional)
阶段4:Cloudflare部署(可选)
If the user wants to deploy to Cloudflare Workers, the simplest path is — it auto-generates , worker entry, and Vite config if missing, installs and , then builds and deploys.
vinext deploywrangler.jsonc@cloudflare/vite-pluginwranglerFor manual setup or custom worker entries, see references/config-examples.md.
如果用户希望部署至Cloudflare Workers,最简单的方式是运行——该命令会自动生成、Worker入口文件和缺失的Vite配置,安装和,然后执行构建和部署。
vinext deploywrangler.jsonc@cloudflare/vite-pluginwrangler如需手动设置或自定义Worker入口,请查看references/config-examples.md。
Phase 5: Verify
阶段5:验证
- Run to start the development server
vinext dev - Confirm the server starts without errors
- Navigate key routes and check functionality
- Report the result to the user — if errors occur, share full output
See references/troubleshooting.md for common migration errors.
- 运行启动开发服务器
vinext dev - 确认服务器无错误启动
- 访问关键路由并检查功能是否正常
- 向用户反馈结果——如果出现错误,分享完整输出信息
查看references/troubleshooting.md了解常见迁移错误。
Known Limitations
已知限制
| Feature | Status |
|---|---|
| Remote images via @unpic; no build-time optimization |
| CDN-loaded, not self-hosted |
| Domain-based i18n | Not supported; path-prefix i18n works |
| Not supported; use Vitest |
| Turbopack/webpack config | Ignored; use Vite plugins instead |
| Route segment configs ignored |
| PPR (Partial Prerendering) | Use |
| 功能 | 状态 |
|---|---|
| 支持通过@unpic处理远程图片;不支持构建时优化 |
| 支持CDN加载,不支持自托管 |
| 基于域名的国际化 | 不支持;路径前缀式国际化可用 |
| 不支持;使用Vitest替代 |
| Turbopack/webpack配置 | 会被忽略;请使用Vite原生插件替代 |
| 路由段配置会被忽略 |
| PPR(部分预渲染) | 使用 |
Anti-patterns
反模式
- Do not modify ,
app/, or application code. vinext shims allpages/imports — no import rewrites needed.next/* - Do not rewrite imports to
next/*in application code. Imports likevinext/*,next/image,next/linkresolve automatically.next/server - Do not copy webpack/Turbopack config into Vite config. Use Vite-native plugins instead.
- Do not skip the compatibility check. Run before migration to surface issues early.
vinext check - Do not remove unless replacing it with
next.config.jsornext.config.ts. vinext reads it for redirects, rewrites, headers, basePath, i18n, images, and env config..mjs
- 请勿修改、
app/目录或应用代码。vinext会自动适配所有pages/导入——无需重写导入语句。next/* - 请勿将导入重写为
next/*。vinext/*、next/image、next/link等导入会自动解析。next/server - 请勿将webpack/Turbopack配置复制到Vite配置中。请使用Vite原生插件替代。
- 请勿跳过兼容性检查。迁移前运行可提前发现问题。
vinext check - 请勿删除,除非用
next.config.js或next.config.ts替代。vinext会读取该文件中的重定向、重写、请求头、basePath、国际化、图片和环境变量配置。.mjs