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
Counter.solid
<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>
}
DOM

Write less than in TSX

Signals read like variables. The compiler writes the Solid calls.

Counter.solid
<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>
}
What the compiler writes
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.

Progress.solid
<script>
  let progress = $signal(40);
</script>

<style>
  .bar {
    width: ${progress}%;
    background: royalblue;
  }
</style>

<div class="bar" />
Stylesheet and DOM
.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.

  • Vite
  • Rollup
  • Rolldown
  • webpack
  • Rspack
  • esbuild

Why not plain TSX?

The same Solid runtime, with less to type.

Tasksolid-sfcSolid TSX
Read a signalcountcount()
Scoped stylesBuilt inCSS Modules or a library
Style from a signal${value} in CSSA style prop by hand
Conditions and lists#if, #for<Show>, <For>
Editor supportVS Code, or the language serverEvery 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

Try it without installing