@asd14/vblocks 3.1.0 β 4.1.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 +54 -16
- package/bin/vblocks.sh +182 -38
- package/package.json +16 -2
- package/src/webpack.config.js +14 -2
package/README.md
CHANGED
|
@@ -3,12 +3,33 @@
|
|
|
3
3
|
|
|
4
4
|
# @asd14/vblocks
|
|
5
5
|
|
|
6
|
-
>
|
|
6
|
+
> Zero-config React builds, as a static site or a single HTML file
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
173
|
-
`.env` does not set
|
|
174
|
-
|
|
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
|
|
@@ -256,6 +282,11 @@ Each of these configs in your app folder replaces the default of the same name:
|
|
|
256
282
|
> - `.swcrc -> jsc.transform.react.refresh`: VBlocks adds the React Refresh
|
|
257
283
|
> transform when `serve` runs in `development` mode
|
|
258
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
|
+
|
|
259
290
|
### Style with Tailwind
|
|
260
291
|
|
|
261
292
|
VBlocks does not include Tailwind. Add it through a `postcss.config.js` in your
|
|
@@ -358,12 +389,17 @@ vblocks init <directory> [--template <name>] [--only <app|plumbing>]
|
|
|
358
389
|
- `--only <app|plumbing>`\
|
|
359
390
|
Write one part of the template (default: both)
|
|
360
391
|
- `plumbing`: `package.json`, `.gitignore`
|
|
361
|
-
- `app`: `src/`, `tsconfig.json` and the template's configs.
|
|
362
|
-
|
|
363
|
-
|
|
392
|
+
- `app`: `src/`, `tsconfig.json` and the template's configs. `init` adds the
|
|
393
|
+
template's dependencies to the nearest `package.json` above `<directory>`.
|
|
394
|
+
Without one, `init` fails
|
|
364
395
|
|
|
365
396
|
**Example**:
|
|
366
397
|
|
|
398
|
+
<!--
|
|
399
|
+
Using the `my-vblock-` prefix, so a reader who tries several scaffolders spots
|
|
400
|
+
the folder at a glance, as with `vite-project` and `nuxt-app`.
|
|
401
|
+
-->
|
|
402
|
+
|
|
367
403
|
```sh
|
|
368
404
|
npx @asd14/vblocks init my-vblock-flow --template xyflow
|
|
369
405
|
cd my-vblock-flow
|
|
@@ -374,11 +410,11 @@ npm install
|
|
|
374
410
|
|
|
375
411
|
Start the development server.
|
|
376
412
|
|
|
377
|
-
-
|
|
378
|
-
-
|
|
413
|
+
- Runs at `http://localhost:8080`, or the next free port
|
|
414
|
+
- Opens the page in the browser
|
|
379
415
|
|
|
380
416
|
```text
|
|
381
|
-
vblocks serve [--mode <mode>] [--prefix <directory>] [<webpack option>...]
|
|
417
|
+
vblocks serve [--mode <mode>] [--prefix <directory>] [--analyze] [<webpack option>...]
|
|
382
418
|
```
|
|
383
419
|
|
|
384
420
|
- `--mode <mode>`\
|
|
@@ -386,6 +422,8 @@ vblocks serve [--mode <mode>] [--prefix <directory>] [<webpack option>...]
|
|
|
386
422
|
React Refresh runs only in `development`
|
|
387
423
|
- `--prefix <directory>`\
|
|
388
424
|
The [app folder](#vocabulary), which must exist (default: the current folder)
|
|
425
|
+
- `--analyze`\
|
|
426
|
+
Run the bundle analyzer, on a free port
|
|
389
427
|
- `<webpack option>`\
|
|
390
428
|
Any other [`webpack serve`](https://webpack.js.org/api/cli/) option. VBlocks
|
|
391
429
|
passes it to Webpack unchanged
|
|
@@ -417,8 +455,8 @@ vblocks build [--mode <mode>] [--prefix <directory>] [--single-file] [<webpack o
|
|
|
417
455
|
|
|
418
456
|
- `--mode <mode>`\
|
|
419
457
|
The Webpack mode, `development` or `production` (default: `production`). In
|
|
420
|
-
`production`, the build minifies JS and HTML, and the default
|
|
421
|
-
minifies CSS
|
|
458
|
+
`production`, the build minifies JS and HTML, and cssnano, in the default
|
|
459
|
+
PostCSS config, minifies CSS
|
|
422
460
|
- `--prefix <directory>`\
|
|
423
461
|
The [app folder](#vocabulary), which must exist (default: the current folder)
|
|
424
462
|
- `--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>] [
|
|
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>
|
|
@@ -19,9 +20,11 @@ set -eu
|
|
|
19
20
|
# VBlocks with the same name.
|
|
20
21
|
#
|
|
21
22
|
# init Write a template into <directory>, which must be missing or
|
|
22
|
-
# empty. A template has two parts: the plumbing,
|
|
23
|
-
# the project folder, and the app. Without --only,
|
|
24
|
-
#
|
|
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
|
|
25
28
|
# serve Start the development server
|
|
26
29
|
# build Build the app into dist/ in the app folder
|
|
27
30
|
# eject Print a default config, to save in the app folder
|
|
@@ -31,9 +34,9 @@ set -eu
|
|
|
31
34
|
# OPTIONS
|
|
32
35
|
# --template <name> init: plain or xyflow (default: plain)
|
|
33
36
|
# --only <app|plumbing> init: write only the app or only the plumbing.
|
|
34
|
-
#
|
|
35
|
-
# folder: the nearest folder above
|
|
36
|
-
# 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
|
|
37
40
|
# --mode <mode> serve, build: the Webpack mode, development or
|
|
38
41
|
# production (default: development for serve,
|
|
39
42
|
# production for build)
|
|
@@ -41,11 +44,11 @@ set -eu
|
|
|
41
44
|
# current folder)
|
|
42
45
|
# --single-file build: one standalone dist/index.html, every
|
|
43
46
|
# asset inlined
|
|
47
|
+
# --analyze serve: run the bundle analyzer, on a free port
|
|
44
48
|
# -h, --help Print this help
|
|
45
49
|
#
|
|
46
50
|
# ENVIRONMENT
|
|
47
|
-
# NO_COLOR
|
|
48
|
-
# non-empty
|
|
51
|
+
# NO_COLOR When set and non-empty, print every summary without color
|
|
49
52
|
#
|
|
50
53
|
# EXAMPLE
|
|
51
54
|
# npx @asd14/vblocks init my-app
|
|
@@ -57,8 +60,8 @@ set -eu
|
|
|
57
60
|
# EXIT CODES
|
|
58
61
|
# 0 Done
|
|
59
62
|
# 2 Invalid usage, or Webpack rejected an option or the config
|
|
60
|
-
# 3 Could not run: a missing tool or project, a failed copy,
|
|
61
|
-
# build
|
|
63
|
+
# 3 Could not run: a missing tool or project, or a failed folder, copy,
|
|
64
|
+
# hook or build
|
|
62
65
|
#
|
|
63
66
|
# SEE ALSO
|
|
64
67
|
# webpack, npm
|
|
@@ -116,7 +119,7 @@ require_cmd() {
|
|
|
116
119
|
#
|
|
117
120
|
# RETURNS
|
|
118
121
|
# 0 stderr is a terminal that shows color
|
|
119
|
-
# 1 It is not, or
|
|
122
|
+
# 1 It is not, NO_COLOR is non-empty, or TERM is dumb or unset
|
|
120
123
|
has_color() {
|
|
121
124
|
[ -t 2 ] && [ -z "${NO_COLOR:-}" ] && [ "${TERM:-dumb}" != "dumb" ]
|
|
122
125
|
}
|
|
@@ -149,6 +152,18 @@ shorten_home() {
|
|
|
149
152
|
printf '%s\n' "$1"
|
|
150
153
|
}
|
|
151
154
|
|
|
155
|
+
# shorten_path <absolute-path>
|
|
156
|
+
#
|
|
157
|
+
# Print <absolute-path> relative to the current folder when it is inside it,
|
|
158
|
+
# otherwise with the home folder as "~".
|
|
159
|
+
shorten_path() {
|
|
160
|
+
case "$1" in
|
|
161
|
+
"$PWD") printf '.\n' ;;
|
|
162
|
+
"$PWD"/*) printf '%s\n' "${1#"$PWD"/}" ;;
|
|
163
|
+
*) shorten_home "$1" ;;
|
|
164
|
+
esac
|
|
165
|
+
}
|
|
166
|
+
|
|
152
167
|
# ββββ
|
|
153
168
|
# β Domain primitives
|
|
154
169
|
# β°βββ
|
|
@@ -171,8 +186,8 @@ list_templates() {
|
|
|
171
186
|
|
|
172
187
|
# find_project_root <directory>
|
|
173
188
|
#
|
|
174
|
-
# Print the nearest folder above <directory> that holds a package.json.
|
|
175
|
-
#
|
|
189
|
+
# Print the nearest folder above <directory> that holds a package.json.
|
|
190
|
+
# <directory> and the folders above it need not exist yet.
|
|
176
191
|
#
|
|
177
192
|
# RETURNS
|
|
178
193
|
# 1 No folder above <directory> holds one
|
|
@@ -186,7 +201,7 @@ find_project_root() {
|
|
|
186
201
|
root_dir=$(dirname "$root_dir")
|
|
187
202
|
|
|
188
203
|
if [ -f "$root_dir/package.json" ]; then
|
|
189
|
-
# Drop "." and ".." from the path
|
|
204
|
+
# Drop "." and ".." from the path. The caller compares it with `pwd`
|
|
190
205
|
(cd -- "$root_dir" && pwd)
|
|
191
206
|
return 0
|
|
192
207
|
fi
|
|
@@ -238,13 +253,100 @@ show_config_file() {
|
|
|
238
253
|
esac
|
|
239
254
|
}
|
|
240
255
|
|
|
256
|
+
# print_title
|
|
257
|
+
#
|
|
258
|
+
# Print the first line of a summary box: the name and the version.
|
|
259
|
+
print_title() {
|
|
260
|
+
printf 'βββββββββββββ€ %s\n' "${GREEN}ο VBlocks v${VB_VERSION}${RESET}"
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
# snapshot_folder <dir>
|
|
264
|
+
#
|
|
265
|
+
# Print one line per file in <dir>: its checksum, a tab, its path relative to
|
|
266
|
+
# <dir>. Skip node_modules/, dist/ and .git/. init never writes there, and
|
|
267
|
+
# they can hold thousands of files.
|
|
268
|
+
snapshot_folder() {
|
|
269
|
+
(cd -- "$1" && find . \( -name node_modules -o -name dist -o -name .git \) \
|
|
270
|
+
-prune -o -type f -print) \
|
|
271
|
+
| sed 's|^\./||' \
|
|
272
|
+
| LC_ALL=C sort \
|
|
273
|
+
| while IFS= read -r snapshot_file; do
|
|
274
|
+
printf '%s\t%s\n' "$(cksum < "$1/$snapshot_file")" "$snapshot_file"
|
|
275
|
+
done
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
# print_changes <before-snapshot> <after-snapshot> <app-subdir>
|
|
279
|
+
#
|
|
280
|
+
# Print "add", "update" or "drop" for each file that differs between two
|
|
281
|
+
# snapshots of the project folder. A path inside <app-subdir> prints as
|
|
282
|
+
# $APP_DIR/..., the rest as $PROJECT_DIR/... <app-subdir> is "." when the app
|
|
283
|
+
# is the project folder, empty when there is no app.
|
|
284
|
+
print_changes() {
|
|
285
|
+
# Every snapshot line has a tab. The AFTER line has none, so it marks where
|
|
286
|
+
# the second snapshot starts
|
|
287
|
+
{
|
|
288
|
+
printf '%s\n' "$1"
|
|
289
|
+
printf 'AFTER\n'
|
|
290
|
+
printf '%s\n' "$2"
|
|
291
|
+
} | awk -F '\t' -v app="$3" '
|
|
292
|
+
function label(path) {
|
|
293
|
+
if (app == ".") return "$APP_DIR/" path
|
|
294
|
+
if (app != "" && index(path, app "/") == 1) {
|
|
295
|
+
return "$APP_DIR/" substr(path, length(app) + 2)
|
|
296
|
+
}
|
|
297
|
+
return "$PROJECT_DIR/" path
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
NF < 2 { is_after = 1; next }
|
|
301
|
+
!is_after { before[$2] = $1; next }
|
|
302
|
+
{
|
|
303
|
+
seen[$2] = 1
|
|
304
|
+
if (!($2 in before)) printf "%-8s%s\n", "add", label($2)
|
|
305
|
+
else if (before[$2] != $1) printf "%-8s%s\n", "update", label($2)
|
|
306
|
+
}
|
|
307
|
+
END {
|
|
308
|
+
for (path in before) {
|
|
309
|
+
if (!(path in seen)) printf "%-8s%s\n", "drop", label(path)
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
'
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
# print_init_summary <parts> <template> <project-dir> <app-dir>
|
|
316
|
+
#
|
|
317
|
+
# Print the version, the parts of <template> that init writes and their
|
|
318
|
+
# folders, to stderr. <app-dir> is empty when init writes no app.
|
|
319
|
+
print_init_summary() {
|
|
320
|
+
case "$1" in
|
|
321
|
+
plumbing) summary_parts="plumbing" ;;
|
|
322
|
+
app) summary_parts="app, $2" ;;
|
|
323
|
+
*) summary_parts="plumbing and app, $2" ;;
|
|
324
|
+
esac
|
|
325
|
+
|
|
326
|
+
{
|
|
327
|
+
print_title
|
|
328
|
+
printf 'β %s\n' "init: $summary_parts"
|
|
329
|
+
printf 'β\n'
|
|
330
|
+
|
|
331
|
+
# When plumbing and app share one folder, print it once, as $APP_DIR
|
|
332
|
+
if [ "$3" != "$4" ]; then
|
|
333
|
+
printf 'β %s\n' "\$PROJECT_DIR: $(shorten_home "$3")"
|
|
334
|
+
fi
|
|
335
|
+
if [ -n "$4" ]; then
|
|
336
|
+
printf 'β %s\n' "\$APP_DIR: $(shorten_home "$4")"
|
|
337
|
+
fi
|
|
338
|
+
|
|
339
|
+
printf 'β°βββ€\n\n'
|
|
340
|
+
} >&2
|
|
341
|
+
}
|
|
342
|
+
|
|
241
343
|
# print_summary <app-dir> <webpack-config> <postcss-config> <swc-config>
|
|
242
344
|
#
|
|
243
345
|
# Print the version, the app folder and the configs Webpack runs with, to
|
|
244
346
|
# stderr.
|
|
245
347
|
print_summary() {
|
|
246
348
|
{
|
|
247
|
-
|
|
349
|
+
print_title
|
|
248
350
|
printf 'β %s\n' "${BOLD}σ± POSIX + ξ££ Webpack, an unlikely story!${RESET}"
|
|
249
351
|
printf 'β\n'
|
|
250
352
|
printf 'β %s\n' "\$APP_DIR: $(shorten_home "$1")"
|
|
@@ -346,7 +448,7 @@ case "$COMMAND" in
|
|
|
346
448
|
--)
|
|
347
449
|
shift
|
|
348
450
|
if [ "$#" -ne 1 ] || [ -n "$INIT_DIR" ]; then
|
|
349
|
-
fail 2 "init takes one
|
|
451
|
+
fail 2 "init takes one folder"
|
|
350
452
|
fi
|
|
351
453
|
INIT_DIR=$1
|
|
352
454
|
shift
|
|
@@ -355,21 +457,30 @@ case "$COMMAND" in
|
|
|
355
457
|
fail 2 "Unknown flag $1"
|
|
356
458
|
;;
|
|
357
459
|
*)
|
|
358
|
-
[ -n "$INIT_DIR" ] && fail 2 "init takes one
|
|
460
|
+
[ -n "$INIT_DIR" ] && fail 2 "init takes one folder"
|
|
359
461
|
INIT_DIR=$1
|
|
360
462
|
shift
|
|
361
463
|
;;
|
|
362
464
|
esac
|
|
363
465
|
done
|
|
364
466
|
|
|
365
|
-
[ -z "$INIT_DIR" ] && fail 2 "init needs a
|
|
467
|
+
[ -z "$INIT_DIR" ] && fail 2 "init needs a folder"
|
|
468
|
+
|
|
469
|
+
# One shape for the printed paths: no trailing "/", and no leading "-" that
|
|
470
|
+
# a command would read as a flag
|
|
471
|
+
while [ "$INIT_DIR" != "/" ] && [ "${INIT_DIR%/}" != "$INIT_DIR" ]; do
|
|
472
|
+
INIT_DIR=${INIT_DIR%/}
|
|
473
|
+
done
|
|
474
|
+
case "$INIT_DIR" in
|
|
475
|
+
-*) INIT_DIR="./$INIT_DIR" ;;
|
|
476
|
+
esac
|
|
366
477
|
|
|
367
478
|
if ! list_templates | grep -qxF -- "$TEMPLATE"; then
|
|
368
479
|
fail 2 "Unknown template \"$TEMPLATE\". Available: $(list_templates | paste -sd ' ' -)"
|
|
369
480
|
fi
|
|
370
481
|
;;
|
|
371
482
|
serve | build)
|
|
372
|
-
# Take the flags of VBlocks out of the arguments
|
|
483
|
+
# Take the flags of VBlocks out of the arguments. Webpack gets the rest
|
|
373
484
|
ARG_COUNT=$#
|
|
374
485
|
while [ "$ARG_COUNT" -gt 0 ]; do
|
|
375
486
|
ARG=$1
|
|
@@ -378,16 +489,23 @@ case "$COMMAND" in
|
|
|
378
489
|
|
|
379
490
|
case "$ARG" in
|
|
380
491
|
--prefix)
|
|
381
|
-
[ "$ARG_COUNT" -eq 0 ] && fail 2 "--prefix needs a
|
|
492
|
+
[ "$ARG_COUNT" -eq 0 ] && fail 2 "--prefix needs a folder"
|
|
382
493
|
PREFIX=$1
|
|
383
494
|
shift
|
|
384
495
|
ARG_COUNT=$((ARG_COUNT - 1))
|
|
385
496
|
;;
|
|
386
497
|
--single-file)
|
|
387
498
|
[ "$COMMAND" = "build" ] || fail 2 "--single-file works only with build"
|
|
388
|
-
#
|
|
499
|
+
# The Webpack config does the work. An ejected config supports the
|
|
500
|
+
# flag only while it reads env.single
|
|
389
501
|
set -- "$@" --env single
|
|
390
502
|
;;
|
|
503
|
+
--analyze)
|
|
504
|
+
[ "$COMMAND" = "serve" ] || fail 2 "--analyze works only with serve"
|
|
505
|
+
# The Webpack config does the work. An ejected config supports the
|
|
506
|
+
# flag only while it reads env.analyze
|
|
507
|
+
set -- "$@" --env analyze
|
|
508
|
+
;;
|
|
391
509
|
*)
|
|
392
510
|
set -- "$@" "$ARG"
|
|
393
511
|
;;
|
|
@@ -395,7 +513,7 @@ case "$COMMAND" in
|
|
|
395
513
|
done
|
|
396
514
|
|
|
397
515
|
if [ -n "$PREFIX" ] && [ ! -d "$PREFIX" ]; then
|
|
398
|
-
fail 2 "$PREFIX is not a
|
|
516
|
+
fail 2 "$PREFIX is not a folder"
|
|
399
517
|
fi
|
|
400
518
|
;;
|
|
401
519
|
eject)
|
|
@@ -425,32 +543,58 @@ case "$COMMAND" in
|
|
|
425
543
|
fi
|
|
426
544
|
fi
|
|
427
545
|
|
|
428
|
-
# An app
|
|
429
|
-
|
|
546
|
+
# An app needs a project folder. The app hooks write to its package.json
|
|
547
|
+
PROJECT_DIR=""
|
|
430
548
|
if [ "$PARTS" = "app" ]; then
|
|
431
|
-
|
|
549
|
+
PROJECT_DIR=$(find_project_root "$INIT_DIR") \
|
|
432
550
|
|| fail 3 "No package.json above $INIT_DIR. Write the project first: npx @asd14/vblocks init <directory> --only plumbing"
|
|
433
551
|
fi
|
|
434
552
|
|
|
435
|
-
mkdir -p -- "$INIT_DIR" || fail 3 "Could not
|
|
553
|
+
mkdir -p -- "$INIT_DIR" || fail 3 "Could not add $INIT_DIR"
|
|
554
|
+
INIT_ABS_DIR=$(cd -- "$INIT_DIR" && pwd)
|
|
555
|
+
|
|
556
|
+
case "$PARTS" in
|
|
557
|
+
plumbing)
|
|
558
|
+
PROJECT_DIR=$INIT_ABS_DIR
|
|
559
|
+
APP_DIR=""
|
|
560
|
+
APP_SUBDIR=""
|
|
561
|
+
;;
|
|
562
|
+
app)
|
|
563
|
+
APP_DIR=$INIT_ABS_DIR
|
|
564
|
+
APP_SUBDIR=${APP_DIR#"$PROJECT_DIR"/}
|
|
565
|
+
;;
|
|
566
|
+
*)
|
|
567
|
+
PROJECT_DIR=$INIT_ABS_DIR
|
|
568
|
+
APP_DIR=$INIT_ABS_DIR
|
|
569
|
+
APP_SUBDIR="."
|
|
570
|
+
;;
|
|
571
|
+
esac
|
|
572
|
+
|
|
573
|
+
BEFORE_SNAPSHOT=$(snapshot_folder "$PROJECT_DIR")
|
|
436
574
|
init_project "$INIT_DIR" "$TEMPLATE" "$PARTS"
|
|
575
|
+
AFTER_SNAPSHOT=$(snapshot_folder "$PROJECT_DIR")
|
|
576
|
+
|
|
577
|
+
print_init_summary "$PARTS" "$TEMPLATE" "$PROJECT_DIR" "$APP_DIR"
|
|
578
|
+
print_changes "$BEFORE_SNAPSHOT" "$AFTER_SNAPSHOT" "$APP_SUBDIR"
|
|
437
579
|
|
|
438
580
|
case "$PARTS" in
|
|
439
581
|
plumbing)
|
|
440
|
-
printf '
|
|
441
|
-
printf ' npx @asd14/vblocks init %s/<app> --only app\n' "$INIT_DIR"
|
|
582
|
+
printf '\nNext, add an app:\n\n'
|
|
583
|
+
printf ' npx @asd14/vblocks init %s/<app> --only app\n' "$INIT_DIR"
|
|
442
584
|
;;
|
|
443
585
|
app)
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
586
|
+
printf '\nNext:\n\n'
|
|
587
|
+
if [ "$PROJECT_DIR" != "$PWD" ]; then
|
|
588
|
+
printf ' cd %s\n' "$(shorten_path "$PROJECT_DIR")"
|
|
589
|
+
fi
|
|
590
|
+
printf ' npm install\n'
|
|
591
|
+
printf ' npx vblocks serve --prefix %s\n' "$APP_SUBDIR"
|
|
448
592
|
;;
|
|
449
593
|
*)
|
|
450
|
-
printf '
|
|
451
|
-
printf ' cd %s\n' "$INIT_DIR"
|
|
452
|
-
printf ' npm install\n'
|
|
453
|
-
printf '
|
|
594
|
+
printf '\nNext:\n\n'
|
|
595
|
+
printf ' cd %s\n' "$INIT_DIR"
|
|
596
|
+
printf ' npm install\n'
|
|
597
|
+
printf ' npx vblocks serve\n'
|
|
454
598
|
;;
|
|
455
599
|
esac
|
|
456
600
|
exit 0
|
|
@@ -467,7 +611,7 @@ case "$COMMAND" in
|
|
|
467
611
|
print_summary "$APP_DIR" "$WEBPACK_CONFIG" "$VB_POSTCSS_CONFIG" "$VB_SWC_CONFIG"
|
|
468
612
|
|
|
469
613
|
# Without a mode, Webpack takes `production`, also for `serve`. A --mode in
|
|
470
|
-
# "$@" comes later, so it
|
|
614
|
+
# "$@" comes later, so it overrides this one
|
|
471
615
|
if [ "$COMMAND" = "build" ]; then
|
|
472
616
|
run_webpack build "$APP_DIR" "$WEBPACK_CONFIG" --mode production "$@"
|
|
473
617
|
else
|
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": "
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "4.1.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": {
|
package/src/webpack.config.js
CHANGED
|
@@ -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 (
|
|
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
|
-
|
|
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(),
|