For AI agents: the complete documentation index is available at https://rspack.rs/llms.txt, the full documentation bundle is available at https://rspack.rs/llms-full.txt, and this page is available as Markdown at https://rspack.rs/guide/integrations/solid.md.
close

Solid

How to use

There are two ways to use Solid with Rspack:

  • Use Rsbuild to start a Solid project with JSX compilation and hot module replacement (HMR) already configured. Follow the Rsbuild guide for Solid.
  • Configure Rspack manually to add Solid to your own Rspack configuration. Follow the steps below or start from the Rspack + Solid example.

Configure Solid

Solid components are commonly written in JSX or TSX. solid-loader lets Rspack compile those components with Solid's native compiler.

The loader requires Rspack 2.0.0 or later and Solid 2.0.0 or later. For an existing Solid 1 project, see Solid v1.

Compile JSX and TSX

Install solid-loader as a development dependency.

npm
yarn
pnpm
bun
deno
npm add solid-loader -D

Add a rule for JavaScript and TypeScript files. In this rule, solid-loader handles JSX and TSX, and builtin:swc-loader removes TypeScript types.

rspack.config.ts
import { defineConfig } from '@rspack/cli';

export default defineConfig({
  resolve: {
    extensions: ['...', '.ts', '.tsx', '.jsx'],
  },
  module: {
    rules: [
      {
        test: /\.[cm]?[jt]sx?$/,
        resolve: {
          fullySpecified: false,
        },
        use: [
          {
            loader: 'builtin:swc-loader',
            options: { detectSyntax: 'auto' },
          },
          'solid-loader',
        ],
      },
    ],
  },
});

Configure TypeScript

For Solid JSX type checking and editor completions, add these options to your tsconfig.json. Rspack compiles JSX and TSX using the loader rule above.

tsconfig.json
{
  "compilerOptions": {
    "jsx": "preserve",
    "jsxImportSource": "@solidjs/web"
  }
}

Resolve Solid libraries

Some Solid component libraries publish their JSX source under the solid condition in their package exports. Add 'solid' to resolve.conditionNames so Rspack can select that source and compile it with the rule above. The '...' entry keeps Rspack's default conditions.

rspack.config.ts
import { defineConfig } from '@rspack/cli';

export default defineConfig({
  resolve: {
    conditionNames: ['solid', '...'],
  },
});

Load hydration modules

When Solid makes a server-rendered page interactive, its web runtime (@solidjs/web) can load additional modules. The server supplies their URLs, and the browser loads them with import(url).

Add the following rule to module.rules. It sets parser.importDynamic to false for @solidjs/web so Rspack preserves the runtime's native import() calls.

rspack.config.ts
import { defineConfig } from '@rspack/cli';

export default defineConfig({
  module: {
    rules: [
      {
        descriptionData: { name: /^@solidjs\/web$/ },
        parser: { importDynamic: false },
      },
    ],
  },
});

Solid v1

For a Solid 1 project, use babel-loader with babel-preset-solid to compile JSX and solid-refresh for hot updates. The Solid v1 example shows the complete Rspack configuration. If you use Rsbuild, follow the Rsbuild guide for Solid v1.