Solid
In this document, you will learn how to build a Solid component library using Rslib. You can check out Solid related example projects in Examples.
Create Solid project
You can use create-rslib to create a project with Rslib + Solid. Just execute the following command:
Then select Solid when prompted to "Select template".
Use Rslib in an existing project
To develop a Solid library, you need to set the target to "web" in rslib.config.ts. This is crucial because Rslib sets the target to "node" by default.
To compile Solid JSX, you need to register both the @rsbuild/plugin-babel and @rsbuild/plugin-solid plugins. The Solid plugin uses babel-preset-solid to transform JSX into Solid's runtime DOM expressions.
Output
Solid component libraries usually ship two types of outputs:
- Pre-compiled output: JSX has already been transformed by
babel-preset-solidinto Solid runtime calls, such astemplate()andinsert(). Application projects that use this component library can import this output directly, without configuring Solid JSX compilation. - JSX source output: the library build does not compile Solid JSX. Instead, it preserves the original JSX syntax and exposes it through the
"solid"condition name inpackage.jsonfor the application-side toolchain.
When an application project that uses this component library can compile Solid JSX (for example, an Rsbuild project with @rsbuild/plugin-solid installed), module resolution will hit the "solid" condition name, read the JSX source output, and recompile it for the application's runtime target: browser apps compile it into client-side DOM rendering code (generate: 'dom'), while SSR frameworks compile it into server-side rendering code (generate: 'ssr'). Application projects without Solid JSX compilation configured fall back to the pre-compiled "import" entry.
Then configure the "exports" field in package.json:
TypeScript
For Solid projects using TypeScript, set "jsx": "preserve" and "jsxImportSource": "solid-js" in your tsconfig.json:
SSR
Most Solid component libraries do not publish a separate SSR build by default. Instead, downstream frameworks resolve the "solid" condition name, get the preserved JSX output, and compile it for their own target.
If you intentionally need a pre-compiled SSR output, configure pluginSolid with the solid.generate option set to 'ssr':
