Skip to content

Commit

Permalink
docs: update minimal-api (#1210)
Browse files Browse the repository at this point in the history
#921 

`handleBuild` is very complicated.
  • Loading branch information
dai-shi authored Feb 6, 2025
1 parent b9031fe commit 46a5e1f
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions docs/minimal-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,55 @@ export default defineEntries({
return renderHtml({ App: <App name="Waku" /> }, <Slot id="App" />, '');
}
},
getBuildConfig: async () => [{ pathSpec: [], entries: [{ rscPath: '' }] }],
handleBuild: () => null,
});
```

Tips for experimenting:

- Object keys like `App` are called RSC ID.
- `input.type === 'custom'` condition can be omitted if you don't need SSR.
- `getBuildConfig` can return `[]` if you don't need to build anything.

#### `handleBuild`

The `handleBuild` function is to produce a build for production.
It has to return AsyncIterable of build instructions.

```tsx
handleBuild: ({
renderRsc,
renderHtml,
rscPath2pathname,
unstable_generatePrefetchCode,
}) =>
createAsyncIterable(async () => {
const moduleIds = new Set<string>();
const generateHtmlHead = () =>
`<script type="module" async>${unstable_generatePrefetchCode(
[''],
moduleIds,
)}</script>`;
const tasks = [
async () => ({
type: 'file' as const,
pathname: rscPath2pathname(''),
body: renderRsc(
{ App: <App name="Waku" /> },
{ moduleIdCallback: (id) => moduleIds.add(id) },
),
}),
async () => ({
type: 'file' as const,
pathname: '/',
body: renderHtml({ App: <App name="Waku" /> }, <Slot id="App" />, {
rscPath: '',
htmlHead: generateHtmlHead(),
}).then(({ body }) => body),
}),
];
return tasks;
}),
```

### Client API

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

0 comments on commit 46a5e1f

Please sign in to comment.