Skip to content

Commit 46a5e1f

Browse files
authored
docs: update minimal-api (#1210)
#921 `handleBuild` is very complicated.
1 parent b9031fe commit 46a5e1f

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

docs/minimal-api.mdx

+44-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,55 @@ export default defineEntries({
2323
return renderHtml({ App: <App name="Waku" /> }, <Slot id="App" />, '');
2424
}
2525
},
26-
getBuildConfig: async () => [{ pathSpec: [], entries: [{ rscPath: '' }] }],
26+
handleBuild: () => null,
2727
});
2828
```
2929

3030
Tips for experimenting:
3131

32+
- Object keys like `App` are called RSC ID.
3233
- `input.type === 'custom'` condition can be omitted if you don't need SSR.
33-
- `getBuildConfig` can return `[]` if you don't need to build anything.
34+
35+
#### `handleBuild`
36+
37+
The `handleBuild` function is to produce a build for production.
38+
It has to return AsyncIterable of build instructions.
39+
40+
```tsx
41+
handleBuild: ({
42+
renderRsc,
43+
renderHtml,
44+
rscPath2pathname,
45+
unstable_generatePrefetchCode,
46+
}) =>
47+
createAsyncIterable(async () => {
48+
const moduleIds = new Set<string>();
49+
const generateHtmlHead = () =>
50+
`<script type="module" async>${unstable_generatePrefetchCode(
51+
[''],
52+
moduleIds,
53+
)}</script>`;
54+
const tasks = [
55+
async () => ({
56+
type: 'file' as const,
57+
pathname: rscPath2pathname(''),
58+
body: renderRsc(
59+
{ App: <App name="Waku" /> },
60+
{ moduleIdCallback: (id) => moduleIds.add(id) },
61+
),
62+
}),
63+
async () => ({
64+
type: 'file' as const,
65+
pathname: '/',
66+
body: renderHtml({ App: <App name="Waku" /> }, <Slot id="App" />, {
67+
rscPath: '',
68+
htmlHead: generateHtmlHead(),
69+
}).then(({ body }) => body),
70+
}),
71+
];
72+
return tasks;
73+
}),
74+
```
3475

3576
### Client API
3677

@@ -72,3 +113,4 @@ const Component = () => {
72113
- [../examples/31_minimal](Minimal example)
73114
- [../examples/34_functions](With server functions)
74115
- [../examples/39_api](With custom API endpoints)
116+
- [../examples/51_spa](Fully client components)

0 commit comments

Comments
 (0)