π No-Build, No-Dependencies Setup with SeraJS β
SeraJS supports direct use in the browser with no bundlers, no build steps, and zero dependencies. This guide shows you how to use SeraJS in a raw HTML file using native ES modules.
β What You Get β
- π« No need for Webpack, Vite, or Babel
- β
Pure native
import
from CDN (e.g. unpkg.com) - β‘ Fast, minimal and reactive UI with signals and effects
π Example: Basic Counter Component β
html
<!DOCTYPE html>
<html>
<head>
<title>Sera js π</title>
</head>
<body>
<script type="module">
import { h, setSignal, setEffect } from "//unpkg.com/serajs";
function Hello() {
const [count, setCount] = setSignal(0);
setEffect(() => {
console.log(count()); // Runs when count changes
});
return h(
"div",
null,
h("h1", null, "Hello World!"),
h("p", { style: { color: "red" } }, "Do you Like Serajs?"),
h("h1", null, () => `Count: ${count()}`),
h(
"button",
{ onclick: () => setCount(count() + 1) },
"Increase Count"
)
);
}
const root = document.body;
root.appendChild(Hello());
</script>
</body>
</html>
π Explanation β
β
import { h, setSignal, setEffect } from "//unpkg.com/serajs";
β
h(tag, props, ...children)
: Creates a virtual DOM node (like React'screateElement
).setSignal(value)
: Creates a reactive state signal.- Returns
[getter, setter]
.
- Returns
setEffect(callback)
: Runs a reactive effect whenever any accessed signal changes.
π‘ Why This Is Cool β
- β‘ Instant load in the browser
- π§ͺ Perfect for experiments, CodePens, or quick demos
- π Great for teaching or learning reactivity without overhead
- π Production-ready with tiny 1.25kb code size
- πΌ Practical for real apps where bundle size matters
π Tips β
- For local dev, use a live server or open in Chrome with the
--allow-file-access-from-files
flag (if importing modules from local paths). - Always use
"type=module"
for script tags when using native ES module imports.
π Zero-Setup Folder Structure β
/your-project
βββ index.html
Thatβs it! No package.json
, no node_modules
.
π§ͺ Try It Yourself β
Paste the above code into an index.html
file and open it in your browser.
Happy hacking with SeraJS! π