Write signals as variables
solid-labels is a compiler for Solid 2.0. Read and assign $signal like any variable, and your bundler gets the accessor and setter calls.
npm install -D solid-labels unplugin-solid-labelspnpm add -D solid-labels unplugin-solid-labelsyarn add -D solid-labels unplugin-solid-labelsbun add -D solid-labels unplugin-solid-labelslet count = $signal(0);
const double = $memo(count * 2);
function increment() {
count += 1;
}
import { createSignal as _createSignal } from "solid-js";
import { createMemo as _createMemo } from "solid-js";
let [count, setcount_1] = _createSignal(0);
const double = _createMemo(() => count() * 2);
function increment() {
setcount_1(current_1 => current_1 += 1);
}import { createSignal as _createSignal } from "solid-js";
import { createMemo as _createMemo } from "solid-js";
let [count, setcount_1] = _createSignal(0, { name: "count" });
const double = _createMemo(() => count() * 2, { name: "double" });
function increment() {
setcount_1(current_1 => current_1 += 1);
}let query = $signal('');
let page = $signal(1);
$effect(() => {
console.log(`Searching ${query}, page ${page}`);
});
import { createSignal as _createSignal } from "solid-js";
import { createEffect as _createEffect } from "solid-js";
let [query, setquery_1] = _createSignal('');
let [page, setpage_1] = _createSignal(1);
_createEffect(() => [query(), page()], effectCallback_1);
function effectCallback_1([query, page]) {
console.log(`Searching ${query}, page ${page}`);
}import { createSignal as _createSignal } from "solid-js";
import { createEffect as _createEffect } from "solid-js";
let [query, setquery_1] = _createSignal('', { name: "query" });
let [page, setpage_1] = _createSignal(1, { name: "page" });
_createEffect(() => [query(), page()], effectCallback_1);
function effectCallback_1([query, page]) {
console.log(`Searching ${query}, page ${page}`);
}const Greeting = $component(({ name, excited = false }) => (
<p>
Hello, {name}
{excited ? '!' : '.'}
</p>
));
const Greeting = (props_1) => {
const name = () => props_1.name,
def_1 = false,
excited = () => { const value_1 = props_1.excited; return value_1 === void 0 ? def_1 : value_1; };
return (
<p>
Hello, {name()}
{excited() ? '!' : '.'}
</p>
);
};53% less to type
The same counter and effect, counted in characters without whitespace.
import { createSignal, createMemo, createEffect } from 'solid-js';
const [count, setCount] = createSignal(0);
const double = createMemo(() => count() * 2);
createEffect(
() => [count(), double()],
([count, double]) => {
document.title = `${count} doubled is ${double}`;
},
);
function increment() {
setCount((current) => current + 1);
}let count = $signal(0);
const double = $memo(count * 2);
$effect(() => {
document.title = `${count} doubled is ${double}`;
});
function increment() {
count += 1;
}Hand-written code uses solid-js@2.0.0.
What the compiler writes for you
Four jobs you stop doing.
Reads drop the parentheses
Writes use =, += and ++. The compiler adds the setter.
let count = $signal(0); count += 1; console.log(count);Effects list their own inputs
The compiler finds every signal the callback reads.
let query = $signal(''); $effect(() => { console.log(`Searching ${query}`); });Destructure props, stay reactive
Defaults become live reads of props.
const Greeting = $component(({ name, excited = false }) => ( <p>Hello, {name}{excited ? '!' : '.'}</p> ));Ships plain Solid
No runtime. The output imports only from solid-js.
import { createSignal as _createSignal } from "solid-js"; import { createMemo as _createMemo } from "solid-js"; let [count, setcount_1] = _createSignal(0); const double = _createMemo(() => count() * 2);
Against writing it by hand
Solid 2.0 either way. Your source differs.
| Task | solid-labels | Solid by hand |
|---|---|---|
| Read a signal | count | count() |
| Write a signal | count += 1 | setCount((c) => c + 1) |
| Effect dependencies | Found by the compiler | Listed in a separate function |
| Imports | Added by the compiler | Written by you |
| Reactive reads | Look like plain reads | Visible as calls |
| Build step | Needs a bundler plugin | Works with Solid's plugin alone |
Questions
Does solid-labels add code to my bundle?
No. The package has no runtime. The compiler runs inside your bundler, and the output imports only from solid-js and @solidjs/web.
Which Solid version does it support?
Solid 2.0 (tested with solid-js@2.0.0). For Solid 1.x, install solid-labels@0.17.
Which bundlers work?
Vite, Rollup and Bun through unplugin-solid-labels. Anything else can call compile() from solid-labels/compiler.
Does TypeScript understand $signal?
Yes. One /// <reference types="solid-labels" /> line declares every compile-time function globally, with full types.
Can I debug the code I wrote?
The compiler edits only the spans it rewrites, so the rest of your file keeps its formatting. Source maps cover every character.
Do I have to convert a whole project?
No. Files without compile-time functions pass through unchanged, so you can start with one component.
What does it cost?
Nothing. solid-labels is MIT licensed.
Write your first $signal
npm install -D solid-labels unplugin-solid-labelspnpm add -D solid-labels unplugin-solid-labelsyarn add -D solid-labels unplugin-solid-labelsbun add -D solid-labels unplugin-solid-labels