@asd14/vblocks 7.1.0 → 8.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.
- package/.sh41/skills/use-vblocks/SKILL.md +48 -34
- package/README.md +171 -49
- package/bin/vblocks.d/eject +3 -3
- package/defaults/postcss.config.js +22 -2
- package/defaults/webpack.config.js +36 -8
- package/docs/DECISIONS.md +1 -0
- package/docs/REFERENCE.md +295 -11
- package/docs/decisions/03.pass-code-meta-as-props.md +44 -0
- package/docs/migrations/v8.md +120 -0
- package/package.json +7 -2
- package/template/xyflow/README.md +2 -3
- package/template/xyflow/app/postcss.config.js +16 -8
- package/template/xyflow/post-init-app.sh +0 -1
- package/template/xyflow-tabs/README.md +2 -3
- package/template/xyflow-tabs/app/postcss.config.js +16 -8
- package/template/xyflow-tabs/post-init-app.sh +0 -1
- package/types/client.d.ts +53 -45
|
@@ -56,6 +56,9 @@ together -->
|
|
|
56
56
|
## Conventions
|
|
57
57
|
|
|
58
58
|
- Write no Webpack, PostCSS or SWC config. The defaults cover a React app
|
|
59
|
+
- To change part of a config, import it from `@asd14/vblocks/postcss` or
|
|
60
|
+
`@asd14/vblocks/webpack` in a config of the same name in the app folder,
|
|
61
|
+
change it, and return it
|
|
59
62
|
- For an advanced use, eg. a micro-frontend, eject the default with
|
|
60
63
|
`vblocks eject` and edit the copy
|
|
61
64
|
- Put each concern that `src/index.tsx` imports in its own
|
|
@@ -63,41 +66,51 @@ together -->
|
|
|
63
66
|
|
|
64
67
|
## Index
|
|
65
68
|
|
|
66
|
-
<!-- sh41:
|
|
67
|
-
counts after each edit of the docs -->
|
|
69
|
+
<!-- sh41: scripts/get-skill-index-lines --write, in the write-sh41-skill skill,
|
|
70
|
+
recomputes the lines and the counts after each edit of the docs -->
|
|
68
71
|
|
|
69
72
|
Paths are relative to the package root: the VBlocks repo, or
|
|
70
73
|
`node_modules/@asd14/vblocks/` in the project folder.
|
|
71
74
|
|
|
72
|
-
**`README.md`**,
|
|
73
|
-
|
|
74
|
-
- "## Quick Start" L:
|
|
75
|
-
- "### Keep several apps in one project" L:
|
|
76
|
-
- "### Use `.env` variables" L:
|
|
77
|
-
- "### Import from `src/` with `@self`" L:
|
|
78
|
-
- "### Use CSS Modules" L:
|
|
79
|
-
- "### Import a file as text" L:
|
|
80
|
-
- "### Write a page in Markdown or MDX" L:
|
|
81
|
-
- "
|
|
82
|
-
- "###
|
|
83
|
-
- "###
|
|
84
|
-
- "###
|
|
85
|
-
- "
|
|
86
|
-
- "
|
|
87
|
-
- "###
|
|
88
|
-
- "
|
|
89
|
-
- "
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
- "##
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
- "
|
|
98
|
-
- "### `vblocks
|
|
99
|
-
- "
|
|
100
|
-
- "
|
|
75
|
+
**`README.md`**, 614 lines:
|
|
76
|
+
|
|
77
|
+
- "## Quick Start" L:72-120
|
|
78
|
+
- "### Keep several apps in one project" L:124-167
|
|
79
|
+
- "### Use `.env` variables" L:169-193
|
|
80
|
+
- "### Import from `src/` with `@self`" L:195-216
|
|
81
|
+
- "### Use CSS Modules" L:218-243
|
|
82
|
+
- "### Import a file as text" L:245-256
|
|
83
|
+
- "### Write a page in Markdown or MDX" L:258-321
|
|
84
|
+
- "#### `code` meta as props" L:275-321
|
|
85
|
+
- "### Pick the browsers" L:323-340
|
|
86
|
+
- "### Replace a config" L:342-379
|
|
87
|
+
- "### Extend a config" L:381-440
|
|
88
|
+
- "#### PostCSS" L:388-420
|
|
89
|
+
- "#### Webpack" L:422-440
|
|
90
|
+
- "### Style with Tailwind" L:442-497
|
|
91
|
+
- "### Send UI annotations to an AI agent" L:499-517
|
|
92
|
+
- "### Open the page from another device" L:519-526
|
|
93
|
+
- "### Build a single HTML file" L:528-539
|
|
94
|
+
- "### Add VBlocks to an existing project" L:541-578
|
|
95
|
+
- "## More docs" L:580-589
|
|
96
|
+
- "## Develop" L:591-610
|
|
97
|
+
|
|
98
|
+
**`docs/REFERENCE.md`**, 605 lines:
|
|
99
|
+
|
|
100
|
+
- "## Domain Vocabulary" L:27-35
|
|
101
|
+
- "### `vblocks`" L:39-75
|
|
102
|
+
- "### `vblocks init`" L:77-129
|
|
103
|
+
- "### `vblocks serve`" L:131-189
|
|
104
|
+
- "### `vblocks build`" L:191-264
|
|
105
|
+
- "### `vblocks eject`" L:266-304
|
|
106
|
+
- "### `webpack.config.js`" L:314-354
|
|
107
|
+
- "### `postcss.config.js`" L:356-409
|
|
108
|
+
- "### `.swcrc`" L:411-461
|
|
109
|
+
- "### `.browserslistrc`" L:463-483
|
|
110
|
+
- "### `@asd14/vblocks/postcss`" L:489-526
|
|
111
|
+
- "### `@asd14/vblocks/webpack`" L:528-580
|
|
112
|
+
- "## Templates" L:582-597
|
|
113
|
+
- "## Environment variables" L:599-605
|
|
101
114
|
|
|
102
115
|
**`template/`**:
|
|
103
116
|
|
|
@@ -105,14 +118,15 @@ Paths are relative to the package root: the VBlocks repo, or
|
|
|
105
118
|
- "## Plumbing" L:9-25
|
|
106
119
|
- "## App" L:27-49
|
|
107
120
|
- **`plain/README.md`**, 19 lines
|
|
108
|
-
- **`xyflow/README.md`**,
|
|
109
|
-
- **`xyflow-tabs/README.md`**,
|
|
121
|
+
- **`xyflow/README.md`**, 27 lines
|
|
122
|
+
- **`xyflow-tabs/README.md`**, 32 lines
|
|
110
123
|
|
|
111
124
|
**`docs/decisions/`**:
|
|
112
125
|
|
|
113
126
|
- `01.resolve-dependency-vblocks-folder.md`, 43 lines
|
|
114
127
|
- `02.read-browserslist-config.md`, 36 lines
|
|
128
|
+
- `03.pass-code-meta-as-props.md`, 44 lines
|
|
115
129
|
|
|
116
130
|
**`types/`**:
|
|
117
131
|
|
|
118
|
-
- `client.d.ts`,
|
|
132
|
+
- `client.d.ts`, 145 lines
|
package/README.md
CHANGED
|
@@ -52,8 +52,12 @@ everything set up.
|
|
|
52
52
|
- [Use CSS Modules](#use-css-modules)
|
|
53
53
|
- [Import a file as text](#import-a-file-as-text)
|
|
54
54
|
- [Write a page in Markdown or MDX](#write-a-page-in-markdown-or-mdx)
|
|
55
|
+
- [`code` meta as props](#code-meta-as-props)
|
|
55
56
|
- [Pick the browsers](#pick-the-browsers)
|
|
56
|
-
- [Replace a
|
|
57
|
+
- [Replace a config](#replace-a-config)
|
|
58
|
+
- [Extend a config](#extend-a-config)
|
|
59
|
+
- [PostCSS](#postcss)
|
|
60
|
+
- [Webpack](#webpack)
|
|
57
61
|
- [Style with Tailwind](#style-with-tailwind)
|
|
58
62
|
- [Send UI annotations to an AI agent](#send-ui-annotations-to-an-ai-agent)
|
|
59
63
|
- [Open the page from another device](#open-the-page-from-another-device)
|
|
@@ -153,7 +157,7 @@ contains the plumbing, and each
|
|
|
153
157
|
+ │ └─ tsconfig.json
|
|
154
158
|
├─ .gitignore
|
|
155
159
|
! └─ package.json # + @xyflow/react, tailwindcss, @tailwindcss/postcss,
|
|
156
|
-
! #
|
|
160
|
+
! # agentation
|
|
157
161
|
```
|
|
158
162
|
|
|
159
163
|
3. **Start a development server for one app**
|
|
@@ -268,6 +272,50 @@ heading:
|
|
|
268
272
|
<Intro components={{ h1: Title }} />
|
|
269
273
|
```
|
|
270
274
|
|
|
275
|
+
#### `code` meta as props
|
|
276
|
+
|
|
277
|
+
The `code` component receives the meta of a code block, the text after its
|
|
278
|
+
language, as props. VBlocks reads it with
|
|
279
|
+
[rehype-mdx-code-props](https://github.com/remcohaszing/rehype-mdx-code-props):
|
|
280
|
+
|
|
281
|
+
````md
|
|
282
|
+
```tsx file="src/app.tsx"
|
|
283
|
+
const a = 1
|
|
284
|
+
```
|
|
285
|
+
````
|
|
286
|
+
|
|
287
|
+
```tsx
|
|
288
|
+
type CodeProps = {
|
|
289
|
+
className: string
|
|
290
|
+
file: string
|
|
291
|
+
children: string
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const Code = ({ className, file, children }: CodeProps) => …
|
|
295
|
+
|
|
296
|
+
<Intro components={{ code: Code }} />
|
|
297
|
+
// Code receives:
|
|
298
|
+
// {
|
|
299
|
+
// className: "language-tsx",
|
|
300
|
+
// file: "src/app.tsx",
|
|
301
|
+
// children: "const a = 1\n"
|
|
302
|
+
// }
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
| Meta | Prop |
|
|
306
|
+
| :------------------- | :------- |
|
|
307
|
+
| `file="src/app.tsx"` | a string |
|
|
308
|
+
| `lines={3}` | a number |
|
|
309
|
+
| `showLines` | `true` |
|
|
310
|
+
| `isOff={false}` | `false` |
|
|
311
|
+
| `ids={[1, 2]}` | an array |
|
|
312
|
+
|
|
313
|
+
`{}` takes any JavaScript expression.
|
|
314
|
+
|
|
315
|
+
> [!IMPORTANT]\
|
|
316
|
+
> MDX fails the build if a meta is not JSX attributes, eg. `file=src/app.tsx` or
|
|
317
|
+
> `{1,3}`.
|
|
318
|
+
|
|
271
319
|
> [!NOTE]\
|
|
272
320
|
> The [client types](types/client.d.ts) declare each `.md` and `.mdx` import as
|
|
273
321
|
> a React component.
|
|
@@ -291,74 +339,141 @@ Without one, they compile for the VBlocks default, `> 0.25%, not dead`.
|
|
|
291
339
|
2. **Update the query**, see
|
|
292
340
|
[the queries of browserslist](https://github.com/browserslist/browserslist#queries)
|
|
293
341
|
|
|
294
|
-
### Replace a
|
|
342
|
+
### Replace a config
|
|
295
343
|
|
|
296
344
|
A config in your app folder replaces the VBlocks default of the same name:
|
|
297
345
|
|
|
298
|
-
- `webpack.config.js`
|
|
299
|
-
- `postcss.config.js
|
|
346
|
+
- [`webpack.config.js`](docs/REFERENCE.md#webpackconfigjs)
|
|
347
|
+
- [`postcss.config.js`](docs/REFERENCE.md#postcssconfigjs), the default has two
|
|
348
|
+
plugins:
|
|
300
349
|
- `postcss-preset-env`, which compiles nesting, `oklch()` and `color-mix()`
|
|
301
|
-
for
|
|
350
|
+
for the browsers of `.browserslistrc`
|
|
351
|
+
- It adds vendor prefixes too
|
|
302
352
|
- `cssnano` in `production`
|
|
303
|
-
- `.swcrc`
|
|
304
|
-
-
|
|
353
|
+
- [`.swcrc`](docs/REFERENCE.md#swcrc)
|
|
354
|
+
- VBlocks still sets four of its keys
|
|
355
|
+
- [`.browserslistrc`](docs/REFERENCE.md#browserslistrc), the default
|
|
356
|
+
`> 0.25%, not dead`
|
|
305
357
|
|
|
306
358
|
1. **[Eject](docs/REFERENCE.md#vblocks-eject) the default into your app folder**
|
|
307
359
|
|
|
308
360
|
```sh
|
|
309
361
|
cd my-vblocks-app
|
|
310
|
-
npx vblocks eject
|
|
362
|
+
npx vblocks eject postcss > postcss.config.js
|
|
311
363
|
```
|
|
312
364
|
|
|
313
|
-
|
|
314
|
-
|
|
365
|
+
> [!IMPORTANT]\
|
|
366
|
+
> Node resolves the packages an ejected config imports from the project
|
|
367
|
+
> folder, not from the VBlocks folder. Install them there. To keep the
|
|
368
|
+
> VBlocks config and change part of it, [extend it](#extend-a-config)
|
|
369
|
+
> instead.
|
|
315
370
|
|
|
316
|
-
2. **
|
|
371
|
+
2. **Install the packages it imports**, see its `import` lines
|
|
317
372
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
373
|
+
```sh
|
|
374
|
+
npm install --save-dev postcss-preset-env cssnano
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
`swc` and `browserslist` import nothing.
|
|
378
|
+
|
|
379
|
+
3. **Update the ejected file**
|
|
380
|
+
|
|
381
|
+
### Extend a config
|
|
382
|
+
|
|
383
|
+
Import the VBlocks config into a config of the same name in your app folder,
|
|
384
|
+
change it, and return it. Only `postcss.config.js` and `webpack.config.js` have
|
|
385
|
+
a VBlocks config to import. Node resolves its packages from the VBlocks folder,
|
|
386
|
+
so you install only the ones you add.
|
|
387
|
+
|
|
388
|
+
#### PostCSS
|
|
389
|
+
|
|
390
|
+
1. **Install your plugin**, eg. one that adds the `@custom-media` definitions of
|
|
391
|
+
`src/media.css` to every CSS file
|
|
392
|
+
|
|
393
|
+
```sh
|
|
394
|
+
npm install --save-dev @csstools/postcss-global-data
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
2. **Add it to the VBlocks config, in `postcss.config.js`**
|
|
398
|
+
|
|
399
|
+
```js
|
|
400
|
+
import { fileURLToPath } from "node:url"
|
|
401
|
+
|
|
402
|
+
import { getPostcssConfig } from "@asd14/vblocks/postcss"
|
|
403
|
+
import postcssGlobalData from "@csstools/postcss-global-data"
|
|
404
|
+
|
|
405
|
+
const MEDIA = fileURLToPath(new URL("src/media.css", import.meta.url))
|
|
406
|
+
|
|
407
|
+
export default api => {
|
|
408
|
+
const config = getPostcssConfig(api)
|
|
409
|
+
// First, so postcss-preset-env finds the `(--name)` definitions it replaces
|
|
410
|
+
config.plugins.unshift(postcssGlobalData({ files: [MEDIA] }))
|
|
411
|
+
|
|
412
|
+
return config
|
|
413
|
+
}
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
PostCSS runs the plugins in array order: `postcss-preset-env`, then `cssnano`
|
|
417
|
+
in `production`. To replace one, destructure the array, eg.
|
|
418
|
+
`const { plugins: [presetEnv, cssnano] } = getPostcssConfig(api)`
|
|
419
|
+
|
|
420
|
+
See also: [`@asd14/vblocks/postcss`](docs/REFERENCE.md#asd14vblockspostcss)
|
|
421
|
+
|
|
422
|
+
#### Webpack
|
|
423
|
+
|
|
424
|
+
1. **Change the VBlocks config, in `webpack.config.js`**
|
|
425
|
+
|
|
426
|
+
```js
|
|
427
|
+
import { getWebpackConfig } from "@asd14/vblocks/webpack"
|
|
428
|
+
|
|
429
|
+
export default (environment, props) => {
|
|
430
|
+
const config = getWebpackConfig(environment, props)
|
|
431
|
+
config.watchOptions = { aggregateTimeout: 200 }
|
|
432
|
+
|
|
433
|
+
return config
|
|
434
|
+
}
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
VBlocks passes the environment and the props, so your `webpack.config.js`
|
|
438
|
+
passes them on.
|
|
439
|
+
|
|
440
|
+
See also: [`@asd14/vblocks/webpack`](docs/REFERENCE.md#asd14vblockswebpack)
|
|
325
441
|
|
|
326
442
|
### Style with Tailwind
|
|
327
443
|
|
|
328
444
|
VBlocks does not include Tailwind. Add it through a `postcss.config.js` in your
|
|
329
|
-
app folder
|
|
445
|
+
app folder.
|
|
330
446
|
|
|
331
447
|
> [!NOTE]\
|
|
332
448
|
> The `xyflow` and `xyflow-tabs` templates of
|
|
333
|
-
> [`vblocks init`](docs/REFERENCE.md#vblocks-init)
|
|
449
|
+
> [`vblocks init`](docs/REFERENCE.md#vblocks-init) write this
|
|
450
|
+
> `postcss.config.js`.
|
|
334
451
|
|
|
335
|
-
1. **Install Tailwind
|
|
336
|
-
imports**
|
|
452
|
+
1. **Install Tailwind and its PostCSS plugin**
|
|
337
453
|
|
|
338
454
|
```sh
|
|
339
|
-
npm install --save-dev tailwindcss @tailwindcss/postcss
|
|
455
|
+
npm install --save-dev tailwindcss @tailwindcss/postcss
|
|
340
456
|
```
|
|
341
457
|
|
|
342
|
-
2. **
|
|
458
|
+
2. **Replace `postcss-preset-env` with the Tailwind plugin, in
|
|
459
|
+
`postcss.config.js`**
|
|
343
460
|
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
|
|
461
|
+
```js
|
|
462
|
+
import { getPostcssConfig } from "@asd14/vblocks/postcss"
|
|
463
|
+
import tailwindcss from "@tailwindcss/postcss"
|
|
347
464
|
|
|
348
|
-
|
|
465
|
+
export default api => {
|
|
466
|
+
const {
|
|
467
|
+
plugins: [, cssnano],
|
|
468
|
+
} = getPostcssConfig(api)
|
|
349
469
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
- postcssPresetEnv({ stage: 2 }),
|
|
358
|
-
+ tailwindcss({ optimize: mode === "production" }),
|
|
359
|
-
...(mode === "production" ? [cssnano({ preset: "default" })] : []),
|
|
360
|
-
],
|
|
361
|
-
})
|
|
470
|
+
return {
|
|
471
|
+
plugins: [
|
|
472
|
+
tailwindcss({ optimize: api.mode === "production" }),
|
|
473
|
+
...(cssnano ? [cssnano] : []),
|
|
474
|
+
],
|
|
475
|
+
}
|
|
476
|
+
}
|
|
362
477
|
```
|
|
363
478
|
|
|
364
479
|
> [!IMPORTANT]\
|
|
@@ -367,7 +482,7 @@ app folder:
|
|
|
367
482
|
> itself. With both plugins, `postcss-preset-env` rewrites Tailwind's `@layer`
|
|
368
483
|
> rules into `:not(#\#)` selectors. The CSS file grows.
|
|
369
484
|
|
|
370
|
-
|
|
485
|
+
3. **Add the Tailwind import to `src/index.css`**
|
|
371
486
|
|
|
372
487
|
```css
|
|
373
488
|
@import "tailwindcss" source(".");
|
|
@@ -464,12 +579,14 @@ npx vblocks build --single-file
|
|
|
464
579
|
|
|
465
580
|
## More docs
|
|
466
581
|
|
|
467
|
-
- **Reference**: every command, template and environment
|
|
468
|
-
[docs/REFERENCE.md](docs/REFERENCE.md)
|
|
582
|
+
- **Reference**: every command, config, export, template and environment
|
|
583
|
+
variable, in [docs/REFERENCE.md](docs/REFERENCE.md)
|
|
469
584
|
- **Decisions**: why the code is this way, in
|
|
470
585
|
[docs/DECISIONS.md](docs/DECISIONS.md)
|
|
471
586
|
- **Release history**: what each version added, fixed and removed, in
|
|
472
587
|
[GitHub releases](https://github.com/asd-xiv/vblocks/releases)
|
|
588
|
+
- **Migrations**: how to update your code for each major version, in
|
|
589
|
+
[docs/migrations/](docs/migrations/)
|
|
473
590
|
|
|
474
591
|
## Develop
|
|
475
592
|
|
|
@@ -478,14 +595,19 @@ vblocks/
|
|
|
478
595
|
├── bin/ # vblocks, and one file per command in vblocks.d/
|
|
479
596
|
├── defaults/ # the configs that eject prints
|
|
480
597
|
├── template/ # the templates of init
|
|
598
|
+
├── test/
|
|
599
|
+
│ ├── mdx-code-meta/ # an MDX page with code meta, built and run in Node
|
|
600
|
+
│ └── verify-templates/ # typechecks, builds and serves each template
|
|
481
601
|
└── types/ # client.d.ts
|
|
482
602
|
```
|
|
483
603
|
|
|
484
|
-
| Script
|
|
485
|
-
|
|
|
486
|
-
| `npm run lint`
|
|
487
|
-
| `npm run typecheck`
|
|
488
|
-
| `npm run
|
|
604
|
+
| Script | Does |
|
|
605
|
+
| :--------------------------------------- | :-------------------------------------------------------------------- |
|
|
606
|
+
| `npm run lint` | Runs ESLint |
|
|
607
|
+
| `npm run typecheck` | Typechecks the code and the client types |
|
|
608
|
+
| `npm run integration-test` | Runs both integration tests |
|
|
609
|
+
| `npm run integration-test:templates` | Typechecks, builds and serves every template `vblocks init` writes |
|
|
610
|
+
| `npm run integration-test:mdx-code-meta` | Builds an MDX page and checks the props its `code` component receives |
|
|
489
611
|
|
|
490
612
|
## License
|
|
491
613
|
|
package/bin/vblocks.d/eject
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
# eject prints the config to stdout. Save it in the app folder. serve and
|
|
11
11
|
# build then run with it in place of the VBlocks default.
|
|
12
12
|
#
|
|
13
|
-
#
|
|
14
|
-
# not from VBlocks. Install them there. serve and build
|
|
15
|
-
# webpack-cli, webpack and webpack-dev-server of VBlocks.
|
|
13
|
+
# Node resolves the packages an ejected config imports from the project
|
|
14
|
+
# folder, not from the VBlocks folder. Install them there. serve and build
|
|
15
|
+
# still run the webpack-cli, webpack and webpack-dev-server of VBlocks.
|
|
16
16
|
#
|
|
17
17
|
# ARGUMENTS
|
|
18
18
|
# config webpack Save it as webpack.config.js
|
|
@@ -2,13 +2,33 @@ import cssnano from "cssnano"
|
|
|
2
2
|
import postcssPresetEnv from "postcss-preset-env"
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Return the PostCSS config of the app: `postcss-preset-env`, and `cssnano` in
|
|
6
|
+
* `production`.
|
|
7
|
+
*
|
|
8
|
+
* Node resolves the plugins from the folder of this file.
|
|
9
|
+
* In an app, install them: `npm install --save-dev postcss-preset-env cssnano`.
|
|
10
|
+
* To keep the VBlocks plugins and add yours, import `getPostcssConfig` from
|
|
11
|
+
* `@asd14/vblocks/postcss` instead.
|
|
6
12
|
*
|
|
7
13
|
* @param {{ mode: "production" | "development" | "none" }} api
|
|
14
|
+
* @returns {{ plugins: import("postcss").AcceptedPlugin[] }}
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // postcss.config.js, in the app folder
|
|
18
|
+
* import { getPostcssConfig } from "@asd14/vblocks/postcss"
|
|
19
|
+
*
|
|
20
|
+
* export default api => {
|
|
21
|
+
* const { plugins: [presetEnv, cssnano] } = getPostcssConfig(api)
|
|
22
|
+
*
|
|
23
|
+
* return { plugins: [presetEnv, ...(cssnano ? [cssnano] : [])] }
|
|
24
|
+
* }
|
|
8
25
|
*/
|
|
9
|
-
|
|
26
|
+
const getPostcssConfig = ({ mode }) => ({
|
|
10
27
|
plugins: [
|
|
11
28
|
postcssPresetEnv({ stage: 2 }),
|
|
29
|
+
// `preset` stops cssnano from reading a config file in the current folder
|
|
12
30
|
...(mode === "production" ? [cssnano({ preset: "default" })] : []),
|
|
13
31
|
],
|
|
14
32
|
})
|
|
33
|
+
|
|
34
|
+
export { getPostcssConfig as default, getPostcssConfig }
|
|
@@ -11,6 +11,7 @@ import DotenvPlugin from "dotenv-webpack"
|
|
|
11
11
|
import HtmlWebPackPlugin from "html-webpack-plugin"
|
|
12
12
|
import MiniCssExtractPlugin from "mini-css-extract-plugin"
|
|
13
13
|
import postcss from "postcss"
|
|
14
|
+
import rehypeMdxCodeProps from "rehype-mdx-code-props"
|
|
14
15
|
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer"
|
|
15
16
|
|
|
16
17
|
const logger = buildLogger({ namespace: "vblocks", level: "info" })
|
|
@@ -127,7 +128,7 @@ const getCssLoaders = ({ classScope, isProduction, postcssConfigPath }) => [
|
|
|
127
128
|
const MAX_REPORTED_FILE_EVENTS = 5
|
|
128
129
|
|
|
129
130
|
/**
|
|
130
|
-
* In serve, print each file of the build that was updated, added or
|
|
131
|
+
* In serve, print each file of the build that was updated, added or deleted
|
|
131
132
|
* since the last compile, as $APP_DIR/...
|
|
132
133
|
*
|
|
133
134
|
* @param {string} appDir
|
|
@@ -136,7 +137,7 @@ const MAX_REPORTED_FILE_EVENTS = 5
|
|
|
136
137
|
const reportFileEvents = appDir => compiler => {
|
|
137
138
|
/** @type {Set<string> | undefined} */
|
|
138
139
|
let previousFiles
|
|
139
|
-
/** @type {Array<["Updated" | "Added" | "
|
|
140
|
+
/** @type {Array<["Updated" | "Added" | "Deleted", string]>} */
|
|
140
141
|
let fileEvents = []
|
|
141
142
|
|
|
142
143
|
// The watcher also reports editor swap files and folders, eg. the src/ that
|
|
@@ -152,7 +153,7 @@ const reportFileEvents = appDir => compiler => {
|
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
155
|
for (const file of watcher.removedFiles ?? []) {
|
|
155
|
-
if (previousFiles?.has(file)) fileEvents.push(["
|
|
156
|
+
if (previousFiles?.has(file)) fileEvents.push(["Deleted", file])
|
|
156
157
|
}
|
|
157
158
|
})
|
|
158
159
|
|
|
@@ -187,7 +188,7 @@ const reportFileEvents = appDir => compiler => {
|
|
|
187
188
|
|
|
188
189
|
/**
|
|
189
190
|
* Replace every script and stylesheet tag of the HTML with the content of the
|
|
190
|
-
* file it points at. Point the icon tag at a data URL of its file. Then
|
|
191
|
+
* file it points at. Point the icon tag at a data URL of its file. Then delete
|
|
191
192
|
* each of those files from the output.
|
|
192
193
|
*
|
|
193
194
|
* Lives in this file so an ejected config stays one file.
|
|
@@ -293,11 +294,25 @@ const RAW_QUERY = /[?&]raw(?:&|$)/
|
|
|
293
294
|
*/
|
|
294
295
|
|
|
295
296
|
/**
|
|
297
|
+
* Return the Webpack config of the app. VBlocks passes the environment and the
|
|
298
|
+
* props, so an app's own `webpack.config.js` passes them on.
|
|
299
|
+
*
|
|
296
300
|
* @param {VBlocksEnvironment} environment
|
|
297
301
|
* @param {VBlocksProps} props
|
|
298
302
|
* @returns {WebpackConfiguration}
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* // webpack.config.js, in the app folder
|
|
306
|
+
* import { getWebpackConfig } from "@asd14/vblocks/webpack"
|
|
307
|
+
*
|
|
308
|
+
* export default (environment, props) => {
|
|
309
|
+
* const config = getWebpackConfig(environment, props)
|
|
310
|
+
* config.watchOptions = { aggregateTimeout: 200 }
|
|
311
|
+
*
|
|
312
|
+
* return config
|
|
313
|
+
* }
|
|
299
314
|
*/
|
|
300
|
-
|
|
315
|
+
const getWebpackConfig = (
|
|
301
316
|
{
|
|
302
317
|
entryDir,
|
|
303
318
|
postcssConfigPath,
|
|
@@ -400,7 +415,18 @@ export default (
|
|
|
400
415
|
exclude: /node_modules/,
|
|
401
416
|
resourceQuery: { not: [RAW_QUERY] },
|
|
402
417
|
resolve: swcResolve,
|
|
403
|
-
use: [
|
|
418
|
+
use: [
|
|
419
|
+
swcLoader,
|
|
420
|
+
{
|
|
421
|
+
loader: require.resolve("@mdx-js/loader"),
|
|
422
|
+
options: {
|
|
423
|
+
// The meta of a code block, eg. `file="src/app.tsx"`, becomes
|
|
424
|
+
// props of the `code` component. `tagName: "code"` replaces
|
|
425
|
+
// the default of the plugin, `pre`
|
|
426
|
+
rehypePlugins: [[rehypeMdxCodeProps, { tagName: "code" }]],
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
],
|
|
404
430
|
},
|
|
405
431
|
{
|
|
406
432
|
test: /\.module\.css$/,
|
|
@@ -458,7 +484,7 @@ export default (
|
|
|
458
484
|
// every path
|
|
459
485
|
historyApiFallback: true,
|
|
460
486
|
|
|
461
|
-
// Hot Module Replacement updates, adds and
|
|
487
|
+
// Hot Module Replacement updates, adds and removes modules in the running
|
|
462
488
|
// app, without a full reload
|
|
463
489
|
// https://webpack.js.org/concepts/hot-module-replacement/
|
|
464
490
|
hot: true,
|
|
@@ -579,7 +605,7 @@ export default (
|
|
|
579
605
|
},
|
|
580
606
|
|
|
581
607
|
optimization: {
|
|
582
|
-
// Mark unused exports, so the minifier
|
|
608
|
+
// Mark unused exports, so the minifier removes them
|
|
583
609
|
usedExports: true,
|
|
584
610
|
|
|
585
611
|
// Merge runtime.js into main.js for fewer HTTP requests
|
|
@@ -616,3 +642,5 @@ export default (
|
|
|
616
642
|
},
|
|
617
643
|
}
|
|
618
644
|
}
|
|
645
|
+
|
|
646
|
+
export { getWebpackConfig as default, getWebpackConfig }
|
package/docs/DECISIONS.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Decisions - @asd14/vblocks
|
|
2
2
|
|
|
3
|
+
- [03. Pass the meta of a code block as props](decisions/03.pass-code-meta-as-props.md)
|
|
3
4
|
- [02. Read the browsers from the browserslist config](decisions/02.read-browserslist-config.md)
|
|
4
5
|
- [01. Resolve each dependency from the VBlocks folder](decisions/01.resolve-dependency-vblocks-folder.md)
|