Solid components in one file.
Write the script, scoped styles and markup together. solid-sfc compiles them to a plain SolidJS 2.0 component.
npm install solid-sfc<script>
let count = $signal(0);
const doubled = $memo(count * 2);
const hot = $memo(count > 4);
</script>
<style>
button {
color: white;
background: royalblue;
scale: ${1 + Math.min(count, 8) / 40};
}
.hot {
background: crimson;
}
</style>
<button class={ hot } onClick=(() => count++)>
Count is {count}
</button>
#if (hot) {
<p>Doubled, that is {doubled}.</p>
}
Write less than in TSX
Signals read like variables. The compiler writes the Solid calls.
<script>
let count = $signal(0);
const doubled = $memo(count * 2);
</script>
<button onClick=(() => (count += 1))>
{count} × 2 = {doubled}
</button>
#if (count > 4) {
<p>That is a lot of clicks.</p>
}
import { createSignal as _createSignal, createMemo as _createMemo, Show as _Show } from 'solid-js';
export default function Counter() {
let [count, setCount] = _createSignal(0);
const doubled = _createMemo(() => count() * 2);
return (
<>
<button onClick={() => (setCount(current => current += 1))}>
{count()} × 2 = {doubled()}
</button>
<_Show when={count() > 4}>
<p>That is a lot of clicks.</p>
</_Show>
</>
);
}
Styles that stay in their file
Selectors only match this component. Signals become CSS variables.
<script>
let progress = $signal(40);
</script>
<style>
.bar {
width: ${progress}%;
background: royalblue;
}
</style>
<div class="bar" />
.bar[s-c1] {
width: var(--s-c1-0);
background: royalblue;
}
<div s-c1 class="bar" style="--s-c1-0: 40%"></div>
Typed, in your editor and in CI
TypeScript checks the markup too.
VS Code extension
Completion, errors, hover types and an outline inside .solid files.
Tooling docssolid-tsc
Type-checks .solid and .ts files together, for CI.
Tooling docsImports from .ts
The TypeScript plugin gives .ts files the props types of .solid files.
Tooling docs
- Vite
- Rollup
- Rolldown
- webpack
- Rspack
- esbuild
Why not plain TSX?
The same Solid runtime, with less to type.
| Task | solid-sfc | Solid TSX |
|---|---|---|
| Read a signal | count | count() |
| Scoped styles | Built in | CSS Modules or a library |
| Style from a signal | ${value} in CSS | A style prop by hand |
| Conditions and lists | #if, #for | <Show>, <For> |
| Editor support | VS Code, or the language server | Every TypeScript editor |
Questions
Is it ready to use?
Version 1 is out for SolidJS 2.0, under the MIT license.
Can I keep my .tsx components?
Yes. A .solid file compiles to a plain Solid component, so both import each other.
Does it render on the server?
Yes. The Vite plugin supports SSR, hydration and server functions.
I use solid-sfc 0.x. How do I move?
1.0 replaces the Babel plugin and solid-styled. The migration guide lists each change. Migration guide