@asd14/vblocks 7.0.0 → 7.1.0

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.
@@ -0,0 +1,118 @@
1
+ ---
2
+ name: use-vblocks
3
+ description: |
4
+ Writes, serves and builds a React app with @asd14/vblocks. Use when the User
5
+ wants to create a React app or build a React page into one HTML file, or when
6
+ the project's package.json has @asd14/vblocks.
7
+ metadata:
8
+ version: "0.1.0"
9
+ ---
10
+
11
+ VBlocks is a zero-config React bundler, like Create React App or Parcel. It
12
+ builds and serves an SPA (single-page application), as a folder or a single HTML
13
+ file. It has no SSR (server-side rendering) or SSG (static site generation), as
14
+ Next.js does.
15
+
16
+ ## Features
17
+
18
+ <!-- sh41: copied from the features at the top of README.md. Update both
19
+ together -->
20
+
21
+ - An app needs only `src/index.tsx` and `src/index.html`
22
+ - VBlocks supports SWC, PostCSS, CSS Modules, MDX, React Refresh and `.env`
23
+ files
24
+ - Several apps can share one `package.json` and `node_modules/`
25
+ - In development, the Agentation toolbar sends UI annotations to an agent
26
+
27
+ ## TL;DR
28
+
29
+ - Scaffold an app, from the template `plain`, `xyflow` or `xyflow-tabs`:\
30
+ `npx @asd14/vblocks init {{path/to/app}} --template {{plain}}`
31
+ - Add VBlocks to an existing project, with `react` and `react-dom` 18 or 19:\
32
+ `npm install --save-dev @asd14/vblocks`
33
+ - Start the development server, at `http://localhost:8080` or the next free
34
+ port. It opens the browser:\
35
+ `npx vblocks serve`
36
+ - Start it on a port, without the browser. Webpack takes each option after
37
+ `--`:\
38
+ `npx vblocks serve -- --port {{8099}} --no-open`
39
+ - Start the server of one app, in a project folder that contains several:\
40
+ `npx vblocks serve --prefix {{path/to/app}}`
41
+ - Build the production bundle into `dist/`:\
42
+ `npx vblocks build`
43
+ - Build one standalone `dist/index.html`, every asset inlined:\
44
+ `npx vblocks build --single-file`
45
+ - Typecheck. SWC strips the types without checking them:\
46
+ `npx tsc`
47
+ - Import from the app's `src/` through `@self`, a path alias, not a package:\
48
+ `import { {{Button}} } from "@self/{{components/button.tsx}}"`
49
+ - Read a variable of the `.env` in the app folder:\
50
+ `process.env["{{NAME}}"]`
51
+ - Import a file as text:\
52
+ `import {{text}} from "{{./note.txt}}?raw"`
53
+ - Import a Markdown or MDX file as a component:\
54
+ `import {{Intro}} from "{{./intro.mdx}}"`
55
+
56
+ ## Conventions
57
+
58
+ - Write no Webpack, PostCSS or SWC config. The defaults cover a React app
59
+ - For an advanced use, eg. a micro-frontend, eject the default with
60
+ `vblocks eject` and edit the copy
61
+ - Put each concern that `src/index.tsx` imports in its own
62
+ `src/index.<concern>.tsx`, eg. `index.app.tsx` defines `App`
63
+
64
+ ## Index
65
+
66
+ <!-- sh41: tools/get-skill-index-lines --write recomputes the lines and the
67
+ counts after each edit of the docs -->
68
+
69
+ Paths are relative to the package root: the VBlocks repo, or
70
+ `node_modules/@asd14/vblocks/` in the project folder.
71
+
72
+ **`README.md`**, 492 lines:
73
+
74
+ - "## Quick Start" L:68-116
75
+ - "### Keep several apps in one project" L:120-163
76
+ - "### Use `.env` variables" L:165-189
77
+ - "### Import from `src/` with `@self`" L:191-212
78
+ - "### Use CSS Modules" L:214-239
79
+ - "### Import a file as text" L:241-252
80
+ - "### Write a page in Markdown or MDX" L:254-273
81
+ - "### Pick the browsers" L:275-292
82
+ - "### Replace a default config" L:294-324
83
+ - "### Style with Tailwind" L:326-382
84
+ - "### Send UI annotations to an AI agent" L:384-402
85
+ - "### Open the page from another device" L:404-411
86
+ - "### Build a single HTML file" L:413-424
87
+ - "### Add VBlocks to an existing project" L:426-463
88
+ - "## More docs" L:465-472
89
+ - "## Develop" L:474-488
90
+
91
+ **`docs/REFERENCE.md`**, 321 lines:
92
+
93
+ - "## Domain Vocabulary" L:19-27
94
+ - "### `vblocks`" L:31-67
95
+ - "### `vblocks init`" L:69-121
96
+ - "### `vblocks serve`" L:123-181
97
+ - "### `vblocks build`" L:183-256
98
+ - "### `vblocks eject`" L:258-296
99
+ - "## Templates" L:298-313
100
+ - "## Environment variables" L:315-321
101
+
102
+ **`template/`**:
103
+
104
+ - **`_common/README.md`**, 49 lines:
105
+ - "## Plumbing" L:9-25
106
+ - "## App" L:27-49
107
+ - **`plain/README.md`**, 19 lines
108
+ - **`xyflow/README.md`**, 28 lines
109
+ - **`xyflow-tabs/README.md`**, 33 lines
110
+
111
+ **`docs/decisions/`**:
112
+
113
+ - `01.resolve-dependency-vblocks-folder.md`, 43 lines
114
+ - `02.read-browserslist-config.md`, 36 lines
115
+
116
+ **`types/`**:
117
+
118
+ - `client.d.ts`, 137 lines
package/README.md CHANGED
@@ -3,32 +3,42 @@
3
3
 
4
4
  # @asd14/vblocks
5
5
 
6
- > Zero-config React builds, as a static site or a single HTML file
6
+ > Zero-config React builds of an SPA (single-page application), as a folder or a
7
+ > single HTML file
7
8
 
8
- **✂️ Zero config**\
9
- Needs only `src/index.tsx` and `src/index.html`
9
+ VBlocks is a zero-config React bundler, like Create React App or Parcel. It has
10
+ no SSR (server-side rendering) or SSG (static site generation), as Next.js does.
11
+
12
+ **✂️ Zero config**
13
+
14
+ - Needs only `src/index.tsx` and `src/index.html`
10
15
 
