@asd14/vblocks 7.0.0 → 8.0.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.
- package/.sh41/skills/use-vblocks/SKILL.md +120 -0
- package/README.md +104 -20
- package/bin/vblocks +2 -1
- package/bin/vblocks.d/build +5 -0
- package/bin/vblocks.d/eject +6 -0
- package/bin/vblocks.d/init +5 -0
- package/bin/vblocks.d/lib/os.sh +188 -0
- package/bin/vblocks.d/lib/terminal.sh +57 -0
- package/bin/vblocks.d/serve +5 -0
- package/bin/vblocks.d/vblocks.sh +13 -2
- package/defaults/webpack.config.js +13 -1
- package/docs/DECISIONS.md +5 -0
- package/docs/REFERENCE.md +321 -0
- package/docs/decisions/01.resolve-dependency-vblocks-folder.md +43 -0
- package/docs/decisions/02.read-browserslist-config.md +36 -0
- package/docs/decisions/03.pass-code-meta-as-props.md +44 -0
- package/docs/migrations/v8.md +120 -0
- package/package.json +12 -7
- package/template/_common/README.md +4 -1
- package/types/client.d.ts +63 -36
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Decisions - @asd14/vblocks
|
|
2
|
+
|
|
3
|
+
- [03. Pass the meta of a code block as props](decisions/03.pass-code-meta-as-props.md)
|
|
4
|
+
- [02. Read the browsers from the browserslist config](decisions/02.read-browserslist-config.md)
|
|
5
|
+
- [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
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# 03. Pass the meta of a code block as props
|
|
2
|
+
|
|
3
|
+
**Date**: 2026-11-19
|
|
4
|
+
|
|
5
|
+
**Independent facts**:
|
|
6
|
+
|
|
7
|
+
- A fenced code block has a language and a meta, the rest of its opening line,
|
|
8
|
+
eg. `file="src/app.tsx"` in ` ```tsx file="src/app.tsx" `
|
|
9
|
+
- MDX keeps the meta out of the props of the `code` element, so a `code`
|
|
10
|
+
component of `components` never receives it
|
|
11
|
+
- MDX turns a number property of a plain element into a string. It removes a
|
|
12
|
+
`false` property. A JSX element keeps both
|
|
13
|
+
- `rehype-mdx-code-props`:
|
|
14
|
+
- reads the meta as JSX attributes: a string in quotes, any other value in
|
|
15
|
+
`{}`, a flag alone
|
|
16
|
+
- replaces the `code` element with a JSX element, which keeps the type of each
|
|
17
|
+
value
|
|
18
|
+
- `vblocks eject webpack` prints one file
|
|
19
|
+
- An ejected config loads its plugins from the project folder
|
|
20
|
+
|
|
21
|
+
**Problem**:
|
|
22
|
+
|
|
23
|
+
- A page cannot tell its `code` component the file, the highlighted lines or any
|
|
24
|
+
other fact a code block states
|
|
25
|
+
|
|
26
|
+
**Solution**:
|
|
27
|
+
|
|
28
|
+
- `defaults/webpack.config.js` runs `rehype-mdx-code-props` on `code`, so the
|
|
29
|
+
`code` component receives the meta as props
|
|
30
|
+
- The meta is JSX attributes: `file="src/app.tsx" lines={3} showLines`
|
|
31
|
+
|
|
32
|
+
**Rejected**:
|
|
33
|
+
|
|
34
|
+
- A rehype plugin of VBlocks, with its own meta syntax, eg.
|
|
35
|
+
`file=src/app.tsx lines=3`. It needed about 125 lines of MDX internals to keep
|
|
36
|
+
the types of the values, and VBlocks would maintain them
|
|
37
|
+
|
|
38
|
+
**Acknowledgments**:
|
|
39
|
+
|
|
40
|
+
- An ejected config needs `rehype-mdx-code-props` in the project folder
|
|
41
|
+
- `rehype-mdx-code-props` had its last release in June 2024. A later major
|
|
42
|
+
version of MDX or unified may break it. VBlocks then needs to fork it or send
|
|
43
|
+
a pull request
|
|
44
|
+
- A meta that is not JSX attributes fails the build
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Migrate to v8
|
|
2
|
+
|
|
3
|
+
Why: [decision 03](../decisions/03.pass-code-meta-as-props.md)
|
|
4
|
+
|
|
5
|
+
<!-- vim-markdown-toc GFM -->
|
|
6
|
+
|
|
7
|
+
- [The `code` component receives the meta](#the-code-component-receives-the-meta)
|
|
8
|
+
- [A code block meta must be JSX attributes](#a-code-block-meta-must-be-jsx-attributes)
|
|
9
|
+
- [An ejected `webpack.config.js` imports `rehype-mdx-code-props`](#an-ejected-webpackconfigjs-imports-rehype-mdx-code-props)
|
|
10
|
+
|
|
11
|
+
<!-- vim-markdown-toc -->
|
|
12
|
+
|
|
13
|
+
All three changes come from one update of the MDX rule in
|
|
14
|
+
`defaults/webpack.config.js`:
|
|
15
|
+
|
|
16
|
+
```diff
|
|
17
|
+
+import rehypeMdxCodeProps from "rehype-mdx-code-props"
|
|
18
|
+
// …
|
|
19
|
+
{
|
|
20
|
+
test: /\.mdx?$/,
|
|
21
|
+
// …
|
|
22
|
+
- use: [swcLoader, { loader: require.resolve("@mdx-js/loader") }],
|
|
23
|
+
+ use: [
|
|
24
|
+
+ swcLoader,
|
|
25
|
+
+ {
|
|
26
|
+
+ loader: require.resolve("@mdx-js/loader"),
|
|
27
|
+
+ options: {
|
|
28
|
+
+ // The meta of a code block, eg. `file="src/app.tsx"`, becomes
|
|
29
|
+
+ // props of the `code` component. `tagName: "code"` replaces
|
|
30
|
+
+ // the default of the plugin, `pre`
|
|
31
|
+
+ rehypePlugins: [[rehypeMdxCodeProps, { tagName: "code" }]],
|
|
32
|
+
+ },
|
|
33
|
+
+ },
|
|
34
|
+
+ ],
|
|
35
|
+
},
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## The `code` component receives the meta
|
|
39
|
+
|
|
40
|
+
VBlocks now passes a valid meta, eg. `title="Example"`, to the `code` component
|
|
41
|
+
as props.
|
|
42
|
+
|
|
43
|
+
````md
|
|
44
|
+
```tsx title="Example"
|
|
45
|
+
const a = 1
|
|
46
|
+
```
|
|
47
|
+
````
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
// Before
|
|
51
|
+
const Code = (props: ComponentProps<"code">) => <code {...props} />
|
|
52
|
+
|
|
53
|
+
// After
|
|
54
|
+
const Code = ({ title, ...props }: ComponentProps<"code">) => (
|
|
55
|
+
<code {...props} />
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**If unchanged**:
|
|
60
|
+
|
|
61
|
+
- Each meta attribute lands on the `<code>` element in the HTML, eg.
|
|
62
|
+
`<code title="Example">`, when a `code` component spreads its props onto it or
|
|
63
|
+
`components` has no `code` entry
|
|
64
|
+
- The browser shows a `title` attribute as a tooltip
|
|
65
|
+
|
|
66
|
+
**Reason**:
|
|
67
|
+
|
|
68
|
+
- A custom `code` component can read the meta, eg. a file name or the
|
|
69
|
+
highlighted lines, to change how it renders a code block
|
|
70
|
+
|
|
71
|
+
## A code block meta must be JSX attributes
|
|
72
|
+
|
|
73
|
+
The meta is the text after the language of a code block. Write it as JSX
|
|
74
|
+
attributes: a string in quotes, any other value in `{}`, a flag alone.
|
|
75
|
+
|
|
76
|
+
````md
|
|
77
|
+
<!-- Before -->
|
|
78
|
+
|
|
79
|
+
```tsx file=src/app.tsx {1,3}
|
|
80
|
+
const a = 1
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
<!-- After -->
|
|
84
|
+
|
|
85
|
+
```tsx file="src/app.tsx" lines={[1, 3]}
|
|
86
|
+
const a = 1
|
|
87
|
+
```
|
|
88
|
+
````
|
|
89
|
+
|
|
90
|
+
**If unchanged**:
|
|
91
|
+
|
|
92
|
+
- Pages with `file=src/app.tsx` fails build with
|
|
93
|
+
`Unexpected character … before attribute value`
|
|
94
|
+
- Pages with `{1,3}` fails build with `Could not parse expression with acorn`
|
|
95
|
+
|
|
96
|
+
**Reason**:
|
|
97
|
+
|
|
98
|
+
- `rehype-mdx-code-props` reads the meta as JSX attributes
|
|
99
|
+
|
|
100
|
+
## An ejected `webpack.config.js` imports `rehype-mdx-code-props`
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
# Before
|
|
104
|
+
npx vblocks eject webpack > webpack.config.js
|
|
105
|
+
|
|
106
|
+
# After
|
|
107
|
+
npx vblocks eject webpack > webpack.config.js
|
|
108
|
+
npm install --save-dev rehype-mdx-code-props
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**If unchanged**:
|
|
112
|
+
|
|
113
|
+
- An ejected config from v7 keeps working but lacking the new plugin, the `code`
|
|
114
|
+
component will not receive the meta.
|
|
115
|
+
- `serve` or `build` fail with
|
|
116
|
+
`ERR_MODULE_NOT_FOUND: Cannot find package 'rehype-mdx-code-props'`
|
|
117
|
+
|
|
118
|
+
**Reason**:
|
|
119
|
+
|
|
120
|
+
- An ejected config loads its plugins from the project folder, not from VBlocks
|
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": "
|
|
5
|
-
"description": "Zero-config React builds, as a
|
|
4
|
+
"version": "8.0.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
|
],
|
|
@@ -57,7 +59,9 @@
|
|
|
57
59
|
"typecheck:code": "tsc --noEmit --project ./.tsconfig/code.json",
|
|
58
60
|
"typecheck:client-types": "tsc --noEmit --project ./.tsconfig/client-types.json",
|
|
59
61
|
"typecheck": "npm run typecheck:code && npm run typecheck:client-types",
|
|
60
|
-
"
|
|
62
|
+
"integration-test:templates": "test/verify-templates/test",
|
|
63
|
+
"integration-test:mdx-code-meta": "test/mdx-code-meta/test",
|
|
64
|
+
"integration-test": "npm run integration-test:templates && npm run integration-test:mdx-code-meta"
|
|
61
65
|
},
|
|
62
66
|
"dependencies": {
|
|
63
67
|
"@asd14/fancy-logger": "^2.0.0",
|
|
@@ -65,7 +69,7 @@
|
|
|
65
69
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.6.3",
|
|
66
70
|
"@swc/core": "^1.16.22",
|
|
67
71
|
"@swc/helpers": "^0.5.24",
|
|
68
|
-
"browserslist": "^4.29.
|
|
72
|
+
"browserslist": "^4.29.6",
|
|
69
73
|
"copy-webpack-plugin": "^14.0.0",
|
|
70
74
|
"css-loader": "^7.1.5",
|
|
71
75
|
"cssnano": "^9.9.0",
|
|
@@ -74,16 +78,17 @@
|
|
|
74
78
|
"mini-css-extract-plugin": "^2.10.2",
|
|
75
79
|
"postcss": "^8.5.33",
|
|
76
80
|
"postcss-loader": "^8.2.1",
|
|
77
|
-
"postcss-preset-env": "^11.6.
|
|
81
|
+
"postcss-preset-env": "^11.6.3",
|
|
78
82
|
"react-refresh": "^0.19.0",
|
|
83
|
+
"rehype-mdx-code-props": "^3.0.1",
|
|
79
84
|
"swc-loader": "^0.2.7",
|
|
80
85
|
"webpack": "^5.112.2",
|
|
81
|
-
"webpack-bundle-analyzer": "^5.4.
|
|
86
|
+
"webpack-bundle-analyzer": "^5.4.3",
|
|
82
87
|
"webpack-cli": "^7.3.1",
|
|
83
88
|
"webpack-dev-server": "^6.1.0"
|
|
84
89
|
},
|
|
85
90
|
"devDependencies": {
|
|
86
|
-
"@asd14/eslint-config": "^
|
|
91
|
+
"@asd14/eslint-config": "^17.0.0",
|
|
87
92
|
"@asd14/prettier-config": "^1.5.0",
|
|
88
93
|
"@asd14/semantic-release-config": "^1.1.0",
|
|
89
94
|
"@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
|
|
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
|