From 15fa376bb8feb1419aec1a810bb51663d57d37f3 Mon Sep 17 00:00:00 2001 From: uhyo Date: Sun, 28 Jun 2026 12:29:42 +0900 Subject: [PATCH] fix: include react and react-dom to optimize deps --- packages/example-fs-routing/vite.config.ts | 4 --- packages/static/src/plugin/index.ts | 29 ++++++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/packages/example-fs-routing/vite.config.ts b/packages/example-fs-routing/vite.config.ts index 998bd97..23dc06f 100644 --- a/packages/example-fs-routing/vite.config.ts +++ b/packages/example-fs-routing/vite.config.ts @@ -5,10 +5,6 @@ import { defineConfig } from "vite"; export default defineConfig({ plugins: [ funstackStatic({ - // SSR is required for file-system routing to render in the dev server - // (pages are server components rendered through FUNSTACK Router), and is - // recommended in general for SEO and faster initial load. - ssr: true, // Built-in file-system routing. Pages under `src/pages` are mapped to // routes via the Next.js-like adapter and rendered with FUNSTACK Router. fsRoutes: { diff --git a/packages/static/src/plugin/index.ts b/packages/static/src/plugin/index.ts index 9e3fc7d..380bcc3 100644 --- a/packages/static/src/plugin/index.ts +++ b/packages/static/src/plugin/index.ts @@ -247,24 +247,27 @@ export default function funstackStatic( if (!config.optimizeDeps) { config.optimizeDeps = {}; } + config.optimizeDeps.include ??= []; // Needed for properly bundling @vitejs/plugin-rsc for browser. // See: https://github.com/vitejs/vite-plugin-react/tree/79bf57cc8b9c77e33970ec2e876bd6d2f1568d5d/packages/plugin-rsc#using-vitejsplugin-rsc-as-a-framework-packages-dependencies - if (config.optimizeDeps.include) { - config.optimizeDeps.include = config.optimizeDeps.include.map( - (entry) => { - if (entry.startsWith("@vitejs/plugin-rsc")) { - entry = `@funstack/static > ${entry}`; - } - return entry; - }, - ); - } - if (!config.optimizeDeps.exclude) { - config.optimizeDeps.exclude = []; - } + config.optimizeDeps.include = config.optimizeDeps.include.map( + (entry) => { + if (entry.startsWith("@vitejs/plugin-rsc")) { + entry = `@funstack/static > ${entry}`; + } + return entry; + }, + ); + config.optimizeDeps.exclude ??= []; // Since code includes imports to virtual modules, we need to exclude // us from Optimize Deps. config.optimizeDeps.exclude.push("@funstack/static"); + // However, since Vite prohibits excluding a CommonJS package, + // we need to include React and ReactDOM so they are bundled properly. + config.optimizeDeps.include.push( + "@funstack/static > react", + "@funstack/static > react-dom", + ); }, }, {