@punkestu/react-html 0.1.0 ā 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/docs-content.d.ts +8 -0
- package/dist/cli/docs-content.d.ts.map +1 -0
- package/dist/cli/docs-content.js +261 -0
- package/dist/cli/docs-content.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +113 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/tui-docs.d.ts +5 -0
- package/dist/cli/tui-docs.d.ts.map +1 -0
- package/dist/cli/tui-docs.js +191 -0
- package/dist/cli/tui-docs.js.map +1 -0
- package/dist/client/hydrate.d.ts +4 -0
- package/dist/client/hydrate.d.ts.map +1 -0
- package/dist/client/hydrate.js +80 -0
- package/dist/client/hydrate.js.map +1 -0
- package/dist/core/bundler.d.ts +7 -0
- package/dist/core/bundler.d.ts.map +1 -0
- package/dist/core/bundler.js +103 -0
- package/dist/core/bundler.js.map +1 -0
- package/dist/core/formatter.d.ts +6 -0
- package/dist/core/formatter.d.ts.map +1 -0
- package/dist/core/formatter.js +74 -0
- package/dist/core/formatter.js.map +1 -0
- package/dist/core/island-client.d.ts +9 -0
- package/dist/core/island-client.d.ts.map +1 -0
- package/dist/core/island-client.js +8 -0
- package/dist/core/island-client.js.map +1 -0
- package/dist/core/island-registry.d.ts +15 -0
- package/dist/core/island-registry.d.ts.map +1 -0
- package/dist/core/island-registry.js +17 -0
- package/dist/core/island-registry.js.map +1 -0
- package/dist/core/island.d.ts +32 -0
- package/dist/core/island.d.ts.map +1 -0
- package/dist/core/island.js +47 -0
- package/dist/core/island.js.map +1 -0
- package/dist/core/loader.d.ts +11 -0
- package/dist/core/loader.d.ts.map +1 -0
- package/dist/core/loader.js +73 -0
- package/dist/core/loader.js.map +1 -0
- package/dist/core/renderer.d.ts +20 -0
- package/dist/core/renderer.d.ts.map +1 -0
- package/dist/core/renderer.js +53 -0
- package/dist/core/renderer.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +104 -0
- package/dist/index.js.map +1 -0
- package/dist/server/dev-server.d.ts +8 -0
- package/dist/server/dev-server.d.ts.map +1 -0
- package/dist/server/dev-server.js +112 -0
- package/dist/server/dev-server.js.map +1 -0
- package/dist/server/engine.d.ts +46 -0
- package/dist/server/engine.d.ts.map +1 -0
- package/dist/server/engine.js +222 -0
- package/dist/server/engine.js.map +1 -0
- package/{src/server/index.ts ā dist/server/index.d.ts} +1 -1
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3 -0
- package/dist/server/index.js.map +1 -0
- package/package.json +4 -1
- package/.react-html/cache/page-fefe905ae5d2.mjs +0 -9
- package/DOCS.md +0 -317
- package/example/public/styles.css +0 -184
- package/example/src/components/Card.tsx +0 -17
- package/example/src/components/Counter.island.tsx +0 -35
- package/example/src/components/Footer.tsx +0 -13
- package/example/src/components/Header.tsx +0 -20
- package/example/src/components/Layout.tsx +0 -39
- package/example/src/components/Tabs.island.tsx +0 -59
- package/example/src/pages/index.tsx +0 -49
- package/example/src/pages/pure.tsx +0 -56
- package/src/cli/docs-content.ts +0 -268
- package/src/cli/index.ts +0 -113
- package/src/cli/tui-docs.ts +0 -214
- package/src/client/hydrate.ts +0 -84
- package/src/core/bundler.ts +0 -122
- package/src/core/formatter.ts +0 -92
- package/src/core/island-client.ts +0 -23
- package/src/core/island-registry.ts +0 -35
- package/src/core/island.tsx +0 -110
- package/src/core/loader.ts +0 -89
- package/src/core/renderer.ts +0 -80
- package/src/index.ts +0 -138
- package/src/server/dev-server.ts +0 -125
- package/src/server/engine.ts +0 -270
- package/tests/engine.test.mjs +0 -288
- package/tsconfig.json +0 -21
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { island } from '../../../src/index.js';
|
|
3
|
-
|
|
4
|
-
export interface TabItem {
|
|
5
|
-
id: string;
|
|
6
|
-
label: string;
|
|
7
|
-
content: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface TabsProps {
|
|
11
|
-
tabs?: TabItem[];
|
|
12
|
-
defaultTab?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const defaultTabs: TabItem[] = [
|
|
16
|
-
{
|
|
17
|
-
id: 'features',
|
|
18
|
-
label: '⨠Features',
|
|
19
|
-
content: 'Write modular React components with standard JSX. Reusable layouts, cards, buttons, with 0 repetitive boilerplate.'
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
id: 'islands',
|
|
23
|
-
label: 'šļø Islands',
|
|
24
|
-
content: 'Only reactive components compile to client-side JavaScript. Everything else is rendered to pure, clean, zero-JS HTML.'
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
id: 'speed',
|
|
28
|
-
label: 'ā” Speed',
|
|
29
|
-
content: 'Ultra-fast builds powered by esbuild. Instant page loads for users because the browser only receives semantic HTML.'
|
|
30
|
-
}
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
function TabsComponent({ tabs = defaultTabs, defaultTab = 'features' }: TabsProps) {
|
|
34
|
-
const [activeTab, setActiveTab] = useState(defaultTab);
|
|
35
|
-
const currentTab = tabs.find((t) => t.id === activeTab) || tabs[0];
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<div className="tabs-container">
|
|
39
|
-
<div className="tabs-header">
|
|
40
|
-
{tabs.map((tab) => (
|
|
41
|
-
<button
|
|
42
|
-
key={tab.id}
|
|
43
|
-
type="button"
|
|
44
|
-
className={`tab-btn ${activeTab === tab.id ? 'active' : ''}`}
|
|
45
|
-
onClick={() => setActiveTab(tab.id)}
|
|
46
|
-
>
|
|
47
|
-
{tab.label}
|
|
48
|
-
</button>
|
|
49
|
-
))}
|
|
50
|
-
</div>
|
|
51
|
-
<div className="tab-content">
|
|
52
|
-
<p>{currentTab.content}</p>
|
|
53
|
-
</div>
|
|
54
|
-
</div>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const Tabs = island(TabsComponent, import.meta.url, 'Tabs');
|
|
59
|
-
export default Tabs;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Layout } from '../components/Layout.js';
|
|
3
|
-
import { Card } from '../components/Card.js';
|
|
4
|
-
import { Counter } from '../components/Counter.island.js';
|
|
5
|
-
import { Tabs } from '../components/Tabs.island.js';
|
|
6
|
-
|
|
7
|
-
export const title = 'react-html Demo - Pure HTML + Reactive Islands';
|
|
8
|
-
export const description = 'Modular HTML with React and selective reactive island compilation';
|
|
9
|
-
|
|
10
|
-
export default function HomePage() {
|
|
11
|
-
return (
|
|
12
|
-
<Layout title={title} description={description} currentPath="/">
|
|
13
|
-
<h1>React to Pure HTML Engine</h1>
|
|
14
|
-
<p className="subtitle">
|
|
15
|
-
Write modular React components for static HTML, and compile only reactive components to minimal JavaScript.
|
|
16
|
-
</p>
|
|
17
|
-
|
|
18
|
-
<div className="grid">
|
|
19
|
-
<Card title="Modular Components" icon="š¦">
|
|
20
|
-
<p>
|
|
21
|
-
Build reusable UI parts like headers, navigation, cards, and footers with React. No repetitive HTML code.
|
|
22
|
-
</p>
|
|
23
|
-
</Card>
|
|
24
|
-
<Card title="Zero-JS by Default" icon="š">
|
|
25
|
-
<p>
|
|
26
|
-
Static components render to 100% pure HTML. No client bundle is generated unless reactive islands are used.
|
|
27
|
-
</p>
|
|
28
|
-
</Card>
|
|
29
|
-
<Card title="Selective Reactivity" icon="šļø">
|
|
30
|
-
<p>
|
|
31
|
-
Interactive components are isolated as islands and bundled into tiny, dedicated client scripts using esbuild.
|
|
32
|
-
</p>
|
|
33
|
-
</Card>
|
|
34
|
-
</div>
|
|
35
|
-
|
|
36
|
-
<h2 style={{ marginBottom: '1rem' }}>Interactive Island Demos</h2>
|
|
37
|
-
<p style={{ color: '#94a3b8', marginBottom: '1.5rem' }}>
|
|
38
|
-
Below are two reactive islands embedded in pure static HTML:
|
|
39
|
-
</p>
|
|
40
|
-
|
|
41
|
-
{/* Reactive Counter Island */}
|
|
42
|
-
<Counter initialCount={10} step={2} />
|
|
43
|
-
|
|
44
|
-
{/* Reactive Tabs Island */}
|
|
45
|
-
<Tabs defaultTab="islands" />
|
|
46
|
-
</Layout>
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Layout } from '../components/Layout.js';
|
|
3
|
-
import { Card } from '../components/Card.js';
|
|
4
|
-
|
|
5
|
-
export const title = '100% Pure HTML - react-html';
|
|
6
|
-
export const description = 'Demonstration of zero JavaScript pure HTML output';
|
|
7
|
-
|
|
8
|
-
export default function PurePage() {
|
|
9
|
-
const features = [
|
|
10
|
-
{
|
|
11
|
-
title: 'Zero Runtime JS',
|
|
12
|
-
icon: 'š”ļø',
|
|
13
|
-
desc: 'This entire page is compiled to semantic HTML. There are no <script> tags, no React runtime, and no client-side JavaScript sent over the wire.'
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
title: 'Modular & DRY',
|
|
17
|
-
icon: 'š§©',
|
|
18
|
-
desc: 'Built using React components like <Layout />, <Header />, <Card />, and <Footer />. No copy-pasting HTML boilerplate!'
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
title: 'Fast TTFB & Paint',
|
|
22
|
-
icon: 'ā”',
|
|
23
|
-
desc: 'Browsers parse pure HTML almost instantly. Perfect for documentation, blogs, landing pages, and marketing sites.'
|
|
24
|
-
}
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<Layout title={title} description={description} currentPath="/pure">
|
|
29
|
-
<h1>Pure Static HTML</h1>
|
|
30
|
-
<p className="subtitle">
|
|
31
|
-
Compiled from React JSX with <strong>0 KB client JavaScript</strong>.
|
|
32
|
-
</p>
|
|
33
|
-
|
|
34
|
-
<div className="grid">
|
|
35
|
-
{features.map((item, idx) => (
|
|
36
|
-
<Card key={idx} title={item.title} icon={item.icon}>
|
|
37
|
-
<p>{item.desc}</p>
|
|
38
|
-
</Card>
|
|
39
|
-
))}
|
|
40
|
-
</div>
|
|
41
|
-
|
|
42
|
-
<div className="card">
|
|
43
|
-
<h3>Inspect the Source Code</h3>
|
|
44
|
-
<p>
|
|
45
|
-
Right-click and select "View Page Source". You will notice:
|
|
46
|
-
</p>
|
|
47
|
-
<ul style={{ paddingLeft: '1.5rem', marginTop: '0.75rem', color: '#94a3b8' }}>
|
|
48
|
-
<li>Clean, indented, semantic HTML5 markup.</li>
|
|
49
|
-
<li>No <code>data-reactroot</code> or React internal comments.</li>
|
|
50
|
-
<li>Zero <code><script></code> tags.</li>
|
|
51
|
-
</ul>
|
|
52
|
-
</div>
|
|
53
|
-
</Layout>
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
package/src/cli/docs-content.ts
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
export interface DocSection {
|
|
2
|
-
id: string;
|
|
3
|
-
title: string;
|
|
4
|
-
summary: string;
|
|
5
|
-
content: string[];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const DOC_SECTIONS: DocSection[] = [
|
|
9
|
-
{
|
|
10
|
-
id: 'intro',
|
|
11
|
-
title: '1. Overview & Philosophy',
|
|
12
|
-
summary: 'Core concepts: pure HTML output, zero-JS by default, and modular JSX.',
|
|
13
|
-
content: [
|
|
14
|
-
'# 1. Overview & Philosophy',
|
|
15
|
-
'',
|
|
16
|
-
'react-html bridges the gap between modern component-based developer experience',
|
|
17
|
-
'and lightweight, blazing-fast static websites.',
|
|
18
|
-
'',
|
|
19
|
-
'* ZERO JAVASCRIPT BY DEFAULT:',
|
|
20
|
-
' Standard components (layouts, navigation, typography, cards, footers) render into',
|
|
21
|
-
' 100% clean, semantic HTML5. No React runtime, no data-reactroot attributes,',
|
|
22
|
-
' and 0 KB JavaScript sent to the browser.',
|
|
23
|
-
'',
|
|
24
|
-
'* MODULAR & DRY (DON\'T REPEAT YOURSELF):',
|
|
25
|
-
' Eliminate copy-pasting HTML boilerplate. Compose pages with reusable React',
|
|
26
|
-
' components (<Layout>, <Header>, <Card>, <Footer>) with typed props.',
|
|
27
|
-
'',
|
|
28
|
-
'* SELECTIVE REACTIVITY (ISLANDS ARCHITECTURE):',
|
|
29
|
-
' Only components that explicitly require client-side interactivity are bundled',
|
|
30
|
-
' into isolated, tiny JavaScript files. Everything around them remains pure HTML.'
|
|
31
|
-
]
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
id: 'quickstart',
|
|
35
|
-
title: '2. Getting Started & Setup',
|
|
36
|
-
summary: 'Installation, Node.js environment, and initial directory structure.',
|
|
37
|
-
content: [
|
|
38
|
-
'# 2. Getting Started & Setup',
|
|
39
|
-
'',
|
|
40
|
-
'* PREREQUISITES:',
|
|
41
|
-
' - Node.js v20.0.0 or higher (runs natively on standard Node.js & npm)',
|
|
42
|
-
'',
|
|
43
|
-
'* INSTALLATION:',
|
|
44
|
-
' $ npm install react-html',
|
|
45
|
-
'',
|
|
46
|
-
'* RECOMMENDED PROJECT STRUCTURE:',
|
|
47
|
-
' my-project/',
|
|
48
|
-
' āāā package.json',
|
|
49
|
-
' āāā public/ # Static assets (CSS, images, icons)',
|
|
50
|
-
' ā āāā styles.css',
|
|
51
|
-
' āāā src/',
|
|
52
|
-
' āāā components/ # Reusable UI components',
|
|
53
|
-
' ā āāā Layout.tsx # Master HTML shell',
|
|
54
|
-
' ā āāā Header.tsx # Navigation bar',
|
|
55
|
-
' ā āāā Counter.island.tsx # Interactive island component',
|
|
56
|
-
' āāā pages/ # Multi-page entries',
|
|
57
|
-
' āāā index.tsx # -> dist/index.html',
|
|
58
|
-
' āāā about.tsx # -> dist/about.html',
|
|
59
|
-
' āāā blog/',
|
|
60
|
-
' āāā first.tsx # -> dist/blog/first.html'
|
|
61
|
-
]
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
id: 'modular-html',
|
|
65
|
-
title: '3. Modular HTML with React',
|
|
66
|
-
summary: 'Creating reusable layouts, header partials, and nested components.',
|
|
67
|
-
content: [
|
|
68
|
-
'# 3. Modular HTML with React',
|
|
69
|
-
'',
|
|
70
|
-
'Stop repeating HTML boilerplate. Create a single Layout component:',
|
|
71
|
-
'',
|
|
72
|
-
'// src/components/Layout.tsx',
|
|
73
|
-
'import React, { ReactNode } from "react";',
|
|
74
|
-
'import { Header } from "./Header.js";',
|
|
75
|
-
'import { Footer } from "./Footer.js";',
|
|
76
|
-
'',
|
|
77
|
-
'export function Layout({ title, children }: { title: string; children: ReactNode }) {',
|
|
78
|
-
' return (',
|
|
79
|
-
' <html lang="en">',
|
|
80
|
-
' <head>',
|
|
81
|
-
' <meta charSet="UTF-8" />',
|
|
82
|
-
' <meta name="viewport" content="width=device-width, initial-scale=1.0" />',
|
|
83
|
-
' <title>{title}</title>',
|
|
84
|
-
' <link rel="stylesheet" href="/styles.css" />',
|
|
85
|
-
' </head>',
|
|
86
|
-
' <body>',
|
|
87
|
-
' <Header />',
|
|
88
|
-
' <main>{children}</main>',
|
|
89
|
-
' <Footer />',
|
|
90
|
-
' </body>',
|
|
91
|
-
' </html>',
|
|
92
|
-
' );',
|
|
93
|
-
'}',
|
|
94
|
-
'',
|
|
95
|
-
'Every page simply wraps its content in <Layout>: no copy-pasting required!'
|
|
96
|
-
]
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
id: 'islands',
|
|
100
|
-
title: '4. Reactive Islands Architecture',
|
|
101
|
-
summary: 'Compiling interactive React components to tiny client-side JavaScript.',
|
|
102
|
-
content: [
|
|
103
|
-
'# 4. Reactive Islands Architecture',
|
|
104
|
-
'',
|
|
105
|
-
'When you need client-side state (useState, useEffect, event listeners):',
|
|
106
|
-
'',
|
|
107
|
-
'1. Create the component and wrap it using island():',
|
|
108
|
-
'// src/components/Counter.island.tsx',
|
|
109
|
-
'import React, { useState } from "react";',
|
|
110
|
-
'import { island } from "react-html";',
|
|
111
|
-
'',
|
|
112
|
-
'function CounterComponent({ initial = 0 }) {',
|
|
113
|
-
' const [count, setCount] = useState(initial);',
|
|
114
|
-
' return (',
|
|
115
|
-
' <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>',
|
|
116
|
-
' );',
|
|
117
|
-
'}',
|
|
118
|
-
'',
|
|
119
|
-
'export const Counter = island(CounterComponent, import.meta.url, "Counter");',
|
|
120
|
-
'export default Counter;',
|
|
121
|
-
'',
|
|
122
|
-
'2. Use it in any page just like a normal React component:',
|
|
123
|
-
'// src/pages/index.tsx',
|
|
124
|
-
'<Counter initial={10} />',
|
|
125
|
-
'',
|
|
126
|
-
'* HOW THE ENGINE COMPILES IT:',
|
|
127
|
-
' - Initial HTML is pre-rendered for instant paint and SEO.',
|
|
128
|
-
' - esbuild bundles ONLY CounterComponent into dist/assets/islands/Counter.js.',
|
|
129
|
-
' - Only pages containing <Counter> will have the <script> tag injected.'
|
|
130
|
-
]
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
id: 'directives',
|
|
134
|
-
title: '5. Hydration Directives (Performance)',
|
|
135
|
-
summary: 'Controlling client hydration timing with load, idle, and visible.',
|
|
136
|
-
content: [
|
|
137
|
-
'# 5. Hydration Directives (Performance)',
|
|
138
|
-
'',
|
|
139
|
-
'Control when JavaScript executes on the user\'s device with the `client` prop:',
|
|
140
|
-
'',
|
|
141
|
-
'* client="load" (Default):',
|
|
142
|
-
' <Counter client="load" />',
|
|
143
|
-
' Hydrates as soon as DOMContentLoaded fires. Use for critical UI above the fold.',
|
|
144
|
-
'',
|
|
145
|
-
'* client="idle":',
|
|
146
|
-
' <Counter client="idle" />',
|
|
147
|
-
' Hydrates during browser idle time via requestIdleCallback. Perfect for widgets',
|
|
148
|
-
' or floating elements that do not block immediate interaction.',
|
|
149
|
-
'',
|
|
150
|
-
'* client="visible":',
|
|
151
|
-
' <Counter client="visible" />',
|
|
152
|
-
' Hydrates only when scrolled into the viewport using IntersectionObserver.',
|
|
153
|
-
' Ideal for carousels, comment sections, or widgets further down the page.'
|
|
154
|
-
]
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
id: 'cli',
|
|
158
|
-
title: '6. CLI Commands & Options',
|
|
159
|
-
summary: 'Full guide for build, dev, and docs commands.',
|
|
160
|
-
content: [
|
|
161
|
-
'# 6. CLI Commands & Options',
|
|
162
|
-
'',
|
|
163
|
-
'* BUILD PRODUCTION STATIC SITE:',
|
|
164
|
-
' $ react-html build [options]',
|
|
165
|
-
' Flags:',
|
|
166
|
-
' --pages <dir> Directory containing pages (default: src/pages or pages)',
|
|
167
|
-
' --out <dir> Output directory (default: dist)',
|
|
168
|
-
' --root <dir> Root directory of the project (default: cwd)',
|
|
169
|
-
' --no-minify Disable JS minification for debugging',
|
|
170
|
-
'',
|
|
171
|
-
'* START DEV SERVER (LIVE PREVIEW & WATCH):',
|
|
172
|
-
' $ react-html dev [options]',
|
|
173
|
-
' Flags:',
|
|
174
|
-
' --port <number> Port to listen on (default: 3000)',
|
|
175
|
-
' --host <string> Host to bind to (default: localhost)',
|
|
176
|
-
'',
|
|
177
|
-
'* TERMINAL UI DOCUMENTATION (TUI):',
|
|
178
|
-
' $ react-html docs # Interactive TUI navigator',
|
|
179
|
-
' $ react-html docs --all # Print entire manual to stdout',
|
|
180
|
-
' $ react-html docs <section-id> # Print specific section'
|
|
181
|
-
]
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
id: 'api',
|
|
185
|
-
title: '7. Programmatic API Reference',
|
|
186
|
-
summary: 'Using build(), renderPageToHtml(), and createDevServer() in Node.js.',
|
|
187
|
-
content: [
|
|
188
|
-
'# 7. Programmatic API Reference',
|
|
189
|
-
'',
|
|
190
|
-
'import { build, renderPageToHtml, island, Island } from "react-html";',
|
|
191
|
-
'',
|
|
192
|
-
'* build(config):',
|
|
193
|
-
' const result = await build({',
|
|
194
|
-
' root: process.cwd(),',
|
|
195
|
-
' pagesDir: "src/pages",',
|
|
196
|
-
' outDir: "dist",',
|
|
197
|
-
' minify: true',
|
|
198
|
-
' });',
|
|
199
|
-
' // Returns: { pages: [...], islands: [...], outDir: string }',
|
|
200
|
-
'',
|
|
201
|
-
'* renderPageToHtml({ pagePath, Component, props, metadata }):',
|
|
202
|
-
' const { html, islands } = renderPageToHtml({',
|
|
203
|
-
' pagePath: "/path/to/page.tsx",',
|
|
204
|
-
' Component: MyPage,',
|
|
205
|
-
' metadata: { title: "Custom Title" }',
|
|
206
|
-
' });',
|
|
207
|
-
' // Returns pure HTML string and list of detected islands.'
|
|
208
|
-
]
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
id: 'server',
|
|
212
|
-
title: '8. Server App Integration (Express, Fastify, Node HTTP)',
|
|
213
|
-
summary: 'Using createEngine() for production static hosting and development live rebuilds.',
|
|
214
|
-
content: [
|
|
215
|
-
'# 8. Server App Integration (Express, Fastify, Node HTTP)',
|
|
216
|
-
'',
|
|
217
|
-
'You can import and use react-html directly inside your backend server application:',
|
|
218
|
-
'',
|
|
219
|
-
'import express from "express";',
|
|
220
|
-
'import { createEngine } from "react-html";',
|
|
221
|
-
'// or: import { createEngine } from "react-html/server";',
|
|
222
|
-
'',
|
|
223
|
-
'const app = express();',
|
|
224
|
-
'const engine = createEngine({',
|
|
225
|
-
' pagesDir: "src/pages",',
|
|
226
|
-
' distDir: "dist",',
|
|
227
|
-
' // Automatically checks process.env.NODE_ENV === "production"',
|
|
228
|
-
'});',
|
|
229
|
-
'',
|
|
230
|
-
'* 1. CONNECT / EXPRESS MIDDLEWARE:',
|
|
231
|
-
' app.use(engine.middleware);',
|
|
232
|
-
' // In production: finds and streams pre-built static HTML from dist/.',
|
|
233
|
-
' // In development: dynamically rebuilds TSX on the fly and returns fresh HTML.',
|
|
234
|
-
'',
|
|
235
|
-
'* 2. PROGRAMMATIC ROUTE RENDERING:',
|
|
236
|
-
' app.get("/custom", async (req, res) => {',
|
|
237
|
-
' const html = await engine.render("index", { user: req.user });',
|
|
238
|
-
' res.setHeader("Content-Type", "text/html; charset=utf-8");',
|
|
239
|
-
' res.send(html);',
|
|
240
|
-
' });',
|
|
241
|
-
'',
|
|
242
|
-
'* 3. NATIVE NODE HTTP SERVER:',
|
|
243
|
-
' import http from "node:http";',
|
|
244
|
-
' const server = http.createServer(engine.handle);',
|
|
245
|
-
' server.listen(3000);'
|
|
246
|
-
]
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
id: 'troubleshooting',
|
|
250
|
-
title: '9. Best Practices & Troubleshooting',
|
|
251
|
-
summary: 'Avoiding hydration mismatch, React error #418, and styling rules.',
|
|
252
|
-
content: [
|
|
253
|
-
'# 8. Best Practices & Troubleshooting',
|
|
254
|
-
'',
|
|
255
|
-
'* PREVENTING HYDRATION MISMATCH (React Error #418):',
|
|
256
|
-
' - Ensure server and initial client props match.',
|
|
257
|
-
' - Do not use client-only objects (window.innerWidth, localStorage) in initial render.',
|
|
258
|
-
' Instead, read them inside useEffect() or an event handler.',
|
|
259
|
-
' - react-html automatically protects island markup during formatting and uses',
|
|
260
|
-
' renderToString for interactive inner trees to guarantee matching text nodes.',
|
|
261
|
-
'',
|
|
262
|
-
'* ISOLATE STATEFUL LOGIC:',
|
|
263
|
-
' Keep non-interactive parts (headers, card shells, footers) pure React components.',
|
|
264
|
-
' Only place state hooks (useState, useReducer) inside *.island.tsx files.'
|
|
265
|
-
]
|
|
266
|
-
}
|
|
267
|
-
];
|
|
268
|
-
|
package/src/cli/index.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { build } from '../index.js';
|
|
3
|
-
import { createDevServer } from '../server/dev-server.js';
|
|
4
|
-
import { launchDocsTui } from './tui-docs.js';
|
|
5
|
-
|
|
6
|
-
export async function runCli(args: string[] = process.argv.slice(2)): Promise<void> {
|
|
7
|
-
const command = args[0] || 'help';
|
|
8
|
-
|
|
9
|
-
function getArgValue(flag: string): string | undefined {
|
|
10
|
-
const idx = args.indexOf(flag);
|
|
11
|
-
return idx !== -1 && args[idx + 1] ? args[idx + 1] : undefined;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const hasFlag = (flag: string) => args.includes(flag);
|
|
15
|
-
|
|
16
|
-
if (hasFlag('--help') || hasFlag('-h') || command === 'help') {
|
|
17
|
-
console.log(`
|
|
18
|
-
react-html - Engine to convert React to pure HTML with reactive islands
|
|
19
|
-
|
|
20
|
-
Usage:
|
|
21
|
-
react-html <command> [options]
|
|
22
|
-
|
|
23
|
-
Commands:
|
|
24
|
-
build Compile pages into pure HTML & bundle reactive islands
|
|
25
|
-
dev Start live preview development server with auto-rebuild
|
|
26
|
-
docs Browse interactive documentation in Terminal UI (TUI)
|
|
27
|
-
help Show this help message
|
|
28
|
-
|
|
29
|
-
Options:
|
|
30
|
-
--pages <dir> Pages directory (default: src/pages or pages)
|
|
31
|
-
--out <dir> Output directory (default: dist)
|
|
32
|
-
--port <number> Dev server port (default: 3000)
|
|
33
|
-
--host <string> Dev server host (default: localhost)
|
|
34
|
-
--no-minify Disable minification for island bundles
|
|
35
|
-
--root <path> Project root directory (default: cwd)
|
|
36
|
-
|
|
37
|
-
Docs Options:
|
|
38
|
-
react-html docs Launch interactive Terminal UI
|
|
39
|
-
react-html docs --all Print complete manual to terminal
|
|
40
|
-
react-html docs <section> Print a specific section (e.g. islands, api, cli)
|
|
41
|
-
`);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (hasFlag('--version') || hasFlag('-v')) {
|
|
46
|
-
console.log(`react-html v0.1.0`);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const root = getArgValue('--root') || process.cwd();
|
|
51
|
-
const pagesDir = getArgValue('--pages');
|
|
52
|
-
const outDir = getArgValue('--out') || 'dist';
|
|
53
|
-
const minify = !hasFlag('--no-minify');
|
|
54
|
-
|
|
55
|
-
if (command === 'build') {
|
|
56
|
-
console.log(`\nš [react-html] Building static site...`);
|
|
57
|
-
const startTime = Date.now();
|
|
58
|
-
try {
|
|
59
|
-
const result = await build({
|
|
60
|
-
root,
|
|
61
|
-
pagesDir,
|
|
62
|
-
outDir,
|
|
63
|
-
minify
|
|
64
|
-
});
|
|
65
|
-
console.log(`ā
[react-html] Build successful in ${Date.now() - startTime}ms`);
|
|
66
|
-
console.log(`š Pages compiled (${result.pages.length}):`);
|
|
67
|
-
result.pages.forEach(p => {
|
|
68
|
-
console.log(` - ${path.relative(root, p.output)}`);
|
|
69
|
-
});
|
|
70
|
-
if (result.islands.length > 0) {
|
|
71
|
-
console.log(`šļø Reactive islands bundled (${result.islands.length}):`);
|
|
72
|
-
result.islands.forEach(isl => {
|
|
73
|
-
console.log(` - ${path.relative(root, isl)}`);
|
|
74
|
-
});
|
|
75
|
-
} else {
|
|
76
|
-
console.log(`⨠Pure 100% HTML generated (0 KB JavaScript overhead)`);
|
|
77
|
-
}
|
|
78
|
-
} catch (err: any) {
|
|
79
|
-
console.error(`ā [react-html] Build failed:`, err?.message || err);
|
|
80
|
-
process.exit(1);
|
|
81
|
-
}
|
|
82
|
-
} else if (command === 'dev') {
|
|
83
|
-
const port = parseInt(getArgValue('--port') || '3000', 10);
|
|
84
|
-
const host = getArgValue('--host') || 'localhost';
|
|
85
|
-
try {
|
|
86
|
-
await createDevServer({
|
|
87
|
-
root,
|
|
88
|
-
pagesDir,
|
|
89
|
-
outDir,
|
|
90
|
-
port,
|
|
91
|
-
host
|
|
92
|
-
});
|
|
93
|
-
} catch (err: any) {
|
|
94
|
-
console.error(`ā [react-html] Dev server failed:`, err?.message || err);
|
|
95
|
-
process.exit(1);
|
|
96
|
-
}
|
|
97
|
-
} else if (command === 'docs') {
|
|
98
|
-
try {
|
|
99
|
-
await launchDocsTui(args[1]);
|
|
100
|
-
} catch (err: any) {
|
|
101
|
-
console.error(`ā [react-html] Docs error:`, err?.message || err);
|
|
102
|
-
process.exit(1);
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
console.error(`Unknown command "${command}". Run "react-html --help" for available commands.`);
|
|
106
|
-
process.exit(1);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Direct invocation check
|
|
111
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
112
|
-
runCli();
|
|
113
|
-
}
|