@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/docs/REFERENCE.md CHANGED
@@ -11,6 +11,14 @@
11
11
  - [`vblocks serve`](#vblocks-serve)
12
12
  - [`vblocks build`](#vblocks-build)
13
13
  - [`vblocks eject`](#vblocks-eject)
14
+ - [Configs](#configs)
15
+ - [`webpack.config.js`](#webpackconfigjs)
16
+ - [`postcss.config.js`](#postcssconfigjs)
17
+ - [`.swcrc`](#swcrc)
18
+ - [`.browserslistrc`](#browserslistrc)
19
+ - [Exports](#exports)
20
+ - [`@asd14/vblocks/postcss`](#asd14vblockspostcss)
21
+ - [`@asd14/vblocks/webpack`](#asd14vblockswebpack)
14
22
  - [Templates](#templates)
15
23
  - [Environment variables](#environment-variables)
16
24
 
@@ -270,13 +278,13 @@ vblocks eject <config>
270
278
  npx vblocks eject postcss > postcss.config.js
271
279
  ```
272
280
 
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 |
281
+ | Name | Description |
282
+ | :------------- | :-------------------------------------------------------------- |
283
+ | `config` | `webpack`: Save it as [`webpack.config.js`](#webpackconfigjs) |
284
+ | | `postcss`: Save it as [`postcss.config.js`](#postcssconfigjs) |
285
+ | | `swc`: Save it as [`.swcrc`](#swcrc) |
286
+ | | `browserslist`: Save it as [`.browserslistrc`](#browserslistrc) |
287
+ | `-h`, `--help` | Print this help |
280
288
 
281
289
  | Exit code | Means |
282
290
  | :-------- | :------------ |
@@ -286,12 +294,288 @@ npx vblocks eject postcss > postcss.config.js
286
294
  `eject` prints the config to stdout. Save it in the app folder. `serve` and
287
295
  `build` then run with it in place of the VBlocks default.
288
296
 
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.
297
+ Node resolves the packages an ejected config imports from the project folder,
298
+ not from the VBlocks folder. Install them there. `serve` and `build` still run
299
+ the `webpack-cli`, `webpack` and `webpack-dev-server` of VBlocks.
292
300
 
293
301
  See also: [`vblocks`](#vblocks), [`vblocks serve`](#vblocks-serve),
294
- [`vblocks build`](#vblocks-build)
302
+ [`vblocks build`](#vblocks-build), [Configs](#configs)
303
+
304
+ </details>
305
+
306
+ ## Configs
307
+
308
+ A config in the app folder replaces the VBlocks default of the same name.
309
+ [`vblocks eject`](#vblocks-eject) prints a default.
310
+
311
+ To change part of the webpack or postcss default instead of replacing it, extend
312
+ it with an [export](#exports).
313
+
314
+ ### `webpack.config.js`
315
+
316
+ Bundle `src/index.tsx`, `src/index.css` if it exists, and `src/index.html` into
317
+ `dist/`
318
+
319
+ ```sh
320
+ npx vblocks eject webpack > webpack.config.js
321
+ ```
322
+
323
+ <details>
324
+ <summary>Loaders, plugins</summary>
325
+
326
+ | Files | Loaders, in the order they run, or the output |
327
+ | :-------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------ |
328
+ | `*.ts`, `*.tsx`, outside `node_modules` | `swc-loader`, with [`.swcrc`](#swcrc) |
329
+ | `*.md`, `*.mdx`, outside `node_modules` | `@mdx-js/loader`, with `rehype-mdx-code-props`, then `swc-loader` |
330
+ | `*.css` | `postcss-loader`, with [`postcss.config.js`](#postcssconfigjs), then `css-loader`, then the loader of `mini-css-extract-plugin` |
331
+ | `*.module.css` | the same, and `css-loader` renames each class to a unique name, see [Use CSS Modules](../README.md#use-css-modules) |
332
+ | `*.jpg`, `*.gif`, `*.png`, `*.svg` | a data URL up to 10 KiB, a file above it. With `--single-file`, a data URL |
333
+ | `*.woff`, `*.woff2`, `*.ttf`, `*.eot` | a file in `dist/fonts/`. With `--single-file`, a data URL |
334
+ | a `?raw` import | the text of the file |
335
+
336
+ - `html-webpack-plugin` writes `dist/index.html` from `src/index.html`, with
337
+ `favicon.svg`
338
+ - `mini-css-extract-plugin` writes the CSS into `dist/css/`
339
+ - `dotenv-webpack` replaces each `process.env["NAME"]` with its value in the
340
+ `.env` of the app folder
341
+ - `copy-webpack-plugin` copies `robots.txt` into `dist/`, except with
342
+ `--single-file`
343
+ - With `--single-file`, the build puts every script, stylesheet and the favicon
344
+ into `dist/index.html`
345
+ - `serve` prints each file of the build that changed since the last compile
346
+ - `@pmmmwh/react-refresh-webpack-plugin` runs in `serve`, in `development`
347
+ - `webpack-bundle-analyzer` runs with `serve --analyze`
348
+
349
+ [`vblocks build`](#vblocks-build) lists what `dist/` contains.
350
+
351
+ To change part of it, extend it with
352
+ [`@asd14/vblocks/webpack`](#asd14vblockswebpack).
353
+
354
+ </details>
355
+
356
+ ### `postcss.config.js`
357
+
358
+ Compile nesting, `oklch()` and `color-mix()` for the browsers of
359
+ [`.browserslistrc`](#browserslistrc), and add vendor prefixes. Minify the CSS in
360
+ `production`
361
+
362
+ ```sh
363
+ npx vblocks eject postcss > postcss.config.js
364
+ ```
365
+
366
+ <details>
367
+ <summary>The default</summary>
368
+
369
+ ```js
370
+ import cssnano from "cssnano"
371
+ import postcssPresetEnv from "postcss-preset-env"
372
+
373
+ /**
374
+ * Return the PostCSS config of the app: `postcss-preset-env`, and `cssnano` in
375
+ * `production`.
376
+ *
377
+ * Node resolves the plugins from the folder of this file.
378
+ * In an app, install them: `npm install --save-dev postcss-preset-env cssnano`.
379
+ * To keep the VBlocks plugins and add yours, import `getPostcssConfig` from
380
+ * `@asd14/vblocks/postcss` instead.
381
+ *
382
+ * @param {{ mode: "production" | "development" | "none" }} api
383
+ * @returns {{ plugins: import("postcss").AcceptedPlugin[] }}
384
+ *
385
+ * @example
386
+ * // postcss.config.js, in the app folder
387
+ * import { getPostcssConfig } from "@asd14/vblocks/postcss"
388
+ *
389
+ * export default api => {
390
+ * const { plugins: [presetEnv, cssnano] } = getPostcssConfig(api)
391
+ *
392
+ * return { plugins: [presetEnv, ...(cssnano ? [cssnano] : [])] }
393
+ * }
394
+ */
395
+ const getPostcssConfig = ({ mode }) => ({
396
+ plugins: [
397
+ postcssPresetEnv({ stage: 2 }),
398
+ // `preset` stops cssnano from reading a config file in the current folder
399
+ ...(mode === "production" ? [cssnano({ preset: "default" })] : []),
400
+ ],
401
+ })
402
+
403
+ export { getPostcssConfig as default, getPostcssConfig }
404
+ ```
405
+
406
+ To change part of it, extend it with
407
+ [`@asd14/vblocks/postcss`](#asd14vblockspostcss).
408
+
409
+ </details>
410
+
411
+ ### `.swcrc`
412
+
413
+ Compile TypeScript and TSX, with the automatic runtime of React, for the
414
+ browsers of [`.browserslistrc`](#browserslistrc)
415
+
416
+ ```sh
417
+ npx vblocks eject swc > .swcrc
418
+ ```
419
+
420
+ <details>
421
+ <summary>The default, and the keys VBlocks sets</summary>
422
+
423
+ ```json
424
+ {
425
+ "$schema": "https://swc.rs/schema.json",
426
+ "minify": false,
427
+ "sourceMaps": true,
428
+ "env": {
429
+ "mode": "entry",
430
+ "coreJs": "3.22"
431
+ },
432
+ "jsc": {
433
+ "externalHelpers": true,
434
+ "minify": {
435
+ "format": {
436
+ "comments": "all"
437
+ }
438
+ },
439
+ "parser": {
440
+ "syntax": "typescript",
441
+ "tsx": true,
442
+ "dynamicImport": true
443
+ },
444
+ "transform": {
445
+ "react": {
446
+ "runtime": "automatic"
447
+ }
448
+ }
449
+ }
450
+ }
451
+ ```
452
+
453
+ VBlocks sets these keys on the `.swcrc`, the default or yours:
454
+
455
+ | Key | Value |
456
+ | :--------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------- |
457
+ | `swcrc` | `false`: SWC reads no other `.swcrc`, eg. the one in the project folder |
458
+ | `env.path` | the app folder, unless yours sets one, so SWC reads the browserslist config from there up |
459
+ | `jsc.transform.react.development`, `jsc.transform.react.refresh` | `true` in `serve`, in `development`, for React Refresh. Without the React Refresh plugin, `refresh: true` breaks the page, so leave it unset in yours |
460
+
461
+ </details>
462
+
463
+ ### `.browserslistrc`
464
+
465
+ The browsers that SWC, Webpack and `postcss-preset-env` compile for
466
+
467
+ ```sh
468
+ npx vblocks eject browserslist > .browserslistrc
469
+ ```
470
+
471
+ <details>
472
+ <summary>The default, and where browserslist reads it</summary>
473
+
474
+ ```text
475
+ > 0.25%, not dead
476
+ ```
477
+
478
+ browserslist reads `BROWSERSLIST`, `BROWSERSLIST_CONFIG`, then a
479
+ `.browserslistrc` or the `browserslist` field of `package.json`, from the app
480
+ folder up. Without any of them, browserslist reads the VBlocks default,
481
+ `defaults/.browserslistrc`. See [Environment variables](#environment-variables).
482
+
483
+ </details>
484
+
485
+ ## Exports
486
+
487
+ Each export is a module. It exports its function by name and as the default.
488
+
489
+ ### `@asd14/vblocks/postcss`
490
+
491
+ Return the PostCSS config of the app: `postcss-preset-env`, and `cssnano` in
492
+ `production`.
493
+
494
+ ```ts
495
+ getPostcssConfig(api: {
496
+ mode: "production" | "development" | "none"
497
+ }): { plugins: AcceptedPlugin[] }
498
+ ```
499
+
500
+ <details>
501
+ <summary>Example, inputs, returns</summary>
502
+
503
+ ```js
504
+ // postcss.config.js, in the app folder
505
+ import { getPostcssConfig } from "@asd14/vblocks/postcss"
506
+
507
+ export default api => {
508
+ const { plugins: [presetEnv, cssnano] } = getPostcssConfig(api)
509
+
510
+ return { plugins: [presetEnv, ...(cssnano ? [cssnano] : [])] }
511
+ }
512
+ ```
513
+
514
+ | Name | Type | Description |
515
+ | :--------- | :---------------------------------------- | :---------------------------------------------------------------------------------------------------- |
516
+ | `api.mode` | `"production" \| "development" \| "none"` | The Webpack mode, `production`, `development` or `none`. With `production`, the config adds `cssnano` |
517
+
518
+ Returns `{ plugins: AcceptedPlugin[] }`: `postcss-preset-env`, then `cssnano` in
519
+ `production`. `cssnano` is `undefined` outside `production`.
520
+
521
+ Node resolves the plugins from the VBlocks folder. Install only the plugins you
522
+ add.
523
+
524
+ See also: [`postcss.config.js`](#postcssconfigjs)
525
+
526
+ </details>
527
+
528
+ ### `@asd14/vblocks/webpack`
529
+
530
+ Return the Webpack config of the app.
531
+
532
+ ```ts
533
+ getWebpackConfig(
534
+ environment: VBlocksEnvironment,
535
+ props: { mode: "production" | "development" }
536
+ ): WebpackConfiguration
537
+ ```
538
+
539
+ <details>
540
+ <summary>Example, inputs, returns</summary>
541
+
542
+ ```js
543
+ // webpack.config.js, in the app folder
544
+ import { getWebpackConfig } from "@asd14/vblocks/webpack"
545
+
546
+ export default (environment, props) => {
547
+ const config = getWebpackConfig(environment, props)
548
+ config.watchOptions = { aggregateTimeout: 200 }
549
+
550
+ return config
551
+ }
552
+ ```
553
+
554
+ VBlocks passes the environment and the props, so an app's own
555
+ `webpack.config.js` passes them on.
556
+
557
+ `environment` has these fields:
558
+
559
+ | Name | Type | Default | Description |
560
+ | :------------------ | :----------------------------------------- | :------- | :--------------------------------------------------------------------------------- |
561
+ | `entryDir` | `string` | | The app folder: `--prefix`, or the folder VBlocks runs in |
562
+ | `postcssConfigPath` | `string` | | Path to the PostCSS config, the app's own or the default |
563
+ | `swcConfigPath` | `string` | | Path to the SWC config, the app's own or the default |
564
+ | `robotsPath` | `string` | | Path to the robots.txt copied to the output folder, missing in a single-file build |
565
+ | `faviconPath` | `string` | | Path to the favicon.svg copied to the output folder |
566
+ | `single` | `boolean` | | Build one standalone index.html, every asset inlined |
567
+ | `analyze` | `boolean` | | Run the bundle analyzer next to the dev server |
568
+ | `logLevel` | `"error" \| "warn" \| "info" \| "verbose"` | `"warn"` | How much Webpack and its dev server print |
569
+ | `WEBPACK_SERVE` | `boolean` | | webpack-cli sets it for `serve`, and its aliases `server` and `s` |
570
+
571
+ `props` has one field, `mode`: `production` or `development`.
572
+
573
+ Returns the Webpack `Configuration` that VBlocks runs.
574
+
575
+ Node resolves its loaders and plugins from the VBlocks folder. Install only the
576
+ packages you add.
577
+
578
+ See also: [`webpack.config.js`](#webpackconfigjs)
295
579
 
296
580
  </details>
297
581
 
@@ -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,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@asd14/vblocks",
4
- "version": "7.1.0",
4
+ "version": "8.1.0",
5
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",
@@ -45,6 +45,8 @@
45
45
  "./client": {
46
46
  "types": "./types/client.d.ts"
47
47
  },
48
+ "./postcss": "./defaults/postcss.config.js",
49
+ "./webpack": "./defaults/webpack.config.js",
48
50
  "./package.json": "./package.json"
49
51
  },
50
52
  "bin": {
@@ -59,7 +61,9 @@
59
61
  "typecheck:code": "tsc --noEmit --project ./.tsconfig/code.json",
60
62
  "typecheck:client-types": "tsc --noEmit --project ./.tsconfig/client-types.json",
61
63
  "typecheck": "npm run typecheck:code && npm run typecheck:client-types",
62
- "unit-test": "tools/verify-templates"
64
+ "integration-test:templates": "test/verify-templates/test",
65
+ "integration-test:mdx-code-meta": "test/mdx-code-meta/test",
66
+ "integration-test": "npm run integration-test:templates && npm run integration-test:mdx-code-meta"
63
67
  },
64
68
  "dependencies": {
65
69
  "@asd14/fancy-logger": "^2.0.0",
@@ -78,6 +82,7 @@
78
82
  "postcss-loader": "^8.2.1",
79
83
  "postcss-preset-env": "^11.6.3",
80
84
  "react-refresh": "^0.19.0",
85
+ "rehype-mdx-code-props": "^3.0.1",
81
86
  "swc-loader": "^0.2.7",
82
87
  "webpack": "^5.112.2",
83
88
  "webpack-bundle-analyzer": "^5.4.3",
@@ -14,7 +14,7 @@ src/
14
14
  ├── details.tsx # the panel for the selected node or edge
15
15
  ├── utils/grid.ts # CELL_SIZE and toPixels
16
16
  └── index.css # replaces the common one: Tailwind and the xyflow styles
17
- postcss.config.js # replaces the VBlocks default: Tailwind, and cssnano in production
17
+ postcss.config.js # extends the VBlocks default: Tailwind in place of postcss-preset-env
18
18
  ```
19
19
 
20
20
  **Hooks**:
@@ -23,6 +23,5 @@ postcss.config.js # replaces the VBlocks default: Tailwind, and cssnano in
23
23
  copy:
24
24
  - Adds `@xyflow/react` to the `dependencies` of the nearest `package.json`,
25
25
  the one of the [project folder](../../docs/REFERENCE.md#domain-vocabulary)
26
- - Adds `tailwindcss`, `@tailwindcss/postcss` and `cssnano` to its
27
- `devDependencies`
26
+ - Adds `tailwindcss` and `@tailwindcss/postcss` to its `devDependencies`
28
27
  - Sets the page title in `src/index.html` to `xyflow :: VBlocks`
@@ -1,14 +1,22 @@
1
+ import { getPostcssConfig } from "@asd14/vblocks/postcss"
1
2
  import tailwindcss from "@tailwindcss/postcss"
2
- import cssnano from "cssnano"
3
3
 
4
4
  /**
5
- * Import the plugins, so Node resolves them from this file's folder
5
+ * Return the PostCSS config of the app: Tailwind, and cssnano in `production`.
6
+ * Tailwind compiles nesting and adds vendor prefixes itself, so it replaces
7
+ * `postcss-preset-env`
6
8
  *
7
9
  * @param {{ mode: "production" | "development" | "none" }} api
8
10
  */
9
- export default ({ mode }) => ({
10
- plugins: [
11
- tailwindcss({ optimize: mode === "production" }),
12
- ...(mode === "production" ? [cssnano({ preset: "default" })] : []),
13
- ],
14
- })
11
+ export default api => {
12
+ const {
13
+ plugins: [, cssnano],
14
+ } = getPostcssConfig(api)
15
+
16
+ return {
17
+ plugins: [
18
+ tailwindcss({ optimize: api.mode === "production" }),
19
+ ...(cssnano ? [cssnano] : []),
20
+ ],
21
+ }
22
+ }
@@ -8,7 +8,6 @@ set -eu
8
8
  npm pkg set \
9
9
  "dependencies.@xyflow/react=^12" \
10
10
  "devDependencies.@tailwindcss/postcss=^4" \
11
- "devDependencies.cssnano=^9" \
12
11
  "devDependencies.tailwindcss=^4"
13
12
 
14
13
  # Name the page in the browser tab.
@@ -19,7 +19,7 @@ src/
19
19
  │ # that centers the diagram at 100%
20
20
  ├── utils/grid.ts # CELL_SIZE and toPixels
21
21
  └── index.css # replaces the common one: Tailwind and the xyflow styles
22
- postcss.config.js # replaces the VBlocks default: Tailwind, and cssnano in production
22
+ postcss.config.js # extends the VBlocks default: Tailwind in place of postcss-preset-env
23
23
  ```
24
24
 
25
25
  **Hooks**:
@@ -28,6 +28,5 @@ postcss.config.js # replaces the VBlocks default: Tailwind, and cssnano
28
28
  copy:
29
29
  - Adds `@xyflow/react` to the `dependencies` of the nearest `package.json`,
30
30
  the one of the [project folder](../../docs/REFERENCE.md#domain-vocabulary)
31
- - Adds `tailwindcss`, `@tailwindcss/postcss` and `cssnano` to its
32
- `devDependencies`
31
+ - Adds `tailwindcss` and `@tailwindcss/postcss` to its `devDependencies`
33
32
  - Sets the page title in `src/index.html` to `xyflow-tabs :: VBlocks`
@@ -1,14 +1,22 @@
1
+ import { getPostcssConfig } from "@asd14/vblocks/postcss"
1
2
  import tailwindcss from "@tailwindcss/postcss"
2
- import cssnano from "cssnano"
3
3
 
4
4
  /**
5
- * Import the plugins, so Node resolves them from this file's folder
5
+ * Return the PostCSS config of the app: Tailwind, and cssnano in `production`.
6
+ * Tailwind compiles nesting and adds vendor prefixes itself, so it replaces
7
+ * `postcss-preset-env`
6
8
  *
7
9
  * @param {{ mode: "production" | "development" | "none" }} api
8
10
  */
9
- export default ({ mode }) => ({
10
- plugins: [
11
- tailwindcss({ optimize: mode === "production" }),
12
- ...(mode === "production" ? [cssnano({ preset: "default" })] : []),
13
- ],
14
- })
11
+ export default api => {
12
+ const {
13
+ plugins: [, cssnano],
14
+ } = getPostcssConfig(api)
15
+
16
+ return {
17
+ plugins: [
18
+ tailwindcss({ optimize: api.mode === "production" }),
19
+ ...(cssnano ? [cssnano] : []),
20
+ ],
21
+ }
22
+ }
@@ -8,7 +8,6 @@ set -eu
8
8
  npm pkg set \
9
9
  "dependencies.@xyflow/react=^12" \
10
10
  "devDependencies.@tailwindcss/postcss=^4" \
11
- "devDependencies.cssnano=^9" \
12
11
  "devDependencies.tailwindcss=^4"
13
12
 
14
13
  # Name the page in the browser tab.