|
2 | 2 |
|
3 | 3 | > [http://jacobdoescode.com](http://jacobdoescode.com)
|
4 | 4 |
|
5 |
| -Custom static site builder. Laid out very similar to Jekyll, but uses React heavily under the hood. It has the following advantages: |
| 5 | +Custom static site builder. Like Jekyll, but uses React heavily under the hood. It has the following advantages: |
6 | 6 |
|
7 | 7 | - Assets get tree shaken (for better or worse)
|
8 |
| -- Optimises assets |
| 8 | +- Optimises assets, including automatic conversion of images to WebP |
9 | 9 | - Assets get renamed to their hashes for long-term caching
|
10 |
| -- Can use React components in Markdown |
| 10 | +- MDX-based - sp you can use React components in Markdown |
11 | 11 | - Generally more React-based - no `{% if blocks %}`
|
12 |
| -- No more \_includes hacks |
| 12 | +- No more `_includes` hacks |
13 | 13 | - Granular control of how assets get used - including inlining critical CSS/JS if required
|
14 | 14 |
|
15 |
| -It's not perfect, but it's good enough for this site. Mostly, these are the issues that just need time investment to fix. |
| 15 | +Using and referencing assets requires React components to do the lifting. The elements `<script>`, `<style>`, `<link>`, `<img>`, and `<video>` equivalent React components in `/core` that do asset optimisation. And finally, `<a href>` works as-is for pages, because page names don't get mangled - but won't work for asset links. |
16 | 16 |
|
17 |
| -JS and CSS assets don't have "proper" bundlers - there's only ways to transform urls to point to the correct assets - not embed assets within them. CSS uses the url syntax. JS works out-of-the-box for import declarations and expressions, and needs you to use `require.resolve` for urls not part of import statements or expressions. Given enough time, `@import` in CSS and `import` declarations in JS would bundle the resources, and `url` functions and `import` expressions (or `require.resolve` calls) would map to asset references. |
| 17 | +The main outstanding issue is JS and CSS assets don't have "proper" bundlers - there's only ways to transform urls to point to the correct assets. It works, but it's less efficient than what things like Webpack will achieve. CSS uses the url syntax to do this. JS works out-of-the-box for `import` declarations and expressions, and needs you to use `require.resolve` for urls not part of import statements or expressions. Given enough time, `@import` in CSS and `import` declarations in JS could/would bundle the resources, and `url()` functions in CSS and `import()` expressions in JS (or `require.resolve` calls) would map to asset references. |
18 | 18 |
|
19 |
| -Referencing assets requires React components to do the lifting. The elements `<script>`, `<style>`, `<link>`, `<img>`, and `<video>` equivalent React components that do optimisation. And finally, `<a href>` works as-is for pages, because page names don't get mangled - but won't work for asset links. |
| 19 | +### Optimisations |
20 | 20 |
|
21 |
| -This last point less a time investment, and more a conceptual question. CSS works without any special extensions. JS relies a few special extensions. Markdown is half-and-half extensions via React components and some HTML elements working out the box. Where should these asset references be handled? |
| 21 | +- Images get compressed in their current format, and a WebP image is generated |
| 22 | + - Avif takes too long to generate (for now), so that is skipped |
| 23 | + - Use the `<Image>` component from `/core` |
| 24 | +- CSS class names and variables are minified to 1 or 2 letters in prod |
| 25 | + - You need to use helper functions when referencing classes from JS/MDX |
| 26 | + - JS assets get a set of global variables (`CSS_CLASSES` and `CSS_VARS`) that you'll need to use to reference classes |
| 27 | +- Assets are renamed to a hash of their content - you'll need to use the `useContent` hook to be able to read and write assets |
| 28 | + - This is also important because it's how the watcher works |
22 | 29 |
|
23 |
| -And just to note, |
24 |
| - |
25 |
| -If you wanted to re-use this work, there's zero config for all the optimisations. Every optimisation I wanted to include is always on. Just fork and remove as necessary. |
26 |
| - |
27 |
| -CSS class and variable names are minified via utility functions in `/core/css`. You need to call these functions in your custom React components. JS assets get a set of global variables (`CSS_CLASSES` and `CSS_VARS`) that you'll need to use. |
| 30 | +If you wanted to re-use this work, there's zero options for all the optimisations: every optimisation I wanted to include is always on. Just fork and remove as necessary. |
0 commit comments