We already test this in examples/basic and we can document this as basic suggestion.
|
{ |
|
name: 'optimize-chunks', |
|
apply: 'build', |
|
config() { |
|
const resolvePackageSource = (source: string) => |
|
normalizePath(fileURLToPath(import.meta.resolve(source))) |
|
|
|
// TODO: this package entry isn't a public API. |
|
const reactServerDom = resolvePackageSource( |
|
'@vitejs/plugin-rsc/react/browser', |
|
) |
|
|
|
return { |
|
environments: { |
|
client: { |
|
build: { |
|
rollupOptions: { |
|
output: { |
|
manualChunks: (id) => { |
|
// need to use functional form to handle commonjs plugin proxy module |
|
// e.g. `(id)?commonjs-es-import` |
|
if ( |
|
id.includes('node_modules/react/') || |
|
id.includes('node_modules/react-dom/') || |
|
id.includes(reactServerDom) |
|
) { |
|
return 'lib-react' |
|
} |
|
if (id === '\0vite/preload-helper.js') { |
|
return 'lib-vite' |
|
} |
|
}, |
|
}, |
|
}, |
|
}, |
|
}, |
|
}, |
|
} |
|
}, |
We already test this in
examples/basicand we can document this as basic suggestion.vite-plugin-react/packages/plugin-rsc/examples/basic/vite.config.ts
Lines 125 to 163 in a96a6b2