Vite Plugin Lets You Run Next.js APIs Anywhere
If you love the developer experience of Next.js but sometimes wish you could deploy your app on any platform, not just Vercel, there's a new tool you should know about. A Vite plugin is quietly changing the game by letting you take the familiar Next.js API routes and rendering patterns with you, wherever you want to host.
Enter vinext—a project from Cloudflare that re-implements the core Next.js API surface on top of Vite. It’s essentially a compatibility layer that lets you write code that feels like Next.js, but build and deploy it as a standard Vite application. This means you’re no longer locked into a specific deployment ecosystem.
What It Does
In short, vinext is a Vite plugin that mimics the way Next.js handles API routes, server-side rendering (SSR), and static site generation (SSG). You structure your project like a Next.js app (think pages/api/ for APIs and getServerSideProps for data fetching), but under the hood, it's powered by Vite's build system.
When you run the build, vinext processes your pages and API routes, outputting a application that can run on Node.js, Cloudflare Workers, or other platforms that support standard JavaScript deployments. It’s not a full clone of Next.js, but it faithfully replicates the parts developers use most.
Why It’s Cool
The clever part here is the focus on developer experience and portability. Many teams have built muscle memory around Next.js's file-based routing and API design. vinext respects that investment while removing the platform constraint. You can keep writing code the same way, but ship it to your own server, a different edge network, or anywhere else that fits your needs.
It’s also built with performance in mind, leveraging Vite’s fast startup and build times. Since it’s plugin-based, it integrates seamlessly into an existing Vite project, meaning you can incrementally adopt this pattern or mix it with other Vite features.
How to Try It
Getting started is straightforward. You can spin up a new project using the template:
npm create vite@latest my-vinext-app -- --template cloudflare-vinext
cd my-vinext-app
npm install
npm run dev
Or, add it to an existing Vite project:
npm install @cloudflare/vite-plugin-vinext
Then, configure your vite.config.js:
import { defineConfig } from 'vite';
import vinext from '@cloudflare/vite-plugin-vinext';
export default defineConfig({
plugins: [vinext()]
});
From there, start creating files in pages/ just like you would in Next.js. Check out the GitHub repository for detailed examples and the full API reference.
Final Thoughts
vinext feels like a pragmatic answer to a common developer dilemma. It acknowledges that Next.js got the API design right for a lot of use cases, but offers an escape hatch for teams who need deployment flexibility. It won’t replace Next.js for everyone, but it’s a fantastic option if you’re building a full-stack app and want to keep your options open for where it runs.
Give it a try on your next side project or if you’re considering a platform migration. It might just save you a rewrite.
@githubprojects
Repository: https://github.com/cloudflare/vinext