Guides

Inline components from packages

List a package in optimizer.packages so its components are copied into your modules and inline there.

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.

vite.config.tsTypeScript
solid({
  ssr: true,
  optimizer: {
    packages: ['@kobalte/core'],
  },
});

Steps#

  1. Check that the package publishes its JSX. Most Solid libraries do through the solid export condition. A package that does not publish JSX has none to copy.

  2. Add the package to the list.

    vite.config.tsTypeScript
    solid({ optimizer: { packages: ['@kobalte/core'] } });

    Re-exports and aliases like const Button = ButtonRoot are followed.

  3. 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.tsTypeScript
    export 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.

  4. Build with optimizer.report on, and read the copy-* reasons.

    ReasonCause
    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.