@asd14/vblocks 5.2.0 → 5.3.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/README.md +84 -164
- package/bin/vblocks.sh +15 -5
- package/package.json +5 -5
- package/src/webpack.config.js +2 -0
package/README.md
CHANGED
|
@@ -28,8 +28,8 @@ Apps share one `package.json` and `node_modules/`. A new app reuses the
|
|
|
28
28
|
installed packages
|
|
29
29
|
|
|
30
30
|
**🤖 Optimized for AI agents**
|
|
31
|
-
The agent's context holds only the app: no Webpack, PostCSS or TypeScript
|
|
32
|
-
|
|
31
|
+
The agent's context holds only the app: no Webpack, PostCSS or TypeScript config
|
|
32
|
+
to write, read or fix
|
|
33
33
|
|
|
34
34
|
> [!IMPORTANT]
|
|
35
35
|
> VBlocks needs Node `^22.22.3`, `^24.15.0` or `>=26.0`.
|
|
@@ -83,6 +83,12 @@ Using "scaffold", the field's word for what `init` does, eg. Yeoman and
|
|
|
83
83
|
create-vite use it.
|
|
84
84
|
-->
|
|
85
85
|
|
|
86
|
+
<!--
|
|
87
|
+
Using the `my-vblocks-` prefix, the package name, so a reader who tries several
|
|
88
|
+
scaffolders spots the folder at a glance, as with `vite-project` and
|
|
89
|
+
`nuxt-app`.
|
|
90
|
+
-->
|
|
91
|
+
|
|
86
92
|
1. **Scaffold a minimal React project**
|
|
87
93
|
|
|
88
94
|
```sh
|
|
@@ -197,8 +203,8 @@ another reader, eg. one with an existing app, goes last.
|
|
|
197
203
|
```
|
|
198
204
|
|
|
199
205
|
Webpack replaces each `process.env["NAME"]` with the value of `NAME`, and
|
|
200
|
-
`undefined` when `.env` does not set it.
|
|
201
|
-
your code does not read.
|
|
206
|
+
`undefined` when `.env` does not set it. Webpack leaves out of the bundle every
|
|
207
|
+
variable your code does not read.
|
|
202
208
|
|
|
203
209
|
> [!WARNING]
|
|
204
210
|
> Never expose a secret, eg. an API key, through `process.env`. Anyone who loads
|
|
@@ -218,9 +224,10 @@ import { Component } from "@self/components"
|
|
|
218
224
|
```
|
|
219
225
|
|
|
220
226
|
> [!NOTE]
|
|
221
|
-
> VBlocks
|
|
222
|
-
> `tsconfig.json`
|
|
223
|
-
>
|
|
227
|
+
> VBlocks compiles TypeScript with SWC and does not typecheck. Run `tsc`
|
|
228
|
+
> yourself. Your `tsconfig.json` needs the same alias as Webpack.
|
|
229
|
+
> The `tsconfig.json` that [`vblocks init`](#vblocks-init) writes already has
|
|
230
|
+
> it. Otherwise, add:
|
|
224
231
|
>
|
|
225
232
|
> ```json
|
|
226
233
|
> {
|
|
@@ -255,16 +262,20 @@ import { Component } from "@self/components"
|
|
|
255
262
|
`development` mode
|
|
256
263
|
|
|
257
264
|
> [!NOTE]
|
|
258
|
-
> The [client types](src/types/client.d.ts) declare `.css
|
|
259
|
-
>
|
|
265
|
+
> The [client types](src/types/client.d.ts) declare `.css`, image and font
|
|
266
|
+
> imports
|
|
260
267
|
|
|
261
268
|
### Replace a default config
|
|
262
269
|
|
|
263
|
-
Each
|
|
270
|
+
Each config in your app folder replaces the default of the same name:
|
|
264
271
|
|
|
265
272
|
- `webpack.config.js`
|
|
266
273
|
- `postcss.config.js`
|
|
274
|
+
- `postcss-preset-env`, which compiles nesting, `oklch()` and `color-mix()`
|
|
275
|
+
for older browsers and adds vendor prefixes
|
|
276
|
+
- `cssnano` in `production`
|
|
267
277
|
- `.swcrc`
|
|
278
|
+
- browser targets `> 0.25%, not dead`
|
|
268
279
|
|
|
269
280
|
1. **[Eject](#vblocks-eject) the default into your app folder**
|
|
270
281
|
|
|
@@ -369,8 +380,9 @@ app folder:
|
|
|
369
380
|
|
|
370
381
|
<!--
|
|
371
382
|
Diátaxis: reference. Mirror SYNOPSIS and OPTIONS of `vblocks --help`, in the
|
|
372
|
-
same words.
|
|
373
|
-
|
|
383
|
+
same words. The SYNOPSIS puts one option per line, with its values, so it fits
|
|
384
|
+
the width of GitHub. Below it, each option is a bullet with its default, and
|
|
385
|
+
its description in sub-bullets.
|
|
374
386
|
-->
|
|
375
387
|
|
|
376
388
|
### `vblocks init`
|
|
@@ -378,116 +390,95 @@ description, like OPTIONS in a man page.
|
|
|
378
390
|
Write a template's plumbing, app, or both into `<directory>`.
|
|
379
391
|
|
|
380
392
|
```text
|
|
381
|
-
vblocks init <directory>
|
|
393
|
+
vblocks init <directory>
|
|
394
|
+
[--template <plain|xyflow>]
|
|
395
|
+
[--only <app|plumbing>]
|
|
382
396
|
```
|
|
383
397
|
|
|
384
|
-
- `<directory
|
|
385
|
-
The folder to write into. It must be missing or empty
|
|
386
|
-
- `--template
|
|
387
|
-
|
|
388
|
-
- `--only
|
|
389
|
-
Write one part of the template
|
|
398
|
+
- `<directory>`
|
|
399
|
+
- The folder to write into. It must be missing or empty
|
|
400
|
+
- `--template` (default: `plain`)
|
|
401
|
+
- `xyflow` adds React Flow and Tailwind
|
|
402
|
+
- `--only` (default: both)
|
|
403
|
+
- Write one part of the template
|
|
390
404
|
- `plumbing`: `package.json`, `.gitignore`
|
|
391
405
|
- `app`: `src/`, `tsconfig.json` and the template's configs. `init` adds the
|
|
392
406
|
template's dependencies to the `package.json` of the
|
|
393
407
|
[project folder](#vocabulary), the nearest folder above `<directory>` with a
|
|
394
408
|
`package.json`. Without that folder, `init` fails
|
|
395
409
|
|
|
396
|
-
**Example**:
|
|
397
|
-
|
|
398
|
-
<!--
|
|
399
|
-
Using the `my-vblocks-` prefix, the package name, so a reader who tries several
|
|
400
|
-
scaffolders spots the folder at a glance, as with `vite-project` and
|
|
401
|
-
`nuxt-app`.
|
|
402
|
-
-->
|
|
403
|
-
|
|
404
|
-
```sh
|
|
405
|
-
npx @asd14/vblocks init my-vblocks-flow --template xyflow
|
|
406
|
-
cd my-vblocks-flow
|
|
407
|
-
npm install
|
|
408
|
-
```
|
|
409
|
-
|
|
410
410
|
### `vblocks serve`
|
|
411
411
|
|
|
412
412
|
Start the development server.
|
|
413
413
|
|
|
414
414
|
- Runs at `http://localhost:8080`, or the next free port
|
|
415
|
-
- Listens on
|
|
415
|
+
- Listens on `localhost`, so another device on your network, eg. a phone, cannot
|
|
416
|
+
open the page
|
|
416
417
|
- Opens the page in the browser
|
|
417
418
|
|
|
418
419
|
```text
|
|
419
|
-
vblocks serve
|
|
420
|
+
vblocks serve
|
|
421
|
+
[--mode <development|production>]
|
|
422
|
+
[--prefix <directory>]
|
|
423
|
+
[--analyze]
|
|
424
|
+
[--log-level <error|warn|info|verbose>]
|
|
425
|
+
[<webpack option>...]
|
|
420
426
|
```
|
|
421
427
|
|
|
422
|
-
- `--mode
|
|
423
|
-
The Webpack mode
|
|
424
|
-
React Refresh runs only in `development`
|
|
425
|
-
- `--prefix
|
|
426
|
-
The [app folder](#vocabulary), which must exist
|
|
427
|
-
- `--analyze
|
|
428
|
-
Run the bundle analyzer, on a free port
|
|
429
|
-
- `--log-level
|
|
430
|
-
How much Webpack, its development server and npm print
|
|
431
|
-
|
|
432
|
-
-
|
|
433
|
-
|
|
434
|
-
passes it to Webpack unchanged
|
|
435
|
-
|
|
436
|
-
**Example**:
|
|
437
|
-
|
|
438
|
-
```sh
|
|
439
|
-
cd my-vblocks-flow
|
|
440
|
-
npx vblocks serve
|
|
441
|
-
# ↓↓↓
|
|
442
|
-
# npx webpack serve --config <webpack config> \
|
|
443
|
-
# --env entryDir=<app folder> \
|
|
444
|
-
# --mode development \
|
|
445
|
-
# ...
|
|
446
|
-
```
|
|
428
|
+
- `--mode` (default: `development`)
|
|
429
|
+
- The Webpack mode
|
|
430
|
+
- React Refresh runs only in `development`
|
|
431
|
+
- `--prefix` (default: the current folder)
|
|
432
|
+
- The [app folder](#vocabulary), which must exist
|
|
433
|
+
- `--analyze`
|
|
434
|
+
- Run the bundle analyzer, on a free port
|
|
435
|
+
- `--log-level` (default: `warn`)
|
|
436
|
+
- How much Webpack, its development server and npm print
|
|
437
|
+
- `<webpack option>...`
|
|
438
|
+
- Any other [`webpack serve`](https://webpack.js.org/api/cli/) option, passed
|
|
439
|
+
unchanged, eg. `--host 0.0.0.0` to listen on the network
|
|
447
440
|
|
|
448
441
|
### `vblocks build`
|
|
449
442
|
|
|
450
|
-
Build the app into a bundle in the `dist/` of the app folder.
|
|
451
|
-
|
|
443
|
+
Build the app into a bundle in the `dist/` of the app folder.
|
|
444
|
+
|
|
445
|
+
By default, `build`:
|
|
452
446
|
|
|
453
447
|
- Writes JS and CSS files with content-hashed names
|
|
454
448
|
- Writes a `react` chunk, and a `vendors` chunk when your other dependencies
|
|
455
449
|
total over 20 KB (10 KB in `development`)
|
|
450
|
+
- Inlines `jpg`, `gif`, `png` and `svg` files up to 10 KB, writes larger ones to
|
|
451
|
+
`dist/` with content-hashed names
|
|
452
|
+
- Writes `woff`, `woff2`, `ttf` and `eot` files to `dist/fonts/`
|
|
453
|
+
- Copies `src/public/favicon.svg` and `src/public/robots.txt` of your app, or
|
|
454
|
+
the defaults of VBlocks
|
|
456
455
|
|
|
457
456
|
```text
|
|
458
|
-
vblocks build
|
|
457
|
+
vblocks build
|
|
458
|
+
[--mode <development|production>]
|
|
459
|
+
[--prefix <directory>]
|
|
460
|
+
[--single-file]
|
|
461
|
+
[--log-level <error|warn|info|verbose>]
|
|
462
|
+
[<webpack option>...]
|
|
459
463
|
```
|
|
460
464
|
|
|
461
|
-
- `--mode
|
|
462
|
-
The Webpack mode
|
|
463
|
-
`production`, `build` minifies JS
|
|
464
|
-
|
|
465
|
-
- `--prefix
|
|
466
|
-
The [app folder](#vocabulary), which must exist
|
|
467
|
-
- `--single-file
|
|
468
|
-
|
|
465
|
+
- `--mode` (default: `production`)
|
|
466
|
+
- The Webpack mode
|
|
467
|
+
- In `production`, `build` minifies JS, HTML and, with the default PostCSS
|
|
468
|
+
config, CSS
|
|
469
|
+
- `--prefix` (default: the current folder)
|
|
470
|
+
- The [app folder](#vocabulary), which must exist
|
|
471
|
+
- `--single-file`
|
|
472
|
+
- Write one standalone `dist/index.html`, every asset inlined
|
|
469
473
|
- A browser opens the file from disk, with no server and no network
|
|
470
474
|
- The bundle has no `robots.txt`
|
|
471
|
-
- Keep the route in the URL hash
|
|
472
|
-
path throws
|
|
473
|
-
- `--log-level
|
|
474
|
-
How much Webpack and npm print
|
|
475
|
-
|
|
476
|
-
-
|
|
477
|
-
|
|
478
|
-
`--stats errors-only`. VBlocks passes it to Webpack unchanged
|
|
479
|
-
|
|
480
|
-
**Example**:
|
|
481
|
-
|
|
482
|
-
```sh
|
|
483
|
-
cd my-vblocks-flow
|
|
484
|
-
npx vblocks build
|
|
485
|
-
# ↓↓↓
|
|
486
|
-
# npx webpack build --config <webpack config> \
|
|
487
|
-
# --env entryDir=<app folder> \
|
|
488
|
-
# --mode production \
|
|
489
|
-
# ...
|
|
490
|
-
```
|
|
475
|
+
- Keep the route in the URL hash
|
|
476
|
+
- On `file://`, `history.pushState` to another path throws
|
|
477
|
+
- `--log-level` (default: `warn`)
|
|
478
|
+
- How much Webpack and npm print
|
|
479
|
+
- `<webpack option>...`
|
|
480
|
+
- Any other [`webpack build`](https://webpack.js.org/api/cli/) option, passed
|
|
481
|
+
unchanged, eg. `--stats errors-only`
|
|
491
482
|
|
|
492
483
|
### `vblocks eject`
|
|
493
484
|
|
|
@@ -497,8 +488,8 @@ Print a default config to stdout.
|
|
|
497
488
|
vblocks eject <webpack|postcss|swc>
|
|
498
489
|
```
|
|
499
490
|
|
|
500
|
-
- `<webpack|postcss|swc
|
|
501
|
-
The config to print
|
|
491
|
+
- `<webpack|postcss|swc>`
|
|
492
|
+
- The config to print
|
|
502
493
|
|
|
503
494
|
Save the output in your app folder to
|
|
504
495
|
[replace the default](#replace-a-default-config):
|
|
@@ -509,77 +500,6 @@ npx vblocks eject postcss > postcss.config.js
|
|
|
509
500
|
npx vblocks eject swc > .swcrc
|
|
510
501
|
```
|
|
511
502
|
|
|
512
|
-
<!--
|
|
513
|
-
PARKED: sort each fact below into an existing section or a new one, or drop
|
|
514
|
-
it. The client types and the PostCSS default have no home yet.
|
|
515
|
-
|
|
516
|
-
## Details
|
|
517
|
-
|
|
518
|
-
### TypeScript
|
|
519
|
-
|
|
520
|
-
VBlocks does not check types and never reads your `tsconfig.json`. It only
|
|
521
|
-
compiles TypeScript with SWC.
|
|
522
|
-
|
|
523
|
-
For convenience, VBlocks provides client types in
|
|
524
|
-
[`client.d.ts`](src/types/client.d.ts) for:
|
|
525
|
-
|
|
526
|
-
- `.css` imports
|
|
527
|
-
- Image and font imports
|
|
528
|
-
- `process.env`
|
|
529
|
-
|
|
530
|
-
You can use them in your `tsconfig.json`:
|
|
531
|
-
|
|
532
|
-
```json
|
|
533
|
-
{
|
|
534
|
-
"compilerOptions": {
|
|
535
|
-
"types": ["@asd14/vblocks/client"]
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
```
|
|
539
|
-
|
|
540
|
-
> [!NOTE]
|
|
541
|
-
> The `tsconfig.json` that [`vblocks init`](#vblocks-init) writes has the client
|
|
542
|
-
> types and the [`@self`](#stop-using--everywhere) alias.
|
|
543
|
-
|
|
544
|
-
### PostCSS
|
|
545
|
-
|
|
546
|
-
The default `postcss.config.js`:
|
|
547
|
-
|
|
548
|
-
```js
|
|
549
|
-
/**
|
|
550
|
-
* @param {{ mode: "production" | "development" | "none" }} api
|
|
551
|
-
*/
|
|
552
|
-
export default ({ mode }) => ({
|
|
553
|
-
plugins: {
|
|
554
|
-
"postcss-preset-env": {
|
|
555
|
-
stage: 2,
|
|
556
|
-
},
|
|
557
|
-
"cssnano": mode === "production" && {
|
|
558
|
-
preset: "default",
|
|
559
|
-
},
|
|
560
|
-
},
|
|
561
|
-
})
|
|
562
|
-
```
|
|
563
|
-
|
|
564
|
-
> [!NOTE]
|
|
565
|
-
> `postcss-preset-env` compiles nesting, `oklch()` and `color-mix()` for older
|
|
566
|
-
> browsers and adds vendor prefixes.
|
|
567
|
-
|
|
568
|
-
### Asset Handling
|
|
569
|
-
|
|
570
|
-
- **Images** - the build inlines `jpg`, `gif`, `png` and `svg` files up to 10 KB
|
|
571
|
-
- **Fonts** - the build writes `woff`, `woff2`, `ttf` and `eot` files to
|
|
572
|
-
`dist/fonts/`
|
|
573
|
-
- **Favicon and `robots.txt`** - yours or the default. With `--single-file`, the
|
|
574
|
-
build inlines the favicon and leaves `robots.txt` out
|
|
575
|
-
|
|
576
|
-
## How It Works
|
|
577
|
-
|
|
578
|
-
VBlocks is a POSIX shell script that runs Webpack. The script exports
|
|
579
|
-
`VB_POSTCSS_CONFIG` and `VB_SWC_CONFIG`, the paths of the configs it picked. The
|
|
580
|
-
Webpack config reads them.
|
|
581
|
-
-->
|
|
582
|
-
|
|
583
503
|
## License
|
|
584
504
|
|
|
585
505
|
MIT
|
package/bin/vblocks.sh
CHANGED
|
@@ -6,11 +6,21 @@ set -eu
|
|
|
6
6
|
# vblocks - Run Webpack with the configs of VBlocks, write a project or an app
|
|
7
7
|
#
|
|
8
8
|
# SYNOPSIS
|
|
9
|
-
# vblocks init <directory>
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
# vblocks
|
|
13
|
-
#
|
|
9
|
+
# vblocks init <directory>
|
|
10
|
+
# [--template <plain|xyflow>]
|
|
11
|
+
# [--only <app|plumbing>]
|
|
12
|
+
# vblocks serve
|
|
13
|
+
# [--mode <development|production>]
|
|
14
|
+
# [--prefix <directory>]
|
|
15
|
+
# [--analyze]
|
|
16
|
+
# [--log-level <error|warn|info|verbose>]
|
|
17
|
+
# [<webpack option>...]
|
|
18
|
+
# vblocks build
|
|
19
|
+
# [--mode <development|production>]
|
|
20
|
+
# [--prefix <directory>]
|
|
21
|
+
# [--single-file]
|
|
22
|
+
# [--log-level <error|warn|info|verbose>]
|
|
23
|
+
# [<webpack option>...]
|
|
14
24
|
# vblocks eject <webpack|postcss|swc>
|
|
15
25
|
# vblocks -h | --help
|
|
16
26
|
#
|
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": "5.
|
|
4
|
+
"version": "5.3.0",
|
|
5
5
|
"description": "Zero-config React builds, as a static site or a single HTML file",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"react",
|
|
@@ -64,22 +64,22 @@
|
|
|
64
64
|
"browserslist": "^4.29.3",
|
|
65
65
|
"copy-webpack-plugin": "^14.0.0",
|
|
66
66
|
"css-loader": "^7.1.5",
|
|
67
|
-
"cssnano": "^9.
|
|
67
|
+
"cssnano": "^9.9.0",
|
|
68
68
|
"dotenv-webpack": "^9.0.0",
|
|
69
69
|
"html-webpack-plugin": "^5.6.8",
|
|
70
70
|
"mini-css-extract-plugin": "^2.10.2",
|
|
71
|
-
"postcss": "^8.5.
|
|
71
|
+
"postcss": "^8.5.30",
|
|
72
72
|
"postcss-loader": "^8.2.1",
|
|
73
73
|
"postcss-preset-env": "^11.6.1",
|
|
74
74
|
"react-refresh": "^0.19.0",
|
|
75
75
|
"swc-loader": "^0.2.7",
|
|
76
|
-
"webpack": "^5.
|
|
76
|
+
"webpack": "^5.112.0",
|
|
77
77
|
"webpack-bundle-analyzer": "^5.4.0",
|
|
78
78
|
"webpack-cli": "^7.2.3",
|
|
79
79
|
"webpack-dev-server": "^6.0.0"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@asd14/eslint-config": "^
|
|
82
|
+
"@asd14/eslint-config": "^16.0.0",
|
|
83
83
|
"@asd14/prettier-config": "^1.5.0",
|
|
84
84
|
"@asd14/semantic-release-config": "^1.0.1",
|
|
85
85
|
"@asd14/ts-config": "^1.6.0",
|
package/src/webpack.config.js
CHANGED
|
@@ -10,6 +10,8 @@ import MiniCssExtractPlugin from "mini-css-extract-plugin"
|
|
|
10
10
|
import webpack from "webpack"
|
|
11
11
|
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer"
|
|
12
12
|
|
|
13
|
+
// `bin/vblocks.sh` sets them to the PostCSS and SWC configs it picked, the
|
|
14
|
+
// app's own or the default
|
|
13
15
|
const VB_SWC_CONFIG = process.env["VB_SWC_CONFIG"]
|
|
14
16
|
const VB_POSTCSS_CONFIG = process.env["VB_POSTCSS_CONFIG"]
|
|
15
17
|
|