UNPKG

1.99 kBMarkdownView Raw
1# Microsite
2
3`microsite` is a tiny, opinionated static-site generator that outputs extremely minimal clientside code using partial hydration.
4
5**At the moment, this is an experiment more than a production-ready tool.**
6
7> Microsite is output as ESM, so it needs to run in a Node environment which supports it (like node@14)
8> You can add a script such as this to your project:
9> `node --experimental-modules --experimental-specifier-resolution=node node_modules/.bin/microsite build`
10
11## Pages
12
13Microsite uses the file-system to generate your output, meaning each component in `src/pages` outputs a corresponding HTML file.
14
15Page templates are written as `.tsx` files with React.
16
17## Styles
18
19Styles are written using CSS Modules. `src/global.css` is, as you guessed, a global CSS file injected on every page.
20Per-page/per-component styles are also inject on the correct pages. They are modules and must be named `*.module.css`.
21
22## Partial hydration
23
24Rather than shipping your entire site back down to the client in a JS bundle, Microsite makes use of **Partial Hydration** to only ship component which need to by hydrated.
25In order to levearge this, all you need to do is wrap a component with the `withHydrate` HOC from `microsite/hydrate`.
26
27There are a few rules that hydrated components rely on: - They can't accept _rich children_, because it's non-trivial to serialize them. Strings and numbers are fine. - They cannot contain other hydrated components, due to the way partial hydration works. - They should be placed as deep as possible in the tree for maximum efficiency.
28
29## Project structure
30
31Microsite cares about the structure of your project. It should look like this:
32
33```
34project/
35├── src/
36│ ├── global.css
37│ ├── global.ts // shipped entirely to client, if present
38│ ├── pages/ // fs-based routing like Next.js
39│ │ └── index.tsx
40│ └── public/ // copied to dist/
41└── tsconfig.json
42```