11
16
  <!--
12
17
  Using "Maximal support" to pair with "Zero config" above: nothing to set up, and
13
18
  everything set up.
14
19
  -->
15
20
 
16
- **🔋 Maximal support**\
17
- SWC, PostCSS, CSS Modules, MDX, React Refresh, `.env` files
21
+ **🔋 Maximal support**
22
+
23
+ - SWC, PostCSS, CSS Modules, MDX, React Refresh, `.env` files
24
+
25
+ **📦 Several apps, one install**
18
26
 
19
- **📦 Several apps, one install**\
20
- Apps share one `package.json` and `node_modules/`. A new app reuses the
21
- installed packages
27
+ - Apps share one `package.json` and `node_modules/`. A new app reuses the
28
+ installed packages
22
29
 
23
- **🤖 Optimized for AI agents**\
24
- The agent's context contains only the app. The agent does not write, read or fix
25
- a Webpack, PostCSS or SWC config
30
+ **🤖 Built for AI agents**
26
31
 
27
- - [Agentation](https://www.agentation.com) in development: click an element and
28
- write what to change. The agent gets the annotation with the element's
32
+ - **[`use-vblocks`](.sh41/skills/use-vblocks/SKILL.md) skill**: teaches an agent
33
+ to write, serve and build a VBlocks app
34
+ - **[Agentation](https://www.agentation.com) in development**: click an element
35
+ and write what to change. The agent gets the annotation with the element's
29
36
  selector, text and React components
30
- - A terminal gets color and a header. An agent reads through a pipe, and gets
31
- only the facts
37
+ - **Small context**:
38
+ - By default, the agent does not write, read or fix a Webpack, PostCSS or SWC
39
+ config
40
+ - VBlocks shows you color, icons and a header in a terminal. When an agent
41
+ runs VBlocks, it gets the same facts without them
32
42
 
33
43
  ## Table of contents
34
44
 
@@ -41,6 +51,7 @@ a Webpack, PostCSS or SWC config
41
51
  - [Import from `src/` with `@self`](#import-from-src-with-self)
42
52
  - [Use CSS Modules](#use-css-modules)
43
53
  - [Import a file as text](#import-a-file-as-text)
54
+ - [Write a page in Markdown or MDX](#write-a-page-in-markdown-or-mdx)
44
55
  - [Pick the browsers](#pick-the-browsers)
45
56
  - [Replace a default config](#replace-a-default-config)
46
57
  - [Style with Tailwind](#style-with-tailwind)
@@ -240,6 +251,27 @@ import greeting from "./greeting.txt?raw"
240
251
  > The [client types](types/client.d.ts) declare each `?raw` import as a
241
252
  > `string`.
242
253
 
254
+ ### Write a page in Markdown or MDX
255
+
256
+ Import an `.md` or `.mdx` file as a React component:
257
+
258
+ ```tsx
259
+ import Intro from "./intro.mdx"
260
+
261
+ const App = () => <Intro />
262
+ ```
263
+
264
+ Pass `components` to replace the element MDX renders for a tag, eg. each `#`
265
+ heading:
266
+
267
+ ```tsx
268
+ <Intro components={{ h1: Title }} />
269
+ ```
270
+
271
+ > [!NOTE]\
272
+ > The [client types](types/client.d.ts) declare each `.md` and `.mdx` import as
273
+ > a React component.
274
+
243
275
  ### Pick the browsers
244
276
 
245
277
  SWC, Webpack and `postcss-preset-env` compile for the browsers of the app's
package/bin/vblocks CHANGED
@@ -3,7 +3,8 @@
3
3
  set -eu
4
4
 
5
5
  # NAME
6
- # vblocks - Zero-config React builds, as a static site or a single HTML file
6
+ # vblocks - Zero-config React builds of an SPA (single-page application), as
7
+ # a folder or a single HTML file
7
8
  #
8
9
  # SYNOPSIS
9
10
  # vblocks <command> [OPTIONS]
@@ -95,6 +95,10 @@ _SCRIPT_DIR=$(dirname "$0")
95
95
  . "$_SCRIPT_DIR/lib/guard.sh"
96
96
  # shellcheck source=lib/help.sh
97
97
  . "$_SCRIPT_DIR/lib/help.sh"
98
+ # shellcheck source=lib/os.sh
99
+ . "$_SCRIPT_DIR/lib/os.sh"
100
+ # shellcheck source=lib/terminal.sh
101
+ . "$_SCRIPT_DIR/lib/terminal.sh"
98
102
  # shellcheck source=vblocks.sh
99
103
  . "$_SCRIPT_DIR/vblocks.sh"
100
104
  # shellcheck source=webpack.sh
@@ -211,6 +215,7 @@ fi
211
215
  _FAVICON_FILE=$(_pick_file "$_APP_DIR" src/public/favicon.svg)
212
216
  _pick_browserslist "$_APP_DIR"
213
217
  _BROWSERSLIST_SOURCE=$(_find_browserslist "$_APP_DIR")
218
+ _set_command_title build "$(basename -- "$_APP_DIR")"
214
219
 
215
220
  _ARTIFACT="SPA bundle"
216
221
  if [ -n "$_IS_SINGLE_FILE" ]; then
@@ -43,6 +43,10 @@ _SCRIPT_DIR=$(dirname "$0")
43
43
  . "$_SCRIPT_DIR/lib/log.sh"
44
44
  # shellcheck source=lib/help.sh
45
45
  . "$_SCRIPT_DIR/lib/help.sh"
46
+ # shellcheck source=lib/os.sh
47
+ . "$_SCRIPT_DIR/lib/os.sh"
48
+ # shellcheck source=lib/terminal.sh
49
+ . "$_SCRIPT_DIR/lib/terminal.sh"
46
50
  # shellcheck source=vblocks.sh
47
51
  . "$_SCRIPT_DIR/vblocks.sh"
48
52
 
@@ -74,5 +78,7 @@ esac
74
78
  # │ Main
75
79
  # ╰───
76
80
 
81
+ _set_command_title eject "$1"
82
+
77
83
  cat -- "$_VB_DIR/defaults/$_EJECT_CONFIG"
78
84
  exit 0
@@ -70,6 +70,10 @@ _SCRIPT_DIR=$(dirname "$0")
70
70
  . "$_SCRIPT_DIR/lib/guard.sh"
71
71
  # shellcheck source=lib/help.sh
72
72
  . "$_SCRIPT_DIR/lib/help.sh"
73
+ # shellcheck source=lib/os.sh
74
+ . "$_SCRIPT_DIR/lib/os.sh"
75
+ # shellcheck source=lib/terminal.sh
76
+ . "$_SCRIPT_DIR/lib/terminal.sh"
73
77
  # shellcheck source=vblocks.sh
74
78
  . "$_SCRIPT_DIR/vblocks.sh"
75
79
 
@@ -346,6 +350,7 @@ if [ "$_PARTS" = "app" ]; then
346
350
  _PROJECT_DIR=$(cd -- "$_PARENT_DIR" && pwd)
347
351
  fi
348
352
 
353
+ _set_command_title init "$(basename -- "$_INIT_DIR")"
349
354
  mkdir -p -- "$_INIT_DIR" || _fail 3 -v folder "$_INIT_DIR" "Could not create the folder"
350
355
  _INIT_ABS_DIR=$(cd -- "$_INIT_DIR" && pwd)
351
356
  _PROJECT_DIR=${_PROJECT_DIR:-$_INIT_ABS_DIR}
@@ -0,0 +1,188 @@
1
+ #!/bin/sh
2
+
3
+ # NAME
4
+ # os.sh - Run functions on exit, create a temporary folder and delete it on
5
+ # exit, find OS folders
6
+ #
7
+ # SYNOPSIS
8
+ # . "$_SCRIPT_DIR/../lib/os.sh"
9
+ #
10
+ # DESCRIPTION
11
+ # Needs log.sh. A script sources it before this file.
12
+
13
+ # _run_if_found <cmd> [arg...]
14
+ #
15
+ # Run <cmd> with its args when the shell finds it. Do nothing when it does
16
+ # not. Use it for an optional command.
17
+ #
18
+ # RETURNS
19
+ # 0 The shell cannot find <cmd>, or <cmd> exits 0
20
+ # other The status of <cmd>
21
+ _run_if_found() {
22
+ command -v "$1" >/dev/null 2>&1 || return 0
23
+ "$@"
24
+ }
25
+
26
+ # _get_user_dir <NAME> <fallback-dir>
27
+ #
28
+ # Print the XDG user folder <NAME>, eg. PICTURES. Print <fallback-dir> when
29
+ # xdg-user-dir is not installed.
30
+ _get_user_dir() {
31
+ if command -v xdg-user-dir >/dev/null 2>&1; then
32
+ xdg-user-dir "$1"
33
+ else
34
+ printf '%s\n' "$2"
35
+ fi
36
+ }
37
+
38
+ # _get_runtime_dir
39
+ #
40
+ # Print the runtime folder of the current user: XDG_RUNTIME_DIR, else
41
+ # /run/user/<uid>. The system clears it at boot, so nothing in it outlasts a
42
+ # reboot.
43
+ #
44
+ # EXIT
45
+ # 3 XDG_RUNTIME_DIR is unset or empty, and /run/user/<uid> is not a
46
+ # folder
47
+ _get_runtime_dir() {
48
+ if [ -n "${XDG_RUNTIME_DIR:-}" ]; then
49
+ printf '%s\n' "$XDG_RUNTIME_DIR"
50
+ return 0
51
+ fi
52
+
53
+ lib_grd_dir="/run/user/$(id -u)"
54
+ [ -d "$lib_grd_dir" ] \
55
+ || _fail 3 -v dir "$lib_grd_dir" "No runtime folder, XDG_RUNTIME_DIR is not set"
56
+
57
+ printf '%s\n' "$lib_grd_dir"
58
+ }
59
+
60
+ # _resolve_bin_dir
61
+ #
62
+ # Print the first writable bin dir of /usr/local/bin and ~/.local/bin.
63
+ # ~/.local/bin is the user bin dir in the "XDG Base Directory Specification":
64
+ # https://specifications.freedesktop.org/basedir/latest/
65
+ #
66
+ # EXIT
67
+ # 3 Neither /usr/local/bin nor ~/.local/bin is a writable directory
68
+ _resolve_bin_dir() {
69
+ for lib_rbd_dir in /usr/local/bin "${HOME:-}/.local/bin"; do
70
+ [ -d "$lib_rbd_dir" ] && [ -w "$lib_rbd_dir" ] && {
71
+ printf '%s' "$lib_rbd_dir"
72
+ return 0
73
+ }
74
+ done
75
+
76
+ _fail 3 -v current_user "$(whoami)" \
77
+ "No writable bin dir (/usr/local/bin, ~/.local/bin)"
78
+ }
79
+
80
+ # _create_temp_dir <name>
81
+ #
82
+ # Create a folder named after <name> under TMPDIR, eg. /tmp/t212.Ab12Cd, and
83
+ # print its path. Pass the path to _delete_on_exit on the next line: a signal
84
+ # between the two leaves the empty folder behind.
85
+ #
86
+ # EXIT
87
+ # 3 mktemp failed
88
+ _create_temp_dir() {
89
+ mktemp -d "${TMPDIR:-/tmp}/$1.XXXXXX" \
90
+ || _fail 3 "Could not create a temporary folder"
91
+ }
92
+
93
+ _EXIT_FUNCTIONS="" # space-separated, the last registered first
94
+ _DELETE_DIR="" # the folder to delete on exit
95
+
96
+ # _on_exit <function>
97
+ #
98
+ # Register <function> to run when the script exits, or when INT, TERM or HUP
99
+ # ends it. <function> gets the exit code as $1: the code of the script on
100
+ # EXIT, 130 on INT, 143 on TERM, 129 on HUP. The last function registered runs
101
+ # first, and each runs once. A failed one does not stop the rest.
102
+ #
103
+ # _on_exit owns the traps of EXIT, INT, TERM and HUP. Its first call replaces
104
+ # any the script set, and a later `trap` on one of them replaces its own.
105
+ #
106
+ # Call it in the main shell. A subshell, eg. $(...), starts with no traps but
107
+ # keeps _EXIT_FUNCTIONS. If the list is empty, _on_exit sets the traps of the
108
+ # subshell, and the function runs when the subshell exits. If not, it sets no
109
+ # trap, and the function never runs.
110
+ #
111
+ # EXIT
112
+ # 3 <function> is not a defined function
113
+ _on_exit() {
114
+ # command -v prints the name of a function, a builtin or a reserved word, the
115
+ # path of a program, or nothing. A builtin passes, eg. `true`, and does no
116
+ # harm
117
+ [ "$(command -v -- "$1")" = "$1" ] \
118
+ || _fail 3 -v function "$1" "_on_exit takes a defined function"
119
+
120
+ # The traps read _EXIT_FUNCTIONS when they run, so only the first call sets
121
+ # the traps
122
+ if [ -z "$_EXIT_FUNCTIONS" ]; then
123
+ trap '_run_exit_functions $?' EXIT
124
+ trap '_end_by_signal INT 130' INT # Ctrl-C
125
+ trap '_end_by_signal TERM 143' TERM # kill, timeout, cancelled CI job
126
+ trap '_end_by_signal HUP 129' HUP # lost SSH connection, closed window
127
+ fi
128
+
129
+ _EXIT_FUNCTIONS="$1 $_EXIT_FUNCTIONS"
130
+ }
131
+
132
+ # _run_exit_functions <exit-code>
133
+ #
134
+ # Take each function off _EXIT_FUNCTIONS, then run it with <exit-code>. A
135
+ # function that exits during a signal trap makes the shell run the EXIT trap,
136
+ # which runs only the functions left.
137
+ _run_exit_functions() {
138
+ while [ -n "$_EXIT_FUNCTIONS" ]; do
139
+ lib_ref_function=${_EXIT_FUNCTIONS%% *}
140
+ _EXIT_FUNCTIONS=${_EXIT_FUNCTIONS#* }
141
+ "$lib_ref_function" "$1" || true
142
+ done
143
+ }
144
+
145
+ # _end_by_signal <signal> <exit-code>
146
+ #
147
+ # Run the functions _on_exit registered with <exit-code>, then end the script
148
+ # by <signal>, so its caller sees the signal. A trap runs in place of the
149
+ # default action of <signal>, so _end_by_signal clears the traps of EXIT and
150
+ # <signal>, then resends <signal>.
151
+ _end_by_signal() {
152
+ _run_exit_functions "$2"
153
+ trap - EXIT "$1"
154
+ kill -s "$1" $$
155
+ }
156
+
157
+ # _delete_on_exit <dir>
158
+ #
159
+ # Delete the absolute folder <dir> when the script exits, or when INT, TERM or
160
+ # HUP ends it. A function that a later _on_exit call registers runs first.
161
+ #
162
+ # A script calls it once. Create any other temporary folder inside <dir>, eg.
163
+ # `mktemp -d "$_TEMP_DIR/part.XXXXXX"`.
164
+ #
165
+ # EXIT
166
+ # 3 A second call, or a <dir> that is not an absolute path
167
+ _delete_on_exit() {
168
+ [ -z "$_DELETE_DIR" ] \
169
+ || _fail 3 -v dir "$1" "_delete_on_exit takes one folder per script. Create this one inside the first"
170
+
171
+ # The script can cd before it exits, and a relative path then names
172
+ # another folder
173
+ case "$1" in
174
+ /*) ;;
175
+ *) _fail 3 -v dir "$1" "_delete_on_exit takes an absolute path" ;;
176
+ esac
177
+
178
+ _DELETE_DIR=$1
179
+ _on_exit _delete_dir
180
+ }
181
+
182
+ # _delete_dir
183
+ #
184
+ # Delete _DELETE_DIR.
185
+ # shellcheck disable=SC2329 # _delete_on_exit registers it with _on_exit
186
+ _delete_dir() {
187
+ rm -rf -- "$_DELETE_DIR"
188
+ }
@@ -0,0 +1,57 @@
1
+ #!/bin/sh
2
+
3
+ # NAME
4
+ # terminal.sh - Set and restore the title of the terminal, wait for Enter
5
+ #
6
+ # SYNOPSIS
7
+ # . "$_SCRIPT_DIR/../lib/terminal.sh"
8
+ #
9
+ # DESCRIPTION
10
+ # Needs log.sh, os.sh. A script sources them before this file.
11
+
12
+ _HAS_TITLE="" # "true" once _set_title changed the window title
13
+
14
+ # _set_title <title>
15
+ #
16
+ # Name the terminal window, when stderr is a terminal. The escape codes are
17
+ # xterm's and most terminals read them, a flag such as --title differs per
18
+ # terminal. The first code saves the old title, _restore_title restores it.
19
+ _set_title() {
20
+ [ -t 2 ] || return 0
21
+
22
+ printf '\033[22;0t\033]0;%s\007' "$1" >&2
23
+ _HAS_TITLE="true"
24
+ }
25
+
26
+ # _restore_title
27
+ #
28
+ # Restore the title that _set_title saved. The window may be gone, and a
29
+ # failed write must not stop the rest.
30
+ _restore_title() {
31
+ if [ -n "$_HAS_TITLE" ]; then
32
+ printf '\033[23;0t' >&2 2>/dev/null || true
33
+ _HAS_TITLE=""
34
+ fi
35
+ }
36
+
37
+ # _set_title_until_exit <title>
38
+ #
39
+ # Name the terminal window <title> until the script exits, or until INT, TERM
40
+ # or HUP ends it, then restore the old title. It registers _restore_title
41
+ # with _on_exit.
42
+ _set_title_until_exit() {
43
+ _on_exit _restore_title
44
+ _set_title "$1"
45
+ }
46
+
47
+ # _wait_for_enter
48
+ #
49
+ # Stop until the user presses Enter. A window opened only for the calling
50
+ # command closes with it, before the user reads what it shows. Without a
51
+ # terminal on stdin, read takes the next line or finds none, and the wait
52
+ # ends at once.
53
+ _wait_for_enter() {
54
+ printf 'Press Enter to continue ' >&2
55
+ # shellcheck disable=SC2034 # read needs a name, nobody reads it
56
+ read -r lib_wfe_reply || true
57
+ }
@@ -79,6 +79,10 @@ _SCRIPT_DIR=$(dirname "$0")
79
79
  . "$_SCRIPT_DIR/lib/guard.sh"
80
80
  # shellcheck source=lib/help.sh
81
81
  . "$_SCRIPT_DIR/lib/help.sh"
82
+ # shellcheck source=lib/os.sh
83
+ . "$_SCRIPT_DIR/lib/os.sh"
84
+ # shellcheck source=lib/terminal.sh
85
+ . "$_SCRIPT_DIR/lib/terminal.sh"
82
86
  # shellcheck source=vblocks.sh
83
87
  . "$_SCRIPT_DIR/vblocks.sh"
84
88
  # shellcheck source=webpack.sh
@@ -158,6 +162,7 @@ _ROBOTS_FILE=$(_pick_file "$_APP_DIR" src/public/robots.txt)
158
162
  _FAVICON_FILE=$(_pick_file "$_APP_DIR" src/public/favicon.svg)
159
163
  _pick_browserslist "$_APP_DIR"
160
164
  _BROWSERSLIST_SOURCE=$(_find_browserslist "$_APP_DIR")
165
+ _set_command_title serve "$(basename -- "$_APP_DIR")"
161
166
 
162
167
  _print_header "$VB_VERSION" "${_BOLD}serve${_RESET}: $_MODE${_SHOULD_ANALYZE:+, analyze}" >&2
163
168
  _print_summary "$_APP_DIR" "$_WEBPACK_CONFIG" "$_POSTCSS_CONFIG" "$_SWC_CONFIG" \
@@ -1,9 +1,10 @@
1
1
  #!/bin/sh
2
2
 
3
3
  # vblocks.sh - What every command of vblocks shares:
4
- # - the folders, the styles of the output and the header
4
+ # - the folders, the styles of the output, the header and the window title
5
5
  #
6
- # Needs lib/log.sh. The command needs to source it before this file.
6
+ # Needs lib/log.sh. _set_command_title also needs lib/os.sh and
7
+ # lib/terminal.sh. The command sources them before this file.
7
8
 
8
9
  # The caller sets _SCRIPT_DIR to the folder of vblocks.sh, then sources it
9
10
  : "${_SCRIPT_DIR:?the caller sets _SCRIPT_DIR before it sources vblocks.sh}"
@@ -74,6 +75,16 @@ _print_header() {
74
75
  printf '╰──┤\n'
75
76
  }
76
77
 
78
+ # _set_command_title <command> <subject>
79
+ #
80
+ # Set the title of the terminal window to "<command> <subject> :: vblocks", eg.
81
+ # "serve flow :: vblocks", until the command exits. <subject> is what the
82
+ # command works on, eg. the app folder. It comes first, because a tab bar cuts
83
+ # a long title at its end.
84
+ _set_command_title() {
85
+ _set_title_until_exit "$1 $2 :: vblocks"
86
+ }
87
+
77
88
  # ╭───
78
89
  # │ Bootstrap
79
90
  # ╰───
@@ -0,0 +1,4 @@
1
+ # Decisions - @asd14/vblocks
2
+
3
+ - [02. Read the browsers from the browserslist config](decisions/02.read-browserslist-config.md)
4
+ - [01. Resolve each dependency from the VBlocks folder](decisions/01.resolve-dependency-vblocks-folder.md)
@@ -0,0 +1,321 @@
1
+ # Reference - @asd14/vblocks
2
+
3
+ ## Table of contents
4
+
5
+ <!-- vim-markdown-toc GFM -->
6
+
7
+ - [Domain Vocabulary](#domain-vocabulary)
8
+ - [Commands](#commands)
9
+ - [`vblocks`](#vblocks)
10
+ - [`vblocks init`](#vblocks-init)
11
+ - [`vblocks serve`](#vblocks-serve)
12
+ - [`vblocks build`](#vblocks-build)
13
+ - [`vblocks eject`](#vblocks-eject)
14
+ - [Templates](#templates)
15
+ - [Environment variables](#environment-variables)
16
+
17
+ <!-- vim-markdown-toc -->
18
+
19
+ ## Domain Vocabulary
20
+
21
+ | Term | Means |
22
+ | :----------------- | :------------------------------------------------------------------------------------- |
23
+ | **Plumbing** | `package.json` and `.gitignore`, for the project folder |
24
+ | **App** | `src/`, `.env.example`, `tsconfig.json` and the template's configs, for the app folder |
25
+ | **Template** | A named set of files that `init` writes, eg. `plain` |
26
+ | **Project folder** | The folder with `package.json` |
27
+ | **App folder** | The folder with `src/index.tsx` and `src/index.html` |
28
+
29
+ ## Commands
30
+
31
+ ### `vblocks`
32
+
33
+ Zero-config React builds of an SPA (single-page application), as a folder or a
34
+ single HTML file
35
+
36
+ ```text
37
+ vblocks <command> [OPTIONS]
38
+ vblocks -h | --help
39
+ ```
40
+
41
+ <details>
42
+ <summary>Example, inputs, exit codes</summary>
43
+
44
+ ```sh
45
+ npx @asd14/vblocks init my-app
46
+ npx vblocks serve --help
47
+ ```
48
+
49
+ | Name | Description |
50
+ | :------------- | :----------------------------------------------- |
51
+ | `command` | `init`: Write a template into a folder |
52
+ | | `serve`: Start the development server of an app |
53
+ | | `build`: Build an app into `dist/` in its folder |
54
+ | | `eject`: Print a default config of VBlocks |
55
+ | `-h`, `--help` | Print this help |
56
+
57
+ | Exit code | Means |
58
+ | :-------- | :-------------------------------- |
59
+ | `0` | Done |
60
+ | `2` | No command, or an unknown command |
61
+
62
+ - Each command prints its own help with `--help`.
63
+
64
+ See also: [`vblocks init`](#vblocks-init), [`vblocks serve`](#vblocks-serve),
65
+ [`vblocks build`](#vblocks-build), [`vblocks eject`](#vblocks-eject)
66
+
67
+ </details>
68
+
69
+ ### `vblocks init`
70
+
71
+ Write a template into a folder
72
+
73
+ ```text
74
+ vblocks init <folder>
75
+ [--template <name>]
76
+ [--only <app|plumbing>]
77
+ vblocks init --list
78
+ ```
79
+
80
+ <details>
81
+ <summary>Example, inputs, exit codes</summary>
82
+
83
+ ```sh
84
+ npx @asd14/vblocks init my-app
85
+ npx @asd14/vblocks init --list
86
+ npx @asd14/vblocks init demos --only plumbing
87
+ npx @asd14/vblocks init demos/flow --template xyflow --only app
88
+ ```
89
+
90
+ | Name | Default | Description |
91
+ | :------------------ | :------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
92
+ | `folder` | | The folder to write into, missing or empty |
93
+ | `--template <name>` | `plain` | The template, one of the names `--list` prints. See [Templates](#templates) |
94
+ | `--list` | | Print the templates, one per line |
95
+ | `--only <part>` | both | Write only the app or only the plumbing. With app, `init` adds the template's dependencies to the `package.json` of the project folder, the parent of `<folder>`. That `package.json` must exist |
96
+ | `-h`, `--help` | | Print this help |
97
+
98
+ | Exit code | Means |
99
+ | :-------- | :--------------------------------------------------------------------------------------------------------------------------------- |
100
+ | `0` | Done |
101
+ | `2` | Invalid usage, an unknown template, or a `<folder>` that is a file or not empty |
102
+ | `3` | Could not run: a missing tool, no `package.json` in the project folder, a folder `init` could not create, or a failed copy or hook |
103
+
104
+ A template has two parts:
105
+
106
+ | Part | Writes |
107
+ | :--------- | :------------------------------------------------------------------------------------- |
108
+ | `plumbing` | `package.json` and `.gitignore`, for the project folder |
109
+ | `app` | `src/`, `.env.example`, `tsconfig.json` and the template's configs, for the app folder |
110
+
111
+ `init` writes each part into its folder, then runs the part's post-init hooks in
112
+ `<folder>`. `template/<name>/README.md`, in the VBlocks folder, lists the files
113
+ and hooks of each template.
114
+
115
+ Print the project folder, each file `init` creates, updates or deletes, then the
116
+ next step.
117
+
118
+ See also: [`vblocks`](#vblocks), [`vblocks serve`](#vblocks-serve), `node`,
119
+ `npm`
120
+
121
+ </details>
122
+
123
+ ### `vblocks serve`
124
+
125
+ Start the development server of an app
126
+
127
+ ```text
128
+ vblocks serve
129
+ [--mode <development|production>]
130
+ [--prefix <folder>]
131
+ [--analyze]
132
+ [--log-level <error|warn|info|verbose>]
133
+ [-- <webpack option>...]
134
+ ```
135
+
136
+ <details>
137
+ <summary>Example, inputs, exit codes</summary>
138
+
139
+ ```sh
140
+ npx vblocks serve
141
+ npx vblocks serve --prefix flow -- --host 0.0.0.0
142
+ npx vblocks serve -- --port 8099 --no-open
143
+ ```
144
+
145
+ | Name | Default | Description |
146
+ | :----------------------- | :----------------- | :----------------------------------------------------------------------------------------------------------------------- |
147
+ | `--mode <mode>` | `development` | The Webpack mode, `development` or `production` |
148
+ | `--prefix <folder>` | the current folder | The app folder, which must exist |
149
+ | `--analyze` | | Run the bundle analyzer, on a free port. An ejected `webpack.config.js` runs the analyzer only if it reads `env.analyze` |
150
+ | `--log-level <level>` | `warn` | How much Webpack and its development server print: `error`, `warn`, `info` or `verbose` |
151
+ | `-- <webpack option>...` | | Pass each option to Webpack, unchanged |
152
+ | `-h`, `--help` | | Print this help |
153
+
154
+ | Exit code | Means |
155
+ | :-------- | :----------------------------------------------------------------------------------------------- |
156
+ | `0` | Done |
157
+ | `2` | Invalid usage, Webpack rejected an option or the config, or browserslist could not read a config |
158
+ | `3` | Could not run: a missing tool, or a failed Webpack run |
159
+
160
+ The app folder contains `src/index.tsx` and `src/index.html`. A config in it,
161
+ `webpack.config.js`, `postcss.config.js`, `.swcrc` or `.browserslistrc`,
162
+ replaces the VBlocks default of the same name. So do `src/public/robots.txt` and
163
+ `src/public/favicon.svg`.
164
+
165
+ Print the app folder, the VBlocks folder, the files Webpack runs with and the
166
+ source of the browsers, then start the server.
167
+
168
+ SWC, Webpack and `postcss-preset-env` compile for the browsers of the app's
169
+ browserslist config. browserslist reads `BROWSERSLIST`, `BROWSERSLIST_CONFIG`,
170
+ then a `.browserslistrc` or the `browserslist` field of `package.json`, from the
171
+ app folder up. Without any of them, browserslist reads the VBlocks default,
172
+ `defaults/.browserslistrc`.
173
+
174
+ The server runs at `http://localhost:8080`, or the next free port. It opens the
175
+ page in the browser. It listens on `localhost`, so another device cannot open
176
+ the page. Pass `-- --host 0.0.0.0` to expose it to the network.
177
+
178
+ See also: [`vblocks`](#vblocks), [`vblocks build`](#vblocks-build),
179
+ [`vblocks eject`](#vblocks-eject), `webpack`
180
+
181
+ </details>
182
+
183
+ ### `vblocks build`
184
+
185
+ Build an app into `dist/` in its folder
186
+
187
+ ```text
188
+ vblocks build
189
+ [--mode <development|production>]
190
+ [--prefix <folder>]
191
+ [--single-file|--single]
192
+ [--log-level <error|warn|info|verbose>]
193
+ [-- <webpack option>...]
194
+ ```
195
+
196
+ <details>
197
+ <summary>Example, inputs, exit codes</summary>
198
+
199
+ ```sh
200
+ npx vblocks build
201
+ cd demos && npx vblocks build --prefix flow --single-file
202
+ npx vblocks build -- --devtool source-map
203
+ ```
204
+
205
+ | Name | Default | Description |
206
+ | :-------------------------- | :----------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
207
+ | `--mode <mode>` | `production` | The Webpack mode, `development` or `production` |
208
+ | `--prefix <folder>` | the current folder | The app folder, which must exist |
209
+ | `--single-file`, `--single` | | Build one standalone `dist/index.html`, every asset inlined, with no `robots.txt`. A browser opens it from disk. There, `history.pushState` to another path throws, so keep the route in the URL hash. An ejected `webpack.config.js` builds one file only if it reads `env.single` |
210
+ | `--log-level <level>` | `warn` | How much Webpack prints: `error`, `warn`, `info` or `verbose` |
211
+ | `-- <webpack option>...` | | Pass each option to Webpack, unchanged |
212
+ | `-h`, `--help` | | Print this help |
213
+
214
+ | Exit code | Means |
215
+ | :-------- | :----------------------------------------------------------------------------------------------- |
216
+ | `0` | Done |
217
+ | `2` | Invalid usage, Webpack rejected an option or the config, or browserslist could not read a config |
218
+ | `3` | Could not run: a missing tool, or a failed Webpack run |
219
+
220
+ The app folder contains `src/index.tsx` and `src/index.html`. A config in it,
221
+ `webpack.config.js`, `postcss.config.js`, `.swcrc` or `.browserslistrc`,
222
+ replaces the VBlocks default of the same name. So do `src/public/robots.txt` and
223
+ `src/public/favicon.svg`.
224
+
225
+ Print the app folder, the VBlocks folder, the files Webpack runs with and the
226
+ source of the browsers, then build. Print each file in `dist/`, its size and the
227
+ total.
228
+
229
+ SWC, Webpack and `postcss-preset-env` compile for the browsers of the app's
230
+ browserslist config. browserslist reads `BROWSERSLIST`, `BROWSERSLIST_CONFIG`,
231
+ then a `.browserslistrc` or the `browserslist` field of `package.json`, from the
232
+ app folder up. Without any of them, browserslist reads the VBlocks default,
233
+ `defaults/.browserslistrc`.
234
+
235
+ Without `--single-file`, `dist/` contains:
236
+
237
+ ```text
238
+ index.html
239
+ favicon.svg
240
+ robots.txt
241
+ js/main.<hash>.js
242
+ js/react.<hash>.js react and react-dom
243
+ js/vendors.<hash>.js the rest of node_modules
244
+ js/*.LICENSE.txt the license comments of each chunk
245
+ css/main.<hash>.css
246
+ fonts/<name>.<ext> each font
247
+ <hash>.<ext> each image over 10 KiB
248
+ ```
249
+
250
+ Webpack inlines an image up to 10 KiB. It splits `react` and `vendors` out of
251
+ `main`, so the browser keeps them cached across builds.
252
+
253
+ See also: [`vblocks`](#vblocks), [`vblocks serve`](#vblocks-serve),
254
+ [`vblocks eject`](#vblocks-eject), `webpack`
255
+
256
+ </details>
257
+
258
+ ### `vblocks eject`
259
+
260
+ Print a default config of VBlocks
261
+
262
+ ```text
263
+ vblocks eject <config>
264
+ ```
265
+
266
+ <details>
267
+ <summary>Example, inputs, exit codes</summary>
268
+
269
+ ```sh
270
+ npx vblocks eject postcss > postcss.config.js
271
+ ```
272
+
273
+ | Name | Description |
274
+ | :------------- | :------------------------------------------- |
275
+ | `config` | `webpack`: Save it as `webpack.config.js` |
276
+ | | `postcss`: Save it as `postcss.config.js` |
277
+ | | `swc`: Save it as `.swcrc` |
278
+ | | `browserslist`: Save it as `.browserslistrc` |
279
+ | `-h`, `--help` | Print this help |
280
+
281
+ | Exit code | Means |
282
+ | :-------- | :------------ |
283
+ | `0` | Done |
284
+ | `2` | Invalid usage |
285
+
286
+ `eject` prints the config to stdout. Save it in the app folder. `serve` and
287
+ `build` then run with it in place of the VBlocks default.
288
+
289
+ An ejected config loads its plugins and loaders from the project folder, not
290
+ from VBlocks. Install them there. `serve` and `build` still run the
291
+ `webpack-cli`, `webpack` and `webpack-dev-server` of VBlocks.
292
+
293
+ See also: [`vblocks`](#vblocks), [`vblocks serve`](#vblocks-serve),
294
+ [`vblocks build`](#vblocks-build)
295
+
296
+ </details>
297
+
298
+ ## Templates
299
+
300
+ ```sh
301
+ npx @asd14/vblocks init --list
302
+ # => plain
303
+ # => xyflow
304
+ # => xyflow-tabs
305
+ ```
306
+
307
+ Each template starts from [the common files](../template/_common/README.md).
308
+
309
+ | Template | Description |
310
+ | :------------------------------------------------- | :------------------------------------------------------------- |
311
+ | [`plain`](../template/plain/README.md) | A "Hello World!" heading. |
312
+ | [`xyflow`](../template/xyflow/README.md) | One diagram, and a details panel for the selected node or edge |
313
+ | [`xyflow-tabs`](../template/xyflow-tabs/README.md) | One tab per diagram, each with its own details panel |
314
+
315
+ ## Environment variables
316
+
317
+ | Name | Values | Default | Description |
318
+ | :-------------------- | :------------------- | :------ | :----------------------------------------------------------------------------------------------------------------- |
319
+ | `NO_COLOR` | non-empty | | `init`: print without color or the header. `serve`, `build`: print without color, the icons or the header |
320
+ | `BROWSERSLIST` | a browserslist query | | `serve`, `build`: the browsers, as a browserslist query. It overrides every config file |
321
+ | `BROWSERSLIST_CONFIG` | a file path | | `serve`, `build`: the path of a browserslist config, in place of the one browserslist finds from the app folder up |
@@ -0,0 +1,43 @@
1
+ # 01. Resolve each dependency from the VBlocks folder
2
+
3
+ **Date**: 2026-11-11
4
+
5
+ **Independent facts**:
6
+
7
+ - Node resolves a package name from the folder of the file that imports it, then
8
+ from each parent folder
9
+ - npm nests or hoists each dependency a package declares, to reduce module
10
+ duplication, in a way that Node still resolves the right version from the
11
+ package's folder
12
+ - npm does not install an optional peer, one marked in `peerDependenciesMeta`.
13
+ When another package installs it, npm does not place that copy within reach of
14
+ the package that declares the peer
15
+ - Webpack resolves a loader named by a string from the folder the command runs
16
+ in, not from its own folder
17
+
18
+ **Problem**:
19
+
20
+ - `webpack-cli` declares `webpack-dev-server` only as an optional peer
21
+ - In an npm workspace, npm can nest `webpack-dev-server` under VBlocks and hoist
22
+ `webpack-cli` to the root. `vblocks serve` then fails: `webpack-cli` cannot
23
+ resolve `webpack-dev-server`, and asks to install it
24
+ - The loaders of the default Webpack config, eg. `swc-loader`, can fail the same
25
+ way
26
+
27
+ **Solution**:
28
+
29
+ - `vblocks serve` and `vblocks build` resolve `webpack-cli`, `webpack` and
30
+ `webpack-dev-server` from the VBlocks folder, so they run the versions VBlocks
31
+ declares
32
+ - The default Webpack config resolves its loaders, and the packages SWC adds to
33
+ app files, eg. `@swc/helpers`, from the VBlocks folder too
34
+ - VBlocks declares `@swc/core`, to choose the compiler that matches its
35
+ `@swc/helpers`
36
+
37
+ **Acknowledgments**:
38
+
39
+ - `swc-loader` loads `@swc/core` from its own folder, and the React Refresh
40
+ plugin loads `react-refresh` from its own. Neither takes the package as an
41
+ option, so each can load another copy than VBlocks'
42
+ - An ejected `webpack.config.js` resolves from the app folder, which declares
43
+ VBlocks, not the loaders. They resolve only when npm hoists them there
@@ -0,0 +1,36 @@
1
+ # 02. Read the browsers from the browserslist config
2
+
3
+ **Date**: 2026-11-15
4
+
5
+ **Independent facts**:
6
+
7
+ - SWC, Webpack and `postcss-preset-env` read the browsers in the same order: the
8
+ `BROWSERSLIST` variable, the `BROWSERSLIST_CONFIG` file, then the nearest
9
+ `.browserslistrc` or `browserslist` field of `package.json`, from a given
10
+ folder up
11
+ - Without any of them, SWC keeps the syntax as written, Webpack stops with an
12
+ error, and `postcss-preset-env` uses the defaults of browserslist
13
+
14
+ **Problem**:
15
+
16
+ - VBlocks gave SWC and Webpack the query of its default `.swcrc`,
17
+ `> 0.25%, not dead`
18
+ - VBlocks gave `postcss-preset-env` no query, so it compiled the CSS for the
19
+ defaults of browserslist, `> 0.5%, last 2 versions, Firefox ESR, not dead`
20
+ - An app that picked other browsers had to set them in two places: `env.targets`
21
+ of `.swcrc`, and a browserslist config for `postcss-preset-env`
22
+
23
+ **Solution**:
24
+
25
+ - The app's browserslist config sets the browsers of SWC, Webpack and
26
+ `postcss-preset-env`. Each tool reads it from the app folder up
27
+ - Without one, `serve` and `build` give the three tools the VBlocks default,
28
+ `> 0.25%, not dead`. The old default `.swcrc` set the same query
29
+ - `vblocks eject browserslist` prints the default, to copy into the app
30
+
31
+ **Acknowledgments**:
32
+
33
+ - An app's `.swcrc` that sets `env.targets` overrides the browserslist config,
34
+ for SWC only
35
+ - Run outside VBlocks, eg. by `npx webpack`, the three tools get no default
36
+ browserslist config
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@asd14/vblocks",
4
- "version": "7.0.0",
5
- "description": "Zero-config React builds, as a static site or a single HTML file",
4
+ "version": "7.1.0",
5
+ "description": "Zero-config React builds of an SPA (single-page application), as a folder or a single HTML file",
6
6
  "keywords": [
7
7
  "react",
8
8
  "webpack",
@@ -33,8 +33,10 @@
33
33
  "url": "git+https://github.com/asd-xiv/vblocks.git"
34
34
  },
35
35
  "files": [
36
+ ".sh41/skills",
36
37
  "bin",
37
38
  "defaults",
39
+ "docs",
38
40
  "template",
39
41
  "types"
40
42
  ],
@@ -65,7 +67,7 @@
65
67
  "@pmmmwh/react-refresh-webpack-plugin": "^0.6.3",
66
68
  "@swc/core": "^1.16.22",
67
69
  "@swc/helpers": "^0.5.24",
68
- "browserslist": "^4.29.5",
70
+ "browserslist": "^4.29.6",
69
71
  "copy-webpack-plugin": "^14.0.0",
70
72
  "css-loader": "^7.1.5",
71
73
  "cssnano": "^9.9.0",
@@ -74,16 +76,16 @@
74
76
  "mini-css-extract-plugin": "^2.10.2",
75
77
  "postcss": "^8.5.33",
76
78
  "postcss-loader": "^8.2.1",
77
- "postcss-preset-env": "^11.6.2",
79
+ "postcss-preset-env": "^11.6.3",
78
80
  "react-refresh": "^0.19.0",
79
81
  "swc-loader": "^0.2.7",
80
82
  "webpack": "^5.112.2",
81
- "webpack-bundle-analyzer": "^5.4.2",
83
+ "webpack-bundle-analyzer": "^5.4.3",
82
84
  "webpack-cli": "^7.3.1",
83
85
  "webpack-dev-server": "^6.1.0"
84
86
  },
85
87
  "devDependencies": {
86
- "@asd14/eslint-config": "^16.3.0",
88
+ "@asd14/eslint-config": "^17.0.0",
87
89
  "@asd14/prettier-config": "^1.5.0",
88
90
  "@asd14/semantic-release-config": "^1.1.0",
89
91
  "@asd14/ts-config": "^2.0.0",
@@ -11,7 +11,7 @@ The template's hook does not replace the common one.
11
11
  The files of the [project folder](../../docs/REFERENCE.md#domain-vocabulary):
12
12
 
13
13
  ```text
14
- package.json # the scripts, React, TypeScript and the browserslist field
14
+ package.json # the scripts, React and TypeScript
15
15
  _gitignore # node_modules, dist and .env
16
16
  ```
17
17
 
@@ -38,6 +38,9 @@ src/
38
38
  tsconfig.json # extends @asd14/ts-config, maps @self/* to src/*
39
39
  ```
40
40
 
41
+ - Put each concern that `src/index.tsx` imports in its own
42
+ `src/index.<concern>.tsx`, eg. `index.app.tsx` defines `App`
43
+
41
44
  **Hooks**:
42
45
 
43
46
  1. [`post-init-app.sh`](post-init-app.sh) runs in the app folder, after the
package/types/client.d.ts CHANGED
@@ -71,6 +71,25 @@ declare module "*.eot" {
71
71
  export default url
72
72
  }
73
73
 
74
+ /**
75
+ * The Markdown document as a React component. VBlocks compiles `.md` with MDX,
76
+ * so it takes the same `components` as an `.mdx` import.
77
+ *
78
+ * @example
79
+ * import Notes from "./notes.md"
80
+ *
81
+ * <Notes components={{ h1: Title }} />
82
+ */
83
+ declare module "*.md" {
84
+ import type { ComponentType } from "react"
85
+
86
+ const MDXContent: ComponentType<{
87
+ components?: Record<string, ComponentType<Record<string, unknown>>>
88
+ }>
89
+
90
+ export default MDXContent
91
+ }
92
+
74
93
  /**
75
94
  * The MDX document as a React component. `components` replaces the element
76
95
  * MDX renders for a tag, eg. `{ h1: Title }`.