@asd14/vblocks 8.1.0 → 8.2.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.
@@ -53,17 +53,6 @@ together -->
53
53
  - Import a Markdown or MDX file as a component:\
54
54
  `import {{Intro}} from "{{./intro.mdx}}"`
55
55
 
56
- ## Conventions
57
-
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
62
- - For an advanced use, eg. a micro-frontend, eject the default with
63
- `vblocks eject` and edit the copy
64
- - Put each concern that `src/index.tsx` imports in its own
65
- `src/index.<concern>.tsx`, eg. `index.app.tsx` defines `App`
66
-
67
56
  ## Index
68
57
 
69
58
  <!-- sh41: scripts/get-skill-index-lines --write, in the write-sh41-skill skill,
@@ -72,7 +61,7 @@ recomputes the lines and the counts after each edit of the docs -->
72
61
  Paths are relative to the package root: the VBlocks repo, or
73
62
  `node_modules/@asd14/vblocks/` in the project folder.
74
63
 
75
- **`README.md`**, 614 lines:
64
+ **`README.md`**, 635 lines:
76
65
 
77
66
  - "## Quick Start" L:72-120
78
67
  - "### Keep several apps in one project" L:124-167
@@ -83,19 +72,19 @@ Paths are relative to the package root: the VBlocks repo, or
83
72
  - "### Write a page in Markdown or MDX" L:258-321
84
73
  - "#### `code` meta as props" L:275-321
85
74
  - "### 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:
75
+ - "### Replace a config" L:342-396
76
+ - "### Extend a config" L:398-461
77
+ - "#### PostCSS" L:405-441
78
+ - "#### Webpack" L:443-461
79
+ - "### Style with Tailwind" L:463-518
80
+ - "### Send UI annotations to an AI agent" L:520-538
81
+ - "### Open the page from another device" L:540-547
82
+ - "### Build a single HTML file" L:549-560
83
+ - "### Add VBlocks to an existing project" L:562-599
84
+ - "## More docs" L:601-610
85
+ - "## Develop" L:612-631
86
+
87
+ **`docs/REFERENCE.md`**, 631 lines:
99
88
 
100
89
  - "## Domain Vocabulary" L:27-35
101
90
  - "### `vblocks`" L:39-75
@@ -104,13 +93,13 @@ Paths are relative to the package root: the VBlocks repo, or
104
93
  - "### `vblocks build`" L:191-264
105
94
  - "### `vblocks eject`" L:266-304
106
95
  - "### `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
96
+ - "### `postcss.config.js`" L:356-422
97
+ - "### `.swcrc`" L:424-474
98
+ - "### `.browserslistrc`" L:476-496
99
+ - "### `@asd14/vblocks/postcss`" L:502-552
100
+ - "### `@asd14/vblocks/webpack`" L:554-606
101
+ - "## Templates" L:608-623
102
+ - "## Environment variables" L:625-631
114
103
 
115
104
  **`template/`**:
116
105
 
package/README.md CHANGED
@@ -362,22 +362,39 @@ A config in your app folder replaces the VBlocks default of the same name:
362
362
  npx vblocks eject postcss > postcss.config.js
363
363
  ```
364
364
 
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.
365
+ > [!IMPORTANT]\
366
+ > Node resolves the packages an ejected config imports from the project folder,
367
+ > not from the VBlocks folder. Install them there. To keep the VBlocks config
368
+ > and change part of it, [extend it](#extend-a-config) instead.
370
369
 
371
- 2. **Install the packages it imports**, see its `import` lines
370
+ 2. **Install the packages it imports, and the ones you add**, eg. one that adds
371
+ the `@custom-media` definitions of `src/media.css` to every CSS file
372
372
 
373
373
  ```sh
374
- npm install --save-dev postcss-preset-env cssnano
374
+ npm install --save-dev postcss-preset-env cssnano @csstools/postcss-global-data
375
375
  ```
376
376
 
377
377
  `swc` and `browserslist` import nothing.
378
378
 
379
379
  3. **Update the ejected file**
380
380
 
381
+ ```diff
382
+ +import { fileURLToPath } from "node:url"
383
+ +
384
+ +import postcssGlobalData from "@csstools/postcss-global-data"
385
+ import cssnano from "cssnano"
386
+ import postcssPresetEnv from "postcss-preset-env"
387
+ +
388
+ +const MEDIA = fileURLToPath(new URL("src/media.css", import.meta.url))
389
+
390
+ /** … */
391
+ const getPostcssConfig = ({ mode }) => ({
392
+ plugins: [
393
+ + // First, so postcss-preset-env finds the `(--name)` definitions it replaces
394
+ + postcssGlobalData({ files: [MEDIA] }),
395
+ postcssPresetEnv({ stage: 2 }),
396
+ ```
397
+
381
398
  ### Extend a config
382
399
 
383
400
  Import the VBlocks config into a config of the same name in your app folder,
@@ -387,35 +404,39 @@ so you install only the ones you add.
387
404
 
388
405
  #### PostCSS
389
406
 
390
- 1. **Install your plugin**, eg. one that adds the `@custom-media` definitions of
391
- `src/media.css` to every CSS file
407
+ 1. **Install the plugin you add**, eg. cssnano, with options of your own
392
408
 
393
409
  ```sh
394
- npm install --save-dev @csstools/postcss-global-data
410
+ npm install --save-dev cssnano
395
411
  ```
396
412
 
397
- 2. **Add it to the VBlocks config, in `postcss.config.js`**
413
+ 2. **Replace the VBlocks cssnano, in `postcss.config.js`**
398
414
 
399
415
  ```js
400
- import { fileURLToPath } from "node:url"
401
-
402
416
  import { getPostcssConfig } from "@asd14/vblocks/postcss"
403
- import postcssGlobalData from "@csstools/postcss-global-data"
417
+ import cssnano from "cssnano"
404
418
 
405
- const MEDIA = fileURLToPath(new URL("src/media.css", import.meta.url))
419
+ // The default preset, which also removes the `/*!` comments
420
+ const CSSNANO_OPTIONS = {
421
+ preset: ["default", { discardComments: { removeAll: true } }],
422
+ }
406
423
 
407
424
  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] }))
