optimizer.packages lists packages whose components are copied into the modules that use them. Their copies inline wherever they can be, so the bundler drops the originals, even when the package lands in another chunk.
solid({
ssr: true,
optimizer: {
packages: ['@kobalte/core'],
},
});Steps#
Check that the package publishes its JSX. Most Solid libraries do through the
solidexport condition. A package that does not publish JSX has none to copy.Add the package to the list.
vite.config.tsTypeScriptsolid({ optimizer: { packages: ['@kobalte/core'] } });Re-exports and aliases like
const Button = ButtonRootare followed.Bundle the package in every build. A listed package has to be bundled in the server build and the client build, or the two builds copy different components. For a server build that leaves dependencies to Node, add the package to
ssr.noExternal.vite.config.tsTypeScriptexport default defineConfig({ ssr: { noExternal: ['@kobalte/core'] }, plugins: [solid({ ssr: true, optimizer: { packages: ['@kobalte/core'] } })], });The plugin warns once when a listed package is external in a build. See Errors.
Build with
optimizer.reporton, and read thecopy-*reasons.Reason Cause copy-external,copy-packageThe module is external to the bundle, or in a package the list does not name. copy-not-jsxThe module is not one the official plugin lowers. copy-cycleThe component's module imports the importer back. copy-shapeThe export is not a component the inline pass can read. copy-wrapperThe component only returns a call of another component in its module. copy-size,copy-no-host,copy-leftThe copy was made but did not inline. The part after copy-is the inline reason.See Report reasons for the full list.
Components from dependencies in node_modules are only copied from the packages this option lists. Copies of listed components inline whatever the size estimate says, since the estimate cannot see the runtime code that only they use.
Related#
- Vite plugin options for the option.
- Find out why a component stays to read the report.
- Hydration for why both builds must copy the same components.
- Chunk and module mode for how copies land in chunks.