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
1 change: 1 addition & 0 deletions packages/plugin-rsc/examples/basic/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default defineConfig({
ssr: './src/framework/entry.ssr.tsx',
rsc: './src/server.tsx',
},
frameworkPackages: ['react'],
// disable auto css injection to manually test `loadCss` feature.
rscCssTransform: false,
ignoredPackageWarnings: [/@vitejs\/test-dep-/],
Expand Down
19 changes: 16 additions & 3 deletions packages/plugin-rsc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ export type RscPluginOptions = {

/** Escape hatch for Waku's `allowServer` */
keepUseCientProxy?: boolean

/**
* The packages which depend on `frameworkPackages` will be automatically added to `noExternal`.
* @default ["react"]
*/
frameworkPackages?: string[]
}

export default function vitePluginRsc(
Expand All @@ -123,15 +129,22 @@ export default function vitePluginRsc(

// crawl packages with "react" in "peerDependencies" to bundle react deps on server
// see https://github.com/svitejs/vitefu/blob/d8d82fa121e3b2215ba437107093c77bde51b63b/src/index.js#L95-L101
const frameworkPackages = rscPluginOptions.frameworkPackages || [
'react',
]
const result = await crawlFrameworkPkgs({
root: process.cwd(),
isBuild: env.command === 'build',
isFrameworkPkgByJson(pkgJson) {
// these are added by default and don't need to crawl further
if ([PKG_NAME, 'react-dom'].includes(pkgJson.name)) {
return
return false
}
const deps = {
...pkgJson['dependencies'],
...pkgJson['peerDependencies'],
}
const deps = pkgJson['peerDependencies']
return deps && 'react' in deps
return frameworkPackages.some((name) => name in deps)
},
})
const noExternal = [
Expand Down
Loading