425
+ const {
426
+ plugins: [presetEnv],
427
+ } = getPostcssConfig(api)
411
428
 
412
- return config
429
+ return {
430
+ plugins: [
431
+ presetEnv,
432
+ ...(api.mode === "production" ? [cssnano(CSSNANO_OPTIONS)] : []),
433
+ ],
434
+ }
413
435
  }
414
436
  ```
415
437
 
416
438
  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)`
439
+ in `production`. Destructure the array to keep the ones you want.
419
440
 
420
441
  See also: [`@asd14/vblocks/postcss`](docs/REFERENCE.md#asd14vblockspostcss)
421
442
 
@@ -16,11 +16,24 @@ import postcssPresetEnv from "postcss-preset-env"
16
16
  * @example
17
17
  * // postcss.config.js, in the app folder
18
18
  * import { getPostcssConfig } from "@asd14/vblocks/postcss"
19
+ * import cssnano from "cssnano"
20
+ *
21
+ * // The default preset, which also removes the `/*!` comments
22
+ * const CSSNANO_OPTIONS = {
23
+ * preset: ["default", { discardComments: { removeAll: true } }],
24
+ * }
19
25
  *
20
26
  * export default api => {
21
- * const { plugins: [presetEnv, cssnano] } = getPostcssConfig(api)
27
+ * const {
28
+ * plugins: [presetEnv],
29
+ * } = getPostcssConfig(api)
22
30
  *
23
- * return { plugins: [presetEnv, ...(cssnano ? [cssnano] : [])] }
31
+ * return {
32
+ * plugins: [
33
+ * presetEnv,
34
+ * ...(api.mode === "production" ? [cssnano(CSSNANO_OPTIONS)] : []),
35
+ * ],
36
+ * }
24
37
  * }
25
38
  */
26
39
  const getPostcssConfig = ({ mode }) => ({
package/docs/REFERENCE.md CHANGED
@@ -385,11 +385,24 @@ import postcssPresetEnv from "postcss-preset-env"
385
385
  * @example
386
386
  * // postcss.config.js, in the app folder
387
387
  * import { getPostcssConfig } from "@asd14/vblocks/postcss"
388
+ * import cssnano from "cssnano"
389
+ *
390
+ * // The default preset, which also removes the `/*!` comments
391
+ * const CSSNANO_OPTIONS = {
392
+ * preset: ["default", { discardComments: { removeAll: true } }],
393
+ * }
388
394
  *
389
395
  * export default api => {
390
- * const { plugins: [presetEnv, cssnano] } = getPostcssConfig(api)
396
+ * const {
397
+ * plugins: [presetEnv],
398
+ * } = getPostcssConfig(api)
391
399
  *
392
- * return { plugins: [presetEnv, ...(cssnano ? [cssnano] : [])] }
400
+ * return {
401
+ * plugins: [
402
+ * presetEnv,
403
+ * ...(api.mode === "production" ? [cssnano(CSSNANO_OPTIONS)] : []),
404
+ * ],
405
+ * }
393
406
  * }
394
407
  */
395
408
  const getPostcssConfig = ({ mode }) => ({
@@ -503,11 +516,24 @@ getPostcssConfig(api: {
503
516
  ```js
504
517
  // postcss.config.js, in the app folder
505
518
  import { getPostcssConfig } from "@asd14/vblocks/postcss"
519
+ import cssnano from "cssnano"
506
520
 
507
- export default api => {
508
- const { plugins: [presetEnv, cssnano] } = getPostcssConfig(api)
521
+ // The default preset, which also removes the `/*!` comments
522
+ const CSSNANO_OPTIONS = {
523
+ preset: ["default", { discardComments: { removeAll: true } }],
524
+ }
509
525
 
510
- return { plugins: [presetEnv, ...(cssnano ? [cssnano] : [])] }
526
+ export default api => {
527
+ const {
528
+ plugins: [presetEnv],
529
+ } = getPostcssConfig(api)
530
+
531
+ return {
532
+ plugins: [
533
+ presetEnv,
534
+ ...(api.mode === "production" ? [cssnano(CSSNANO_OPTIONS)] : []),
535
+ ],
536
+ }
511
537
  }
512
538
  ```
513
539
 
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": "8.1.0",
4
+ "version": "8.2.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",