Migrating from Next.js
Most Next.js projects will migrate to Swift Rust with minimal effort. The file-based router, the layout system, the data-fetching patterns, and the components are all familiar.
What stays the same
- The
app/directory layout layout.tsx,page.tsx,loading.tsx,error.tsx,not-found.tsx- Dynamic segments (
[slug],[...catchAll]) - Route handlers (
app/api/foo/route.tswithGET,POST) - The
Image,Font, andHeadcomponents - Server components by default,
"use client"for client components
What changes
Package names
Replace next with swift-rust everywhere. Import paths become:
next/image→swift-rust(theImagecomponent)next/font/google→swift-rust/font/googlenext/font/local→swift-rust/font/localnext/link→swift-rust(theLinkcomponent)next/navigation→swift-rust/routernext/server→swift-rust/router
Removed
next.config.js→swift-rust.config.json(JSON, not JS)next-env.d.ts→ not needed; types come fromswift-rustdirectlynext/script→ use a<script>tag withdangerouslySetInnerHTMLor import the script at the top of a"use client"componentuseRouterfromnext/navigation→ fromswift-rust/router
Server actions
Server actions work the same way. The only difference is the import path.
Image loader
The loader prop on <Image> uses /_swift-rust/image instead of /_next/image. If you have a custom loader, point it at the new path.
Render modes
Set "rendering": "ssr-wasm" in swift-rust.config.json to match the Next.js App Router's behavior. Other modes ("ssr", "ssr-htmx", "wasm") don't have direct Next.js equivalents.
Step-by-step migration
- Scaffold a new Swift Rust project alongside your existing one.
- Copy
app/,components/, andlib/across. - Run a search-and-replace for
from "next/tofrom "swift-rust/(or for justfrom "swift-rust). - Update
package.jsondependencies. - Update
tsconfig.jsonpaths if needed (Swift Rust uses the same"@/*"convention by default). - Run
bun installandbun run dev.