Skip to content

Document manualChunks example #865

@hi-ogawa

Description

@hi-ogawa

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'
}
},
},
},
},
},
},
}
},

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions