@asd14/vblocks 3.1.0 β†’ 4.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/README.md CHANGED
@@ -3,12 +3,33 @@
3
3
 
4
4
  # @asd14/vblocks
5
5
 
6
- > πŸ“œ POSIX + πŸ“¦ Webpack, an unlikely story!
6
+ > Zero-config React builds, as a static site or a single HTML file
7
7
 
8
- - **Minimal config** - Needs only `src/index.tsx` and `src/index.html`
9
- - **Maximal support** - SWC, PostCSS (CSS Modules configured), MDX, React
10
- Refresh, Dotenv, bundle analyzer
11
- - **Static SPA** - Builds to `dist/` with no server part, for any static host
8
+ **βœ‚οΈ Zero config**
9
+ Needs only `src/index.tsx` and `src/index.html`
10
+
11
+ <!--
12
+ Using "Maximal support" to answer "Zero config" above: nothing to set up, and
13
+ everything set up.
14
+ -->
15
+
16
+ **πŸ”‹ Maximal support**
17
+ SWC, PostCSS (CSS Modules configured), MDX, React Refresh, Dotenv
18
+
19
+ <!--
20
+ PARKED until SSG is finished, then name both outputs: SPA and SSG.
21
+
22
+ **πŸ“„ Static website**
23
+ Builds to `dist/`, for any static host
24
+ -->
25
+
26
+ **πŸ“¦ Several apps, one install**
27
+ Apps share one `package.json` and `node_modules/`, a new app reuses the
28
+ installed packages
29
+
30
+ **πŸ€– Optimized for AI agents**
31
+ No config to write, so an agent spends its tokens on the content, not on the
32
+ setup
12
33
 
13
34
  > [!IMPORTANT]
14
35
  > VBlocks needs Node `^22.22.3`, `^24.15.0` or `>=26.0`.
@@ -57,6 +78,11 @@ DiΓ‘taxis: tutorial. The fewest steps to a working build. It shows enough of
57
78
  VBlocks for the reader to decide whether VBlocks fits their project.
58
79
  -->
59
80
 
81
+ <!--
82
+ Using "scaffold", the field's word for what `init` does, eg. Yeoman and
83
+ create-vite use it.
84
+ -->
85
+
60
86
  1. **Scaffold a minimal React project**
61
87
 
62
88
  ```sh
@@ -169,9 +195,9 @@ another reader, eg. one with an existing app, goes last.
169
195
  const apiUrl = process.env["API_URL"]
170
196
  ```
171
197
 
172
- Webpack replaces each `process.env` with the variable's value. A variable that
173
- `.env` does not set is replaced with `undefined`. The build leaves out every
174
- variable your code does not read.
198
+ Webpack replaces each `process.env["NAME"]` with the value of `NAME`, and
199
+ `undefined` when `.env` does not set it. The build leaves out every variable
200
+ your code does not read.
175
201
 
176
202
  > [!WARNING]
177
203
  > Never expose a secret, eg. an API key, through `process.env`. Anyone who loads
@@ -358,12 +384,17 @@ vblocks init <directory> [--template <name>] [--only <app|plumbing>]
358
384
  - `--only <app|plumbing>`\
359
385
  Write one part of the template (default: both)
360
386
  - `plumbing`: `package.json`, `.gitignore`
361
- - `app`: `src/`, `tsconfig.json` and the template's configs. The template's
362
- hook adds its dependencies to the nearest `package.json` above
363
- `<directory>`. Without one, `init` fails
387
+ - `app`: `src/`, `tsconfig.json` and the template's configs. `init` adds the
388
+ template's dependencies to the nearest `package.json` above `<directory>`.
389
+ Without one, `init` fails
364
390
 
365
391
  **Example**:
366
392
 
393
+ <!--
394
+ Using the `my-vblock-` prefix, so a reader who tries several scaffolders spots
395
+ the folder at a glance, as with `vite-project` and `nuxt-app`.
396
+ -->
397
+
367
398
  ```sh
368
399
  npx @asd14/vblocks init my-vblock-flow --template xyflow
369
400
  cd my-vblock-flow
@@ -374,11 +405,11 @@ npm install
374
405
 
375
406
  Start the development server.
376
407
 
377
- - The server runs at `http://localhost:8080`. It opens the page in the browser
378
- - The bundle analyzer runs at `http://127.0.0.1:8888`
408
+ - Runs at `http://localhost:8080`, or the next free port
409
+ - Opens the page in the browser
379
410
 
380
411
  ```text
381
- vblocks serve [--mode <mode>] [--prefix <directory>] [<webpack option>...]
412
+ vblocks serve [--mode <mode>] [--prefix <directory>] [--analyze] [<webpack option>...]
382
413
  ```
383
414
 
384
415
  - `--mode <mode>`\
@@ -386,6 +417,8 @@ vblocks serve [--mode <mode>] [--prefix <directory>] [<webpack option>...]
386
417
  React Refresh runs only in `development`
387
418
  - `--prefix <directory>`\
