Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/vinext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
},
"devDependencies": {
"@vitejs/plugin-rsc": "0.5.19",
"vite": "7.3.1"
"vite": "^8.0.0"
}
}
2 changes: 1 addition & 1 deletion examples/app-router-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": {
"react": "^19.2.4",
"react-dom": "^19.2.4",
"vite": "^7.3.1",
"vite": "^8.0.0",
"vinext": "workspace:*",
"@vitejs/plugin-rsc": "^0.5.19",
"react-server-dom-webpack": "^19.2.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/app-router-nitro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": {
"react": "^19.2.4",
"react-dom": "^19.2.4",
"vite": "^7",
"vite": "^8.0.0",
"vinext": "workspace:*",
"nitro": "npm:nitro-nightly@latest"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/app-router-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"postcss": "8.5.3",
"tailwindcss": "4.1.4",
"typescript": "^5.0.0",
"vite": "^7.0.0",
"vite": "^8.0.0",
"wrangler": "^4.65.0"
}
}
2 changes: 1 addition & 1 deletion examples/benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": {
"react": "^19.2.4",
"react-dom": "^19.2.4",
"vite": "^7.3.1",
"vite": "^8.0.0",
"vinext": "workspace:*",
"@vitejs/plugin-rsc": "^0.5.19",
"react-server-dom-webpack": "^19.2.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/hackernews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"react": "^19.2.4",
"react-dom": "^19.2.4",
"server-only": "^0.0.1",
"vite": "^7.3.1",
"vite": "^8.0.0",
"vinext": "workspace:*",
"@vitejs/plugin-rsc": "^0.5.19",
"react-server-dom-webpack": "^19.2.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/nextra-docs-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@types/react-dom": "^19.0.0",
"@vitejs/plugin-rsc": "^0.5.0",
"typescript": "^5.0.0",
"vite": "^7.0.0",
"vite": "^8.0.0",
"wrangler": "^4.65.0"
}
}
2 changes: 1 addition & 1 deletion examples/pages-router-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": {
"react": "^19.2.4",
"react-dom": "^19.2.4",
"vite": "^7.3.1",
"vite": "^8.0.0",
"vinext": "workspace:*",
"@cloudflare/vite-plugin": "^1.25.0",
"wrangler": "^4.65.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/realworld-api-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"react": "^19.2.4",
"react-dom": "^19.2.4",
"swr": "^2.0.0",
"vite": "^7.3.1",
"vite": "^8.0.0",
"vinext": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/tpr-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"react": "^19.2.4",
"react-dom": "^19.2.4",
"react-server-dom-webpack": "^19.2.4",
"vite": "^7.3.1",
"vite": "^8.0.0",
"vinext": "workspace:*",
"@vitejs/plugin-rsc": "^0.5.19"
},
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@
"react": "^19.2.4",
"react-dom": "^19.2.4",
"typescript": "^5.7.0",
"vite": "^7.3.1",
"vitest": "^3.2.1"
"vite": "^8.0.0",
"vitest": "^4.1.0"
},
"packageManager": "pnpm@10.30.0",
"pnpm": {
"overrides": {
"rollup": "^4.59.0"
},
"peerDependencyRules": {
"ignoreMissing": [
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/vinext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-rsc": "^0.5.19",
"react-server-dom-webpack": "^19.2.4",
"vite": "^7.3.1"
"vite": "^8.0.0"
},
"peerDependencies": {
"@mdx-js/rollup": "^3.0.0",
"@vitejs/plugin-rsc": "^0.5.19",
"react": ">=19.2.0",
"react-dom": ">=19.2.0",
"react-server-dom-webpack": "^19.2.4",
"vite": "^7.0.0 || ^8.0.0"
"vite": "^8.0.0"
},
"peerDependenciesMeta": {
"@mdx-js/rollup": {
Expand Down
4 changes: 2 additions & 2 deletions packages/vinext/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ async function buildApp() {
outDir: "dist/client",
manifest: true,
ssrManifest: true,
rollupOptions: {
rolldownOptions: {
input: "virtual:vinext-client-entry",
output: clientOutputConfig,
treeshake: clientTreeshakeConfig,
Expand All @@ -403,7 +403,7 @@ async function buildApp() {
build: {
outDir: "dist/server",
ssr: "virtual:vinext-server-entry",
rollupOptions: {
rolldownOptions: {
output: {
entryFileNames: "entry.js",
},
Expand Down
42 changes: 10 additions & 32 deletions packages/vinext/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import { hasBasePath } from "./utils/base-path.js";
import { asyncHooksStubPlugin } from "./plugins/async-hooks-stub.js";
import { clientReferenceDedupPlugin } from "./plugins/client-reference-dedup.js";
import { hasWranglerConfig, formatMissingCloudflarePluginError } from "./deploy.js";
import tsconfigPaths from "vite-tsconfig-paths";
import react, { Options as VitePluginReactOptions } from "@vitejs/plugin-react";
import MagicString from "magic-string";
import path from "node:path";
Expand Down Expand Up @@ -234,22 +233,6 @@ function extractStaticValue(node: any): unknown {
}
}

/**
* Detect Vite major version at runtime by resolving from cwd.
* The plugin may be installed in a workspace root with Vite 7 but used
* by a project that has Vite 8 — so we resolve from cwd, not from
* the plugin's own location.
*/
function getViteMajorVersion(): number {
try {
const require = createRequire(path.join(process.cwd(), "package.json"));
const vitePkg = require("vite/package.json");
return parseInt(vitePkg.version, 10);
} catch {
return 7; // default to Vite 7
}
}

type UserResolveConfigWithTsconfigPaths = NonNullable<UserConfig["resolve"]> & {
tsconfigPaths?: boolean;
};
Expand Down Expand Up @@ -708,7 +691,6 @@ export interface VinextOptions {
}

export default function vinext(options: VinextOptions = {}): PluginOption[] {
const viteMajorVersion = getViteMajorVersion();
let root: string;
let pagesDir: string;
let appDir: string;
Expand Down Expand Up @@ -830,7 +812,6 @@ export default function vinext(options: VinextOptions = {}): PluginOption[] {
// Resolve tsconfig paths/baseUrl aliases so real-world Next.js repos
// that use @/*, #/*, or baseUrl imports work out of the box.
// Vite 8+ supports this natively via resolve.tsconfigPaths.
...(viteMajorVersion >= 8 ? [] : [tsconfigPaths()]),
// React Fast Refresh + JSX transform for client components.
reactPlugin,
// Transform CJS require()/module.exports to ESM before other plugins
Expand All @@ -843,8 +824,7 @@ export default function vinext(options: VinextOptions = {}): PluginOption[] {
async config(config, env) {
root = config.root ?? process.cwd();
const userResolve = config.resolve as UserResolveConfigWithTsconfigPaths | undefined;
const shouldEnableNativeTsconfigPaths =
viteMajorVersion >= 8 && userResolve?.tsconfigPaths === undefined;
const shouldEnableNativeTsconfigPaths = userResolve?.tsconfigPaths === undefined;

// Load .env files into process.env before anything else.
// Next.js loads .env files before evaluating next.config.js, so
Expand Down Expand Up @@ -1166,15 +1146,16 @@ export default function vinext(options: VinextOptions = {}): PluginOption[] {
// Disable Vite's default HTML serving - we handle all routing
appType: "custom",
build: {
rollupOptions: {
rolldownOptions: {
// Suppress "Module level directives cause errors when bundled"
// warnings for "use client" / "use server" directives. Our shims
// and third-party libraries legitimately use these directives;
// they are handled by the RSC plugin and are harmless in the
// final bundle. We preserve any user-supplied onwarn so custom
// warning handling is not lost.
onwarn: (() => {
const userOnwarn = config.build?.rollupOptions?.onwarn;
const userOnwarn =
config.build?.rolldownOptions?.onwarn ?? config.build?.rollupOptions?.onwarn;
return (warning, defaultHandler) => {
if (
warning.code === "MODULE_LEVEL_DIRECTIVE" &&
Expand Down Expand Up @@ -1260,11 +1241,8 @@ export default function vinext(options: VinextOptions = {}): PluginOption[] {
optimizeDeps: {
exclude: ["vinext", "@vercel/og"],
},
// Enable JSX in .tsx/.jsx files
// Vite 7 uses `esbuild` for transforms, Vite 8+ uses `oxc`
...(viteMajorVersion >= 8
? { oxc: { jsx: { runtime: "automatic" } } }
: { esbuild: { jsx: "automatic" } }),
// Enable JSX in .tsx/.jsx files (Vite 8 uses oxc for transforms)
oxc: { jsx: { runtime: "automatic" } },
// Define env vars for client bundle
define: defines,
// Set base path if configured
Expand Down Expand Up @@ -1327,7 +1305,7 @@ export default function vinext(options: VinextOptions = {}): PluginOption[] {
},
build: {
outDir: "dist/server",
rollupOptions: {
rolldownOptions: {
input: { index: VIRTUAL_RSC_ENTRY },
},
},
Expand All @@ -1352,7 +1330,7 @@ export default function vinext(options: VinextOptions = {}): PluginOption[] {
},
build: {
outDir: "dist/server/ssr",
rollupOptions: {
rolldownOptions: {
input: { index: VIRTUAL_APP_SSR_ENTRY },
},
},
Expand Down Expand Up @@ -1390,7 +1368,7 @@ export default function vinext(options: VinextOptions = {}): PluginOption[] {
// on every page — defeating code-splitting for React.lazy() and
// next/dynamic boundaries.
...(hasCloudflarePlugin ? { manifest: true } : {}),
rollupOptions: {
rolldownOptions: {
input: { index: VIRTUAL_APP_BROWSER_ENTRY },
output: clientOutputConfig,
treeshake: clientTreeshakeConfig,
Expand All @@ -1409,7 +1387,7 @@ export default function vinext(options: VinextOptions = {}): PluginOption[] {
build: {
manifest: true,
ssrManifest: true,
rollupOptions: {
rolldownOptions: {
input: { index: VIRTUAL_CLIENT_ENTRY },
output: clientOutputConfig,
treeshake: clientTreeshakeConfig,
Expand Down
Loading
Loading