npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@punkestu/react-html

v1.2.0

Published

Engine to convert React/JSX to pure HTML with selective reactive island compilation

Readme

react-html ⚛️ ➡️ 📄

A blazing-fast engine to convert React/JSX components into pure, semantic HTML with selective compilation of interactive components into micro JavaScript islands.

Write DRY, modular HTML using React components without shipping any React runtime or JavaScript to the client by default.

🌐 Live Demo: https://soreaja.my.id  |  🐙 GitHub: https://github.com/punkestu/react-html


🌐 Live Example & Repository


🌟 Why react-html?

  • Zero-JS by Default: Static pages are rendered to 100% pure HTML. No client-side React runtime, no <script> tags, and 0 KB JavaScript overhead.
  • Modular & DRY: Stop duplicating headers, footers, meta tags, and layouts. Build reusable components (<Layout>, <Header>, <Card>, <Footer>) using familiar React JSX syntax.
  • Selective Reactivity (Islands Architecture): When a component needs client-side interactivity (counters, modals, tabs, forms), the engine bundles only that component into a standalone, micro ESM script using esbuild.
  • Fast Build Pipeline: Powered by esbuild for instantaneous static site generation and sub-100ms builds.
  • Node.js Native: Runs strictly on standard Node.js (v20+) with npm.

🚀 Quick Start

Installation

npm install react-html

Or install globally / link locally:

npm link

CLI Usage

# Build static site to dist/ (with code splitting & automatic WebP image optimization)
react-html build

# Ultra-light Preact mode (drops total framework chunk to ~24 KB!)
react-html build --preact

# Disable automatic WebP image conversion
react-html build --no-webp

# Build with custom pages or output directory
react-html build --pages src/pages --out dist

# Start dev server with watch & live recompile
react-html dev --port 3000

📖 How It Works

1. Pure Modular HTML (Zero JavaScript)

Create your reusable layout and page components using standard JSX:

// src/components/Layout.tsx
import React, { ReactNode } from 'react';

export function Layout({ title, children }: { title: string; children: ReactNode }) {
  return (
    <html lang="en">
      <head>
        <meta charSet="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>{title}</title>
        <link rel="stylesheet" href="/styles.css" />
      </head>
      <body>
        <header>
          <h1>My Modular Site</h1>
        </header>
        <main>{children}</main>
      </body>
    </html>
  );
}
// src/pages/about.tsx
import React from 'react';
import { Layout } from '../components/Layout.js';

export default function AboutPage() {
  return (
    <Layout title="About Us">
      <h2>About Our Project</h2>
      <p>This entire page compiles into pure static HTML with 0 KB JavaScript!</p>
    </Layout>
  );
}

Output in dist/about.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charSet="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>About Us</title>
    <link rel="stylesheet" href="/styles.css"/>
  </head>
  <body>
    <header>
      <h1>My Modular Site</h1>
    </header>
    <main>
      <h2>About Our Project</h2>
      <p>This entire page compiles into pure static HTML with 0 KB JavaScript!</p>
    </main>
  </body>
</html>

2. Reactive Components (Island Auto-Discovery)

When a component needs client-side state and interactivity, simply name the file *.island.tsx (or place it inside an islands/ directory) and export default your pure React component. Zero wrapping required!

// src/components/Counter.island.tsx (or src/islands/Counter.tsx)
import React, { useState } from 'react';

export default function Counter({ initial = 0 }: { initial?: number }) {
  const [count, setCount] = useState(initial);

  return (
    <div className="counter">
      <button onClick={() => setCount(c => c - 1)}>-</button>
      <span>Count: {count}</span>
      <button onClick={() => setCount(c => c + 1)}>+</button>
    </div>
  );
}

Now import and use it in any page just like a normal React component:

// src/pages/index.tsx
import React from 'react';
import { Layout } from '../components/Layout.js';
import Counter from '../components/Counter.island.js';

export default function HomePage() {
  return (
    <Layout title="Home">
      <h2>Welcome!</h2>
      {/* Pre-rendered to HTML for instant paint, then hydrated with tiny JS */}
      <Counter initial={10} />
    </Layout>
  );
}

💡 Manual Island Wrapping (Optional): If you prefer explicit wrapping or have dynamic component references, island(Component, import.meta.url, 'Name') and <Island component={...} /> are also supported for full backward compatibility.

What the engine does:

  1. Renders the initial static markup during SSR for instant paint.
  2. Compiles a dedicated micro-bundle dist/assets/islands/Counter.js.
  3. Injects <script type="module" src="/assets/islands/Counter.js"></script> into index.html.
  4. Hydrates only the island element in-place using React 19's hydrateRoot.

