# @solidjs/compiler Solid 2.0's native Oxc JSX compiler. Integrations call `transform()` once per source module; this package is not a Vite, Rollup, or Babel plugin by itself. The JavaScript fallback is [`@solidjs/babel-plugin`](../babel-plugin). > **Solid 2.0.** Pin exact versions. The Node `transform()` interface is the supported public contract; the Rust `compile` API is unstable. ## Installation ```bash npm install @solidjs/compiler ``` The package ships prebuilt native binaries as optional per-platform packages (`@solidjs/compiler-darwin-arm64`, `-darwin-x64`, `-linux-x64-gnu`, `-linux-arm64-gnu`, `-win32-x64-msvc`). Your package manager installs the one matching your platform. On other platforms, build from source with `pnpm run build` inside `packages/compiler` (requires a Rust toolchain). ### WebAssembly and StackBlitz A WASI fallback covers environments such as StackBlitz WebContainers, where Node reports a native platform but cannot load `.node` addons. Package managers install `@solidjs/compiler-wasm32-wasi` as an optional dependency. The package entry prefers a native binding and falls back to WASI when native addons are unavailable. - `NAPI_RS_FORCE_WASI=error` requires the WASI binding (useful in tests). - `SOLID_COMPILER_NATIVE=/path/to/binding.node` loads an explicit native addon. ## Usage Omitted options match `@solidjs/babel-plugin` (and the old `babel-preset-solid`): `moduleName` is `"@solidjs/web"`, `generate` is `"dom"`, and control-flow tags (`For`, `Show`, `Switch`, `Match`, `Loading`, `Reveal`, `Portal`, `Repeat`, `Dynamic`, `Errored`) are auto-imported from that module. ```js const { transform } = require("@solidjs/compiler"); const result = transform(`const view =
Hello
;`, { filename: "App.jsx" }); console.log(result.code); ``` `transformAsync()` is the same transform behind a promise, for integration points that expect one. ### Client DOM ```js const result = transform(source, { filename: "App.jsx", generate: "dom", hydratable: true }); ``` `contextToCustomElements` defaults to `true`. Use `dev: true` with `hydratable: true` to emit hydration walk helpers such as `getFirstChild` / `getNextSibling`. ### SSR SSR still imports runtime helpers from `@solidjs/web`. Set `generate: "ssr"` (and `hydratable: true` when the client will hydrate). ```js const result = transform(source, { filename: "entry-server.jsx", generate: "ssr", hydratable: true }); ``` ### Universal and dynamic Custom renderers use `generate: "universal"` with `moduleName` pointing at the renderer package. Dynamic mode uses that renderer as the fallback and can route a configured set of native tags to the DOM renderer. ```js const result = transform(source, { filename: "hybrid.jsx", moduleName: "solid-custom-dom", generate: "dynamic", renderers: [ { name: "dom", moduleName: "@solidjs/web", elements: ["div", "span", "button", "input"] } ] }); ``` ### TSRX (experimental) TSRX (TypeScript Render Extensions) is a syntax for declarative UI whose constructs (`@if`/`@else`, `@for … @empty`, `@switch`/`@case`, `@try`/`@catch`/`@pending`, and `@{}` statement containers) desugar to the Solid control-flow components. `.tsrx` filenames route through the TSRX frontend automatically and compile to the same output as `@solidjs/babel-plugin`'s TSRX support, byte for byte. ```js const result = transform(tsrxSource, { filename: "App.tsrx" }); // TSRX