@asd14/vblocks 4.0.0 → 5.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
@@ -282,6 +282,11 @@ Each of these configs in your app folder replaces the default of the same name:
282
282
  > - `.swcrc -> jsc.transform.react.refresh`: VBlocks adds the React Refresh
283
283
  > transform when `serve` runs in `development` mode
284
284
 
285
+ > [!NOTE]
286
+ > [`build --single-file`](#vblocks-build) and
287
+ > [`serve --analyze`](#vblocks-serve) reach your `webpack.config.js` as
288
+ > `env.single` and `env.analyze`.
289
+
285
290
  ### Style with Tailwind
286
291
 
287
292
  VBlocks does not include Tailwind. Add it through a `postcss.config.js` in your
@@ -406,10 +411,11 @@ npm install
406
411
  Start the development server.
407
412
 
408
413
  - Runs at `http://localhost:8080`, or the next free port
414
+ - Listens on this machine only, `--host 0.0.0.0` exposes it to the network
409
415
  - Opens the page in the browser
410
416
 
411
417
  ```text
412
- vblocks serve [--mode <mode>] [--prefix <directory>] [--analyze] [<webpack option>...]
418
+ vblocks serve [--mode <mode>] [--prefix <directory>] [--analyze] [--log-level <level>] [<webpack option>...]
413
419
  ```
414
420
 
415
421
  - `--mode <mode>`\
@@ -419,6 +425,9 @@ vblocks serve [--mode <mode>] [--prefix <directory>] [--analyze] [<webpack optio
419
425
  The [app folder](#vocabulary), which must exist (default: the current folder)
420
426
  - `--analyze`\
421
427
  Run the bundle analyzer, on a free port
428
+ - `--log-level <level>`\
429
+ How much Webpack, its dev server and npm print: `error`, `warn`, `info` or
430
+ `verbose` (default: `warn`)
422
431
  - `<webpack option>`\
423
432
  Any other [`webpack serve`](https://webpack.js.org/api/cli/) option. VBlocks
424
433
  passes it to Webpack unchanged
@@ -445,7 +454,7 @@ build:
445
454
  total over 20 KB (10 KB in `development`)
446
455
 
447
456
  ```text
448
- vblocks build [--mode <mode>] [--prefix <directory>] [--single-file] [<webpack option>...]
457
+ vblocks build [--mode <mode>] [--prefix <directory>] [--single-file] [--log-level <level>] [<webpack option>...]
449
458
  ```
450
459
 
451
460
  - `--mode <mode>`\
@@ -460,6 +469,9 @@ vblocks build [--mode <mode>] [--prefix <directory>] [--single-file] [<webpack o
460
469
  - The build leaves `robots.txt` out
461
470
  - Keep the route in the URL hash. On `file://`, `history.pushState` to another
462
471
  path throws
472
+ - `--log-level <level>`\
473
+ How much Webpack, its dev server and npm print: `error`, `warn`, `info` or
474
+ `verbose` (default: `warn`)
463
475
  - `<webpack option>`\
464
476
  Any other [`webpack build`](https://webpack.js.org/api/cli/) option, eg.
465
477
  `--stats errors-only`. VBlocks passes it to Webpack unchanged
package/bin/vblocks.sh CHANGED
@@ -8,9 +8,9 @@ set -eu
8
8
  # SYNOPSIS
9
9
  # vblocks init <directory> [--template <name>] [--only <app|plumbing>]
10
10
  # vblocks serve [--mode <mode>] [--prefix <directory>] [--analyze]
11
- # [<webpack option>...]
11
+ # [--log-level <level>] [<webpack option>...]
12
12
  # vblocks build [--mode <mode>] [--prefix <directory>] [--single-file]
13
- # [<webpack option>...]
13
+ # [--log-level <level>] [<webpack option>...]
14
14
  # vblocks eject <webpack|postcss|swc>
15
15
  # vblocks -h | --help
16
16
  #
@@ -20,9 +20,11 @@ set -eu
20
20
  # VBlocks with the same name.
21
21
  #
22
22
  # init Write a template into <directory>, which must be missing or
23
- # empty. A template has two parts: the plumbing, the files of
24
- # the project folder, and the app. Without --only, write both.
25
- # After each part, run its post-init hooks in <directory>
23
+ # empty. A template has two parts: the plumbing, which holds
24
+ # the files of the project folder, and the app. Without --only,
25
+ # write both.
26
+ # After each part, run its post-init hooks in <directory>.
27
+ # Print each file it adds or updates, then the next steps
26
28
  # serve Start the development server
27
29
  # build Build the app into dist/ in the app folder
28
30
  # eject Print a default config, to save in the app folder
@@ -32,9 +34,9 @@ set -eu
32
34
  # OPTIONS
33
35
  # --template <name> init: plain or xyflow (default: plain)
34
36
  # --only <app|plumbing> init: write only the app or only the plumbing.
35
- # The app adds its dependencies to the project
36
- # folder: the nearest folder above <directory>
37
- # with a package.json
37
+ # init adds the app's dependencies to the
38
+ # project folder: the nearest folder above
39
+ # <directory> with a package.json
38
40
  # --mode <mode> serve, build: the Webpack mode, development or
39
41
  # production (default: development for serve,
40
42
  # production for build)
@@ -43,11 +45,13 @@ set -eu
43
45
  # --single-file build: one standalone dist/index.html, every
44
46
  # asset inlined
45
47
  # --analyze serve: run the bundle analyzer, on a free port
48
+ # --log-level <level> serve, build: how much Webpack, its dev server and
49
+ # npm print: error, warn, info or verbose (default:
50
+ # warn)
46
51
  # -h, --help Print this help
47
52
  #
48
53
  # ENVIRONMENT
49
- # NO_COLOR Disables color in the summary of serve and build when set and
50
- # non-empty
54
+ # NO_COLOR When set and non-empty, print every summary without color
51
55
  #
52
56
  # EXAMPLE
53
57
  # npx @asd14/vblocks init my-app
@@ -59,8 +63,8 @@ set -eu
59
63
  # EXIT CODES
60
64
  # 0 Done
61
65
  # 2 Invalid usage, or Webpack rejected an option or the config
62
- # 3 Could not run: a missing tool or project, a failed copy, hook or
63
- # build
66
+ # 3 Could not run: a missing tool or project, or a failed folder, copy,
67
+ # hook or build
64
68
  #
65
69
  # SEE ALSO
66
70
  # webpack, npm
@@ -82,6 +86,7 @@ INIT_DIR="" # init <directory>
82
86
  TEMPLATE="plain" # init --template
83
87
  PARTS="plumbing app" # init --only, "plumbing" or "app"
84
88
  PREFIX="" # serve/build --prefix, the app folder
89
+ LOG_LEVEL="warn" # serve/build --log-level, error, warn, info or verbose
85
90
  EJECT_CONFIG="" # eject <config>
86
91
 
87
92
  # ╭───
@@ -118,7 +123,7 @@ require_cmd() {
118
123
  #
119
124
  # RETURNS
120
125
  # 0 stderr is a terminal that shows color
121
- # 1 It is not, or NO_COLOR is set
126
+ # 1 It is not, NO_COLOR is non-empty, or TERM is dumb or unset
122
127
  has_color() {
123
128
  [ -t 2 ] && [ -z "${NO_COLOR:-}" ] && [ "${TERM:-dumb}" != "dumb" ]
124
129
  }
@@ -151,6 +156,18 @@ shorten_home() {
151
156
  printf '%s\n' "$1"
152
157
  }
153
158
 
159
+ # shorten_path <absolute-path>
160
+ #
161
+ # Print <absolute-path> relative to the current folder when it is inside it,
162
+ # otherwise with the home folder as "~".
163
+ shorten_path() {
164
+ case "$1" in
165
+ "$PWD") printf '.\n' ;;
166
+ "$PWD"/*) printf '%s\n' "${1#"$PWD"/}" ;;
167
+ *) shorten_home "$1" ;;
168
+ esac
169
+ }
170
+
154
171
  # ╭───
155
172
  # │ Domain primitives
156
173
  # ╰───
@@ -173,8 +190,8 @@ list_templates() {
173
190
 
174
191
  # find_project_root <directory>
175
192
  #
176
- # Print the nearest folder above <directory> that holds a package.json. The
177
- # folders of <directory> need not exist yet.
193
+ # Print the nearest folder above <directory> that holds a package.json.
194
+ # <directory> and the folders above it need not exist yet.
178
195
  #
179
196
  # RETURNS
180
197
  # 1 No folder above <directory> holds one
@@ -188,7 +205,7 @@ find_project_root() {
188
205
  root_dir=$(dirname "$root_dir")
189
206
 
190
207
  if [ -f "$root_dir/package.json" ]; then
191
- # Drop "." and ".." from the path, the caller compares it with `pwd`
208
+ # Drop "." and ".." from the path. The caller compares it with `pwd`
192
209
  (cd -- "$root_dir" && pwd)
193
210
  return 0
194
211
  fi
@@ -240,13 +257,100 @@ show_config_file() {
240
257
  esac
241
258
  }
242
259
 
260
+ # print_title
261
+ #
262
+ # Print the first line of a summary box: the name and the version.
263
+ print_title() {
264
+ printf '╭───────────┤ %s\n' "${GREEN} VBlocks v${VB_VERSION}${RESET}"
265
+ }
266
+
267
+ # snapshot_folder <dir>
268
+ #
269
+ # Print one line per file in <dir>: its checksum, a tab, its path relative to
270
+ # <dir>. Skip node_modules/, dist/ and .git/. init never writes there, and
271
+ # they can hold thousands of files.
272
+ snapshot_folder() {
273
+ (cd -- "$1" && find . \( -name node_modules -o -name dist -o -name .git \) \
274
+ -prune -o -type f -print) \
275
+ | sed 's|^\./||' \
276
+ | LC_ALL=C sort \
277
+ | while IFS= read -r snapshot_file; do
278
+ printf '%s\t%s\n' "$(cksum < "$1/$snapshot_file")" "$snapshot_file"
279
+ done
280
+ }
281
+
282
+ # print_changes <before-snapshot> <after-snapshot> <app-subdir>
283
+ #
284
+ # Print "add", "update" or "drop" for each file that differs between two
285
+ # snapshots of the project folder. A path inside <app-subdir> prints as
286
+ # $APP_DIR/..., the rest as $PROJECT_DIR/... <app-subdir> is "." when the app
287
+ # is the project folder, empty when there is no app.
288
+ print_changes() {
289
+ # Every snapshot line has a tab. The AFTER line has none, so it marks where
290
+ # the second snapshot starts
291
+ {
292
+ printf '%s\n' "$1"
293
+ printf 'AFTER\n'
294
+ printf '%s\n' "$2"
295
+ } | awk -F '\t' -v app="$3" '
296
+ function label(path) {
297
+ if (app == ".") return "$APP_DIR/" path
298
+ if (app != "" && index(path, app "/") == 1) {
299
+ return "$APP_DIR/" substr(path, length(app) + 2)
300
+ }
301
+ return "$PROJECT_DIR/" path
302
+ }
303
+
304
+ NF < 2 { is_after = 1; next }
305
+ !is_after { before[$2] = $1; next }
306
+ {
307
+ seen[$2] = 1
308
+ if (!($2 in before)) printf "%-8s%s\n", "add", label($2)
309
+ else if (before[$2] != $1) printf "%-8s%s\n", "update", label($2)
310
+ }
311
+ END {
312
+ for (path in before) {
313
+ if (!(path in seen)) printf "%-8s%s\n", "drop", label(path)
314
+ }
315
+ }
316
+ '
317
+ }
318
+
319
+ # print_init_summary <parts> <template> <project-dir> <app-dir>
320
+ #
321
+ # Print the version, the parts of <template> that init writes and their
322
+ # folders, to stderr. <app-dir> is empty when init writes no app.
323
+ print_init_summary() {
324
+ case "$1" in
325
+ plumbing) summary_parts="plumbing" ;;
326
+ app) summary_parts="app, $2" ;;
327
+ *) summary_parts="plumbing and app, $2" ;;
328
+ esac
329
+
330
+ {
331
+ print_title
332
+ printf '│ %s\n' "init: $summary_parts"
333
+ printf '│\n'
334
+
335
+ # When plumbing and app share one folder, print it once, as $APP_DIR
336
+ if [ "$3" != "$4" ]; then
337
+ printf '│ %s\n' "\$PROJECT_DIR: $(shorten_home "$3")"
338
+ fi
339
+ if [ -n "$4" ]; then
340
+ printf '│ %s\n' "\$APP_DIR: $(shorten_home "$4")"
341
+ fi
342
+
343
+ printf '╰──┤\n\n'
344
+ } >&2
345
+ }
346
+
243
347
  # print_summary <app-dir> <webpack-config> <postcss-config> <swc-config>
244
348
  #
245
349
  # Print the version, the app folder and the configs Webpack runs with, to
246
350
  # stderr.
247
351
  print_summary() {
248
352
  {
249
- printf '╭───────────┤ %s\n' "${GREEN} VBlocks v${VB_VERSION}${RESET}"
353
+ print_title
250
354
  printf '│ %s\n' "${BOLD}󱆃 POSIX +  Webpack, an unlikely story!${RESET}"
251
355
  printf '│\n'
252
356
  printf '│ %s\n' "\$APP_DIR: $(shorten_home "$1")"
@@ -277,9 +381,17 @@ run_webpack() {
277
381
  webpack_favicon_file=$(pick_file \
278
382
  "$webpack_app_dir/src/public/favicon.svg" "$VB_DIR/src/public/favicon.svg")
279
383
 
384
+ # npm echoes every npx call at notice, the level between warn and info
385
+ case "$LOG_LEVEL" in
386
+ info) webpack_npm_level="notice" ;;
387
+ *) webpack_npm_level=$LOG_LEVEL ;;
388
+ esac
389
+
280
390
  webpack_status=0
281
- npx webpack "$webpack_action" --config "$webpack_config" \
391
+ npx --loglevel="$webpack_npm_level" webpack "$webpack_action" \
392
+ --config "$webpack_config" \
282
393
  --env "entryDir=$webpack_app_dir" \
394
+ --env "logLevel=$LOG_LEVEL" \
283
395
  --env "robotsPath=$webpack_robots_file" \
284
396
  --env "faviconPath=$webpack_favicon_file" \
285
397
  "$@" || webpack_status=$?
@@ -348,7 +460,7 @@ case "$COMMAND" in
348
460
  --)
349
461
  shift
350
462
  if [ "$#" -ne 1 ] || [ -n "$INIT_DIR" ]; then
351
- fail 2 "init takes one directory"
463
+ fail 2 "init takes one folder"
352
464
  fi
353
465
  INIT_DIR=$1
354
466
  shift
@@ -357,21 +469,30 @@ case "$COMMAND" in
357
469
  fail 2 "Unknown flag $1"
358
470
  ;;
359
471
  *)
360
- [ -n "$INIT_DIR" ] && fail 2 "init takes one directory"
472
+ [ -n "$INIT_DIR" ] && fail 2 "init takes one folder"
361
473
  INIT_DIR=$1
362
474
  shift
363
475
  ;;
364
476
  esac
365
477
  done
366
478
 
367
- [ -z "$INIT_DIR" ] && fail 2 "init needs a directory"
479
+ [ -z "$INIT_DIR" ] && fail 2 "init needs a folder"
480
+
481
+ # One shape for the printed paths: no trailing "/", and no leading "-" that
482
+ # a command would read as a flag
483
+ while [ "$INIT_DIR" != "/" ] && [ "${INIT_DIR%/}" != "$INIT_DIR" ]; do
484
+ INIT_DIR=${INIT_DIR%/}
485
+ done
486
+ case "$INIT_DIR" in
487
+ -*) INIT_DIR="./$INIT_DIR" ;;
488
+ esac
368
489
 
369
490
  if ! list_templates | grep -qxF -- "$TEMPLATE"; then
370
491
  fail 2 "Unknown template \"$TEMPLATE\". Available: $(list_templates | paste -sd ' ' -)"
371
492
  fi
372
493
  ;;
373
494
  serve | build)
374
- # Take the flags of VBlocks out of the arguments, Webpack gets the rest
495
+ # Take the flags of VBlocks out of the arguments. Webpack gets the rest
375
496
  ARG_COUNT=$#
376
497
  while [ "$ARG_COUNT" -gt 0 ]; do
377
498
  ARG=$1
@@ -380,19 +501,30 @@ case "$COMMAND" in
380
501
 
381
502
  case "$ARG" in
382
503
  --prefix)
383
- [ "$ARG_COUNT" -eq 0 ] && fail 2 "--prefix needs a directory"
504
+ [ "$ARG_COUNT" -eq 0 ] && fail 2 "--prefix needs a folder"
384
505
  PREFIX=$1
385
506
  shift
386
507
  ARG_COUNT=$((ARG_COUNT - 1))
387
508
  ;;
509
+ --log-level)
510
+ [ "$ARG_COUNT" -eq 0 ] && fail 2 "--log-level needs a level"
511
+ case "$1" in
512
+ error | warn | info | verbose) LOG_LEVEL=$1 ;;
513
+ *) fail 2 "Unknown level \"$1\", use error, warn, info or verbose" ;;
514
+ esac
515
+ shift
516
+ ARG_COUNT=$((ARG_COUNT - 1))
517
+ ;;
388
518
  --single-file)
389
519
  [ "$COMMAND" = "build" ] || fail 2 "--single-file works only with build"
390
- # webpack.config.js reads env.single, an ejected one too
520
+ # The Webpack config does the work. An ejected config supports the
521
+ # flag only while it reads env.single
391
522
  set -- "$@" --env single
392
523
  ;;
393
524
  --analyze)
394
525
  [ "$COMMAND" = "serve" ] || fail 2 "--analyze works only with serve"
395
- # webpack.config.js reads env.analyze, an ejected one too
526
+ # The Webpack config does the work. An ejected config supports the
527
+ # flag only while it reads env.analyze
396
528
  set -- "$@" --env analyze
397
529
  ;;
398
530
  *)
@@ -402,7 +534,7 @@ case "$COMMAND" in
402
534
  done
403
535
 
404
536
  if [ -n "$PREFIX" ] && [ ! -d "$PREFIX" ]; then
405
- fail 2 "$PREFIX is not a directory"
537
+ fail 2 "$PREFIX is not a folder"
406
538
  fi
407
539
  ;;
408
540
  eject)
@@ -432,32 +564,58 @@ case "$COMMAND" in
432
564
  fi
433
565
  fi
434
566
 
435
- # An app joins a project, the app hooks write its package.json
436
- PROJECT_ROOT=""
567
+ # An app needs a project folder. The app hooks write to its package.json
568
+ PROJECT_DIR=""
437
569
  if [ "$PARTS" = "app" ]; then
438
- PROJECT_ROOT=$(find_project_root "$INIT_DIR") \
570
+ PROJECT_DIR=$(find_project_root "$INIT_DIR") \
439
571
  || fail 3 "No package.json above $INIT_DIR. Write the project first: npx @asd14/vblocks init <directory> --only plumbing"
440
572
  fi
441
573
 
442
- mkdir -p -- "$INIT_DIR" || fail 3 "Could not create $INIT_DIR"
574
+ mkdir -p -- "$INIT_DIR" || fail 3 "Could not add $INIT_DIR"
575
+ INIT_ABS_DIR=$(cd -- "$INIT_DIR" && pwd)
576
+
577
+ case "$PARTS" in
578
+ plumbing)
579
+ PROJECT_DIR=$INIT_ABS_DIR
580
+ APP_DIR=""
581
+ APP_SUBDIR=""
582
+ ;;
583
+ app)
584
+ APP_DIR=$INIT_ABS_DIR
585
+ APP_SUBDIR=${APP_DIR#"$PROJECT_DIR"/}
586
+ ;;
587
+ *)
588
+ PROJECT_DIR=$INIT_ABS_DIR
589
+ APP_DIR=$INIT_ABS_DIR
590
+ APP_SUBDIR="."
591
+ ;;
592
+ esac
593
+
594
+ BEFORE_SNAPSHOT=$(snapshot_folder "$PROJECT_DIR")
443
595
  init_project "$INIT_DIR" "$TEMPLATE" "$PARTS"
596
+ AFTER_SNAPSHOT=$(snapshot_folder "$PROJECT_DIR")
597
+
598
+ print_init_summary "$PARTS" "$TEMPLATE" "$PROJECT_DIR" "$APP_DIR"
599
+ print_changes "$BEFORE_SNAPSHOT" "$AFTER_SNAPSHOT" "$APP_SUBDIR"
444
600
 
445
601
  case "$PARTS" in
446
602
  plumbing)
447
- printf 'Wrote %s. Add an app:\n\n' "$INIT_DIR" >&2
448
- printf ' npx @asd14/vblocks init %s/<app> --only app\n' "$INIT_DIR" >&2
603
+ printf '\nNext, add an app:\n\n'
604
+ printf ' npx @asd14/vblocks init %s/<app> --only app\n' "$INIT_DIR"
449
605
  ;;
450
606
  app)
451
- APP_DIR=$(cd -- "$INIT_DIR" && pwd)
452
- printf 'Wrote %s. Next, in %s:\n\n' "$INIT_DIR" "$PROJECT_ROOT" >&2
453
- printf ' npm install\n' >&2
454
- printf ' npm start -- --prefix %s\n' "${APP_DIR#"$PROJECT_ROOT"/}" >&2
607
+ printf '\nNext:\n\n'
608
+ if [ "$PROJECT_DIR" != "$PWD" ]; then
609
+ printf ' cd %s\n' "$(shorten_path "$PROJECT_DIR")"
610
+ fi
611
+ printf ' npm install\n'
612
+ printf ' npx vblocks serve --prefix %s\n' "$APP_SUBDIR"
455
613
  ;;
456
614
  *)
457
- printf 'Wrote %s. Next:\n\n' "$INIT_DIR" >&2
458
- printf ' cd %s\n' "$INIT_DIR" >&2
459
- printf ' npm install\n' >&2
460
- printf ' npm start\n' >&2
615
+ printf '\nNext:\n\n'
616
+ printf ' cd %s\n' "$INIT_DIR"
617
+ printf ' npm install\n'
618
+ printf ' npx vblocks serve\n'
461
619
  ;;
462
620
  esac
463
621
  exit 0
@@ -474,7 +632,7 @@ case "$COMMAND" in
474
632
  print_summary "$APP_DIR" "$WEBPACK_CONFIG" "$VB_POSTCSS_CONFIG" "$VB_SWC_CONFIG"
475
633
 
476
634
  # Without a mode, Webpack takes `production`, also for `serve`. A --mode in
477
- # "$@" comes later, so it wins
635
+ # "$@" comes later, so it overrides this one
478
636
  if [ "$COMMAND" = "build" ]; then
479
637
  run_webpack build "$APP_DIR" "$WEBPACK_CONFIG" --mode production "$@"
480
638
  else
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": "4.0.0",
4
+ "version": "5.0.0",
5
5
  "description": "Zero-config React builds, as a static site or a single HTML file",
6
6
  "keywords": [
7
7
  "react",
@@ -149,8 +149,19 @@ const inlineAssets = compiler => {
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
151
  * @property {boolean} [analyze] - Run the bundle analyzer next to the dev server
152
+ * @property {"error"|"warn"|"info"|"verbose"} [logLevel] - How much Webpack and its dev server print
152
153
  */
153
154
 
155
+ /**
156
+ * The stats preset of Webpack for each log level of VBlocks
157
+ */
158
+ const STATS_BY_LOG_LEVEL = /** @type {const} */ ({
159
+ error: "errors-only",
160
+ warn: "errors-warnings",
161
+ info: "normal",
162
+ verbose: "verbose",
163
+ })
164
+
154
165
  /**
155
166
  * @typedef {Object} VBlocksProps
156
167
  *
@@ -163,7 +174,7 @@ const inlineAssets = compiler => {
163
174
  * @returns {WebpackConfiguration}
164
175
  */
165
176
  export default (
166
- { entryDir, robotsPath, faviconPath, single, analyze },
177
+ { entryDir, robotsPath, faviconPath, single, analyze, logLevel = "warn" },
167
178
  { mode }
168
179
  ) => {
169
180
  const isProduction = mode === "production"
@@ -195,8 +206,9 @@ export default (
195
206
 
196
207
  mode: mode,
197
208
 
198
- // Keep the summary of VBlocks on screen, `--stats` overrides it
199
- stats: "errors-warnings",
209
+ // Keep the summary of VBlocks on screen. `--log-level` sets it, `--stats`
210
+ // overrides it
211
+ stats: STATS_BY_LOG_LEVEL[logLevel],
200
212
 
201
213
  output: {
202
214
  // A standalone file opens from disk, where "/" is the filesystem root
@@ -339,12 +351,43 @@ export default (
339
351
 
340
352
  // Tells dev-server to open the browser after server had been started.
341
353
  open: true,
354
+
355
+ // Only this machine opens the page. `--host 0.0.0.0` exposes it to
356
+ // the network, eg. for a phone
357
+ host: "localhost",
358
+
359
+ // Serve only what Webpack builds, not a public/ folder in the
360
+ // folder VBlocks runs in
361
+ static: false,
362
+
363
+ // Print the URL once, as the result of serve. The startup lines of
364
+ // the dev server stay hidden, see infrastructureLogging
365
+ onListening: developmentServer => {
366
+ const address = developmentServer.server?.address()
367
+
368
+ // A TCP server gives an object, a pipe server gives a string
369
+ if (typeof address !== "object" || address === null) return
370
+
371
+ const { port } = address
372
+ process.stdout.write(`Local: http://localhost:${port}\n`)
373
+
374
+ if (developmentServer.options.host !== "localhost") {
375
+ process.stdout.write(
376
+ `Network: ${developmentServer.options.host}:${port}\n`
377
+ )
378
+ }
379
+ },
380
+
342
381
  client: {
343
382
  overlay: true,
344
383
  },
345
384
  }
346
385
  : undefined,
347
386
 
387
+ // At warn, hide the info lines of the dev server, and of the client in the
388
+ // browser console
389
+ infrastructureLogging: { level: logLevel },
390
+
348
391
  plugins: [
349
392
  new HtmlWebPackPlugin({
350
393
  template: paths.htmlTemplate,