3. Pure Vanilla DOM Islands (Zero-React Client Compilation)

Want client-side interactivity but zero React or VDOM runtime on the client?

You can write standard React JSX on the server for DRY markup, and export a native client(element, props) controller function in the same island file:

// src/components/VanillaCounter.island.tsx
import React from 'react';

// 1. Server: Pure modular HTML via standard React JSX
export default function VanillaCounter({ initialCount = 0, step = 1 }: { initialCount?: number; step?: number }) {
  return (
    <div className="counter-box">
      <span className="counter-value">{initialCount}</span>
      <button data-action="dec">- {step}</button>
      <button data-action="inc">+ {step}</button>
    </div>
  );
}

// 2. Client: Pure native DOM controller (Zero React/VDOM runtime!)
export function client(el: HTMLElement, props: { initialCount?: number; step?: number }) {
  let count = props.initialCount || 0;
  const step = props.step || 1;
  const display = el.querySelector('.counter-value');

  el.querySelector('[data-action="dec"]')?.addEventListener('click', () => {
    count -= step;
    if (display) display.textContent = String(count);
  });

  el.querySelector('[data-action="inc"]')?.addEventListener('click', () => {
    count += step;
    if (display) display.textContent = String(count);
  });
}

Why this is huge:

  • 0 KB React, 0 KB ReactDOM, 0 KB Preact: The engine completely stubs React in the client bundle.
  • Zero Chunk Imports: Outputs a single, self-contained standalone .js file (~1 KB uncompressed, ~450 bytes gzipped).
  • Zero Hydration Overhead: Bypasses VDOM reconciliation and binds native event listeners directly to existing DOM nodes.
  • Mix & Match: You can use Pure Vanilla DOM islands and standard React/Preact islands in the very same project without conflict!

🛠️ Hydration Directives

react-html supports client loading directives to maximize performance:

| Directive | Syntax | Behavior | | :--- | :--- | :--- | | load (default) | <Counter client="load" /> | Hydrates immediately on DOM ready | | idle | <Counter client="idle" /> | Hydrates during browser idle time (requestIdleCallback) | | visible | <Counter client="visible" /> | Hydrates when scrolled into view (IntersectionObserver) |


⚡ Tiny Island Bundles & Preact Ultra-Light Mode

react-html uses ESM multi-entry code splitting and comment stripping to keep island bundles tiny:

  • Code Splitting by Default: Component logic is separated from runtime code. Counter.js and Tabs.js weigh only ~800 bytes to 1 KB each, importing a shared vendor chunk that the browser caches across all pages.
  • Ultra-Light Preact Mode (--preact): Want microscopic client bundles? Pass --preact to alias client hydration to preact/compat. You still write standard React JSX, but the shared runtime shrinks by 90% down to ~24 KB uncompressed (~8 KB gzipped)!
# Build with Preact ultra-light runtime
react-html build --preact

🖼️ Automatic WebP Image Optimization

On build, react-html automatically scans raster images in your static assets (.png, .jpg, .jpeg, .gif, .tiff, .bmp) and converts them into optimized, high-performance .webp format.

  • Automatic Conversion: Runs out of the box during react-html build.
  • Exclusive WebP Output: Non-webp images are never copied to the output directory; only .webp images are output in dist/.
  • Opt-Out Flag: Disable conversion anytime using --no-webp (or webp: false in build()), which preserves and copies images in their original formats.
  • Quality Control: Custom quality settings via --webp-quality <1-100> (default: 80).
# Disable WebP conversion
react-html build --no-webp

# Custom WebP quality (1-100)
react-html build --webp-quality 90

💻 Programmatic API

You can also run react-html programmatically from your Node.js scripts:

import { build } from 'react-html';

const result = await build({
  root: process.cwd(),
  pagesDir: 'src/pages',
  outDir: 'dist',
  minify: true,
  // WebP options (enabled by default)
  webp: {
    enabled: true,       // Set to false to disable (copies original formats)
    quality: 80,         // 1-100 (default: 80)
    keepOriginal: false  // Keep original non-webp files (default: false)
  }
});

console.log(`Compiled ${result.pages.length} pages, ${result.islands.length} islands, and optimized ${result.images.length} images.`);

🧪 Testing

Run the automated test suite powered by Node.js test runner:

npm test

Continuous Integration (CI)

Automated testing is configured via GitHub Actions in .github/workflows/test.yml:

  • Runs automatically on every push and pull_request targeting main.
  • Matrix test strategy executes builds (npm run build) and unit tests (npm test) across both Node.js 20 LTS and Node.js 22 LTS.

📄 License

MIT