@asd14/vblocks 4.1.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
@@ -411,10 +411,11 @@ npm install
411
411
  Start the development server.
412
412
 
413
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
414
415
  - Opens the page in the browser
415
416
 
416
417
  ```text
417
- vblocks serve [--mode <mode>] [--prefix <directory>] [--analyze] [<webpack option>...]
418
+ vblocks serve [--mode <mode>] [--prefix <directory>] [--analyze] [--log-level <level>] [<webpack option>...]
418
419
  ```
419
420
 
420
421
  - `--mode <mode>`\
@@ -424,6 +425,9 @@ vblocks serve [--mode <mode>] [--prefix <directory>] [--analyze] [<webpack optio
424
425
  The [app folder](#vocabulary), which must exist (default: the current folder)
425
426
  - `--analyze`\
426
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`)
427
431
  - `<webpack option>`\
428
432
  Any other [`webpack serve`](https://webpack.js.org/api/cli/) option. VBlocks
429
433
  passes it to Webpack unchanged
@@ -450,7 +454,7 @@ build:
450
454
  total over 20 KB (10 KB in `development`)
451
455
 
452
456
  ```text
453
- vblocks build [--mode <mode>] [--prefix <directory>] [--single-file] [<webpack option>...]
457
+ vblocks build [--mode <mode>] [--prefix <directory>] [--single-file] [--log-level <level>] [<webpack option>...]
454
458
  ```
455
459
 
456
460
  - `--mode <mode>`\
@@ -465,6 +469,9 @@ vblocks build [--mode <mode>] [--prefix <directory>] [--single-file] [<webpack o
465
469
  - The build leaves `robots.txt` out
466
470
  - Keep the route in the URL hash. On `file://`, `history.pushState` to another
467
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`)
468
475
  - `<webpack option>`\
469
476
  Any other [`webpack build`](https://webpack.js.org/api/cli/) option, eg.
470
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
  #
@@ -45,6 +45,9 @@ set -eu
45
45
  # --single-file build: one standalone dist/index.html, every
46
46
  # asset inlined
47
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)
48
51
  # -h, --help Print this help
49
52
  #
50
53
  # ENVIRONMENT
@@ -83,6 +86,7 @@ INIT_DIR="" # init <directory>
83
86
  TEMPLATE="plain" # init --template
84
87
  PARTS="plumbing app" # init --only, "plumbing" or "app"
85
88
  PREFIX="" # serve/build --prefix, the app folder
89
+ LOG_LEVEL="warn" # serve/build --log-level, error, warn, info or verbose
86
90
  EJECT_CONFIG="" # eject <config>
87
91
 
88
92
  # ╭───
@@ -377,9 +381,17 @@ run_webpack() {
377
381
  webpack_favicon_file=$(pick_file \
378
382
  "$webpack_app_dir/src/public/favicon.svg" "$VB_DIR/src/public/favicon.svg")
379
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
+
380
390
  webpack_status=0
381
- npx webpack "$webpack_action" --config "$webpack_config" \
391
+ npx --loglevel="$webpack_npm_level" webpack "$webpack_action" \
392
+ --config "$webpack_config" \
382
393
  --env "entryDir=$webpack_app_dir" \
394
+ --env "logLevel=$LOG_LEVEL" \
383
395
  --env "robotsPath=$webpack_robots_file" \
384
396
  --env "faviconPath=$webpack_favicon_file" \
385
397
  "$@" || webpack_status=$?
@@ -494,6 +506,15 @@ case "$COMMAND" in
494
506
  shift
495
507
  ARG_COUNT=$((ARG_COUNT - 1))
496
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
+ ;;
497
518
  --single-file)
498
519
  [ "$COMMAND" = "build" ] || fail 2 "--single-file works only with build"
499
520
  # The Webpack config does the work. An ejected config supports the
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.1.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,