388
419
  The [app folder](#vocabulary), which must exist (default: the current folder)
420
+ - `--analyze`\
421
+ Run the bundle analyzer, on a free port
389
422
  - `<webpack option>`\
390
423
  Any other [`webpack serve`](https://webpack.js.org/api/cli/) option. VBlocks
391
424
  passes it to Webpack unchanged
@@ -417,8 +450,8 @@ vblocks build [--mode <mode>] [--prefix <directory>] [--single-file] [<webpack o
417
450
 
418
451
  - `--mode <mode>`\
419
452
  The Webpack mode, `development` or `production` (default: `production`). In
420
- `production`, the build minifies JS and HTML, and the default PostCSS config
421
- minifies CSS
453
+ `production`, the build minifies JS and HTML, and cssnano, in the default
454
+ PostCSS config, minifies CSS
422
455
  - `--prefix <directory>`\
423
456
  The [app folder](#vocabulary), which must exist (default: the current folder)
424
457
  - `--single-file`\
package/bin/vblocks.sh CHANGED
@@ -7,7 +7,8 @@ set -eu
7
7
  #
8
8
  # SYNOPSIS
9
9
  # vblocks init <directory> [--template <name>] [--only <app|plumbing>]
10
- # vblocks serve [--mode <mode>] [--prefix <directory>] [<webpack option>...]
10
+ # vblocks serve [--mode <mode>] [--prefix <directory>] [--analyze]
11
+ # [<webpack option>...]
11
12
  # vblocks build [--mode <mode>] [--prefix <directory>] [--single-file]
12
13
  # [<webpack option>...]
13
14
  # vblocks eject <webpack|postcss|swc>
@@ -41,6 +42,7 @@ set -eu
41
42
  # current folder)
42
43
  # --single-file build: one standalone dist/index.html, every
43
44
  # asset inlined
45
+ # --analyze serve: run the bundle analyzer, on a free port
44
46
  # -h, --help Print this help
45
47
  #
46
48
  # ENVIRONMENT
@@ -388,6 +390,11 @@ case "$COMMAND" in
388
390
  # webpack.config.js reads env.single, an ejected one too
389
391
  set -- "$@" --env single
390
392
  ;;
393
+ --analyze)
394
+ [ "$COMMAND" = "serve" ] || fail 2 "--analyze works only with serve"
395
+ # webpack.config.js reads env.analyze, an ejected one too
396
+ set -- "$@" --env analyze
397
+ ;;
391
398
  *)
392
399
  set -- "$@" "$ARG"
393
400
  ;;
package/package.json CHANGED
@@ -1,8 +1,22 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@asd14/vblocks",
4
- "version": "3.1.0",
5
- "description": "󱆃 POSIX + ξ££ Webpack, an unlikely story!",
4
+ "version": "4.0.0",
5
+ "description": "Zero-config React builds, as a static site or a single HTML file",
6
+ "keywords": [
7
+ "react",
8
+ "webpack",
9
+ "zero-config",
10
+ "single-file",
11
+ "static-site",
12
+ "spa",
13
+ "scaffolding",
14
+ "cli",
15
+ "ai-agents",
16
+ "swc",
17
+ "postcss",
18
+ "mdx"
19
+ ],
6
20
  "license": "MIT",
7
21
  "sideEffects": false,
8
22
  "publishConfig": {
@@ -148,6 +148,7 @@ const inlineAssets = compiler => {
148
148
  * @property {string} robotsPath - Path to robots.txt copied to the output directory
149
149
  * @property {string} faviconPath - Path to favicon.ico copied to the output directory
150
150
  * @property {boolean} [single] - Build one standalone index.html, every asset inlined
151
+ * @property {boolean} [analyze] - Run the bundle analyzer next to the dev server
151
152
  */
152
153
 
153
154
  /**
@@ -161,10 +162,14 @@ const inlineAssets = compiler => {
161
162
  * @param {VBlocksProps} props
162
163
  * @returns {WebpackConfiguration}
163
164
  */
164
- export default ({ entryDir, robotsPath, faviconPath, single }, { mode }) => {
165
+ export default (
166
+ { entryDir, robotsPath, faviconPath, single, analyze },
167
+ { mode }
168
+ ) => {
165
169
  const isProduction = mode === "production"
166
170
  const isServe = process.argv[2] == "serve"
167
171
  const isSingle = Boolean(single) && !isServe
172
+ const isAnalyze = Boolean(analyze) && isServe
168
173
  const hasReactRefresh = isServe && mode === "development"
169
174
  const swcConfig = loadSwcConfig({ hasReactRefresh })
170
175
  const commonPostCSSConfigs = createCssModuleConfig(isProduction)
@@ -190,6 +195,9 @@ export default ({ entryDir, robotsPath, faviconPath, single }, { mode }) => {
190
195
 
191
196
  mode: mode,
192
197
 
198
+ // Keep the summary of VBlocks on screen, `--stats` overrides it
199
+ stats: "errors-warnings",
200
+
193
201
  output: {
194
202
  // A standalone file opens from disk, where "/" is the filesystem root
195
203
  publicPath: isSingle ? "" : "/",
@@ -352,6 +360,8 @@ export default ({ entryDir, robotsPath, faviconPath, single }, { mode }) => {
352
360
 
353
361
  new DotenvPlugin({
354
362
  path: paths.dotenv,
363
+ // Don't spam logs, an app without a .env is common
364
+ silent: true,
355
365
  }),
356
366
 
357
367
  !isSingle &&
@@ -369,9 +379,11 @@ export default ({ entryDir, robotsPath, faviconPath, single }, { mode }) => {
369
379
 
370
380
  isSingle && inlineAssets,
371
381
 
372
- isServe &&
382
+ isAnalyze &&
373
383
  new BundleAnalyzerPlugin({
374
384
  openAnalyzer: false,
385
+ // Two dev servers would otherwise both take 8888
386
+ analyzerPort: "auto",
375
387
  }),
376
388
 
377
389
  hasReactRefresh && new ReactRefreshWebpackPlugin(),