@asd14/vblocks 5.4.0 → 6.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 +52 -56
- package/bin/vblocks +71 -0
- package/bin/vblocks.d/build +193 -0
- package/bin/vblocks.d/eject +69 -0
- package/bin/vblocks.d/init +337 -0
- package/bin/vblocks.d/lib.sh +569 -0
- package/bin/vblocks.d/serve +149 -0
- package/bin/vblocks.d/vblocks.sh +95 -0
- package/bin/vblocks.d/webpack.sh +120 -0
- package/defaults/postcss.config.js +14 -0
- package/{src → defaults}/webpack.config.js +40 -21
- package/package.json +18 -14
- package/template/xyflow/app/postcss.config.js +9 -8
- package/template/xyflow/app/src/diagram.tsx +0 -2
- package/template/xyflow/post-init-app.sh +1 -0
- package/template/xyflow-tabs/app/postcss.config.js +9 -8
- package/template/xyflow-tabs/post-init-app.sh +1 -0
- package/{src/types → types}/client.d.ts +20 -1
- package/bin/vblocks.sh +0 -685
- package/src/postcss.config.js +0 -13
- package/template/xyflow/app/src/ui/zoom-level.tsx +0 -29
- /package/{src → defaults}/.swcrc +0 -0
- /package/{src → defaults/src}/public/favicon.svg +0 -0
- /package/{src → defaults/src}/public/robots.txt +0 -0
package/README.md
CHANGED
|
@@ -153,7 +153,7 @@ Several apps, eg. demos or MVP sketches, can share one `package.json` and one
|
|
|
153
153
|
+ │ ├─ postcss.config.js
|
|
154
154
|
+ │ └─ tsconfig.json
|
|
155
155
|
├─ .gitignore
|
|
156
|
-
! └─ package.json # + @xyflow/react, tailwindcss, @tailwindcss/postcss
|
|
156
|
+
! └─ package.json # + @xyflow/react, tailwindcss, @tailwindcss/postcss, cssnano
|
|
157
157
|
```
|
|
158
158
|
|
|
159
159
|
3. **Start a development server for one app**
|
|
@@ -206,8 +206,8 @@ variable your code does not read.
|
|
|
206
206
|
> the page can read it.
|
|
207
207
|
|
|
208
208
|
> [!NOTE]
|
|
209
|
-
> The [client types](
|
|
210
|
-
>
|
|
209
|
+
> The [client types](types/client.d.ts) declare `process.env` and nothing else
|
|
210
|
+
> from Node, because Webpack replaces nothing else.
|
|
211
211
|
|
|
212
212
|
### Stop using `../../../` everywhere
|
|
213
213
|
|
|
@@ -257,8 +257,7 @@ import { Component } from "@self/components"
|
|
|
257
257
|
`development` mode
|
|
258
258
|
|
|
259
259
|
> [!NOTE]
|
|
260
|
-
> The [client types](
|
|
261
|
-
> imports
|
|
260
|
+
> The [client types](types/client.d.ts) declare `.css`, image and font imports.
|
|
262
261
|
|
|
263
262
|
### Replace a default config
|
|
264
263
|
|
|
@@ -288,11 +287,6 @@ Each config in your app folder replaces the default of the same name:
|
|
|
288
287
|
> - `.swcrc -> jsc.transform.react.refresh`: VBlocks adds the React Refresh
|
|
289
288
|
> transform when `serve` runs in `development` mode
|
|
290
289
|
|
|
291
|
-
> [!NOTE]
|
|
292
|
-
> VBlocks passes [`build --single-file`](#vblocks-build) and
|
|
293
|
-
> [`serve --analyze`](#vblocks-serve) to your `webpack.config.js` as
|
|
294
|
-
> `env.single` and `env.analyze`.
|
|
295
|
-
|
|
296
290
|
### Style with Tailwind
|
|
297
291
|
|
|
298
292
|
VBlocks does not include Tailwind. Add it through a `postcss.config.js` in your
|
|
@@ -302,10 +296,11 @@ app folder:
|
|
|
302
296
|
> The `xyflow` and `xyflow-tabs` templates of [`vblocks init`](#vblocks-init)
|
|
303
297
|
> have this setup.
|
|
304
298
|
|
|
305
|
-
1. **Install Tailwind
|
|
299
|
+
1. **Install Tailwind, the Tailwind plugin for PostCSS and cssnano, which the
|
|
300
|
+
ejected config imports**
|
|
306
301
|
|
|
307
302
|
```sh
|
|
308
|
-
npm install --save-dev tailwindcss @tailwindcss/postcss
|
|
303
|
+
npm install --save-dev tailwindcss @tailwindcss/postcss cssnano
|
|
309
304
|
```
|
|
310
305
|
|
|
311
306
|
2. **Eject the default PostCSS config into your app folder**
|
|
@@ -317,18 +312,16 @@ app folder:
|
|
|
317
312
|
3. **Replace `postcss-preset-env` with the Tailwind plugin**
|
|
318
313
|
|
|
319
314
|
```diff
|
|
315
|
+
+import tailwindcss from "@tailwindcss/postcss"
|
|
316
|
+
import cssnano from "cssnano"
|
|
317
|
+
-import postcssPresetEnv from "postcss-preset-env"
|
|
318
|
+
|
|
320
319
|
export default ({ mode }) => ({
|
|
321
|
-
plugins:
|
|
322
|
-
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
+ optimize: mode === "production",
|
|
327
|
-
+ },
|
|
328
|
-
"cssnano": mode === "production" && {
|
|
329
|
-
preset: "default",
|
|
330
|
-
},
|
|
331
|
-
},
|
|
320
|
+
plugins: [
|
|
321
|
+
- postcssPresetEnv({ stage: 2 }),
|
|
322
|
+
+ tailwindcss({ optimize: mode === "production" }),
|
|
323
|
+
...(mode === "production" ? [cssnano({ preset: "default" })] : []),
|
|
324
|
+
],
|
|
332
325
|
})
|
|
333
326
|
```
|
|
334
327
|
|
|
@@ -360,7 +353,7 @@ app folder:
|
|
|
360
353
|
npm install --save-dev @asd14/vblocks # needs react and react-dom ^18 or ^19
|
|
361
354
|
```
|
|
362
355
|
|
|
363
|
-
2. **Add the [client types](
|
|
356
|
+
2. **Add the [client types](types/client.d.ts) and the
|
|
364
357
|
[`@self`](#stop-using--everywhere) alias to your `tsconfig.json`**
|
|
365
358
|
|
|
366
359
|
```diff
|
|
@@ -389,6 +382,8 @@ app folder:
|
|
|
389
382
|
|
|
390
383
|
### Commands
|
|
391
384
|
|
|
385
|
+
Each command prints its own help with `--help`, eg. `npx vblocks serve --help`.
|
|
386
|
+
|
|
392
387
|
#### `vblocks init`
|
|
393
388
|
|
|
394
389
|
Write a template's plumbing, app, or both into `<directory>`.
|
|
@@ -408,8 +403,8 @@ vblocks init <directory>
|
|
|
408
403
|
- `plumbing`: `package.json`, `.gitignore`
|
|
409
404
|
- `app`: `src/`, `tsconfig.json` and the template's configs. `init` adds the
|
|
410
405
|
template's dependencies to the `package.json` of the
|
|
411
|
-
[project folder](#vocabulary), the
|
|
412
|
-
`package.json
|
|
406
|
+
[project folder](#vocabulary), the parent of `<directory>`. Without a
|
|
407
|
+
`package.json` there, `init` fails
|
|
413
408
|
|
|
414
409
|
#### `vblocks serve`
|
|
415
410
|
|
|
@@ -426,7 +421,7 @@ vblocks serve
|
|
|
426
421
|
[--prefix <directory>]
|
|
427
422
|
[--analyze]
|
|
428
423
|
[--log-level <error|warn|info|verbose>]
|
|
429
|
-
[<webpack option>...]
|
|
424
|
+
[-- <webpack option>...]
|
|
430
425
|
```
|
|
431
426
|
|
|
432
427
|
- `--mode` (default: `development`)
|
|
@@ -437,10 +432,11 @@ vblocks serve
|
|
|
437
432
|
- `--analyze`
|
|
438
433
|
- Run the bundle analyzer, on a free port
|
|
439
434
|
- `--log-level` (default: `warn`)
|
|
440
|
-
- How much Webpack
|
|
441
|
-
-
|
|
442
|
-
- Any
|
|
443
|
-
|
|
435
|
+
- How much Webpack and its development server print
|
|
436
|
+
- `-- <webpack option>...`
|
|
437
|
+
- Any [`webpack serve`](https://webpack.js.org/api/cli/) option
|
|
438
|
+
- `serve` passes each one to Webpack unchanged
|
|
439
|
+
- eg. `-- --host 0.0.0.0`, to listen on the network
|
|
444
440
|
|
|
445
441
|
#### `vblocks build`
|
|
446
442
|
|
|
@@ -452,7 +448,7 @@ By default, `build`:
|
|
|
452
448
|
- Writes a `react` chunk, and a `vendors` chunk when your other dependencies
|
|
453
449
|
total over 20 KB (10 KB in `development`)
|
|
454
450
|
- Inlines `jpg`, `gif`, `png` and `svg` files up to 10 KB
|
|
455
|
-
- Writes larger to `dist/` with content-hashed names
|
|
451
|
+
- Writes larger images to `dist/` with content-hashed names
|
|
456
452
|
- Writes `woff`, `woff2`, `ttf` and `eot` files to `dist/fonts/`
|
|
457
453
|
- Copies `src/public/favicon.svg` and `src/public/robots.txt` of your app, or
|
|
458
454
|
the defaults of VBlocks
|
|
@@ -461,9 +457,9 @@ By default, `build`:
|
|
|
461
457
|
vblocks build
|
|
462
458
|
[--mode <development|production>]
|
|
463
459
|
[--prefix <directory>]
|
|
464
|
-
[--single-file]
|
|
460
|
+
[--single-file|--single]
|
|
465
461
|
[--log-level <error|warn|info|verbose>]
|
|
466
|
-
[<webpack option>...]
|
|
462
|
+
[-- <webpack option>...]
|
|
467
463
|
```
|
|
468
464
|
|
|
469
465
|
- `--mode` (default: `production`)
|
|
@@ -472,17 +468,18 @@ vblocks build
|
|
|
472
468
|
config, CSS
|
|
473
469
|
- `--prefix` (default: the current folder)
|
|
474
470
|
- The [app folder](#vocabulary), which must exist
|
|
475
|
-
- `--single-file`
|
|
471
|
+
- `--single-file|--single`
|
|
476
472
|
- Write one standalone `dist/index.html`, every asset inlined
|
|
477
473
|
- A browser opens the file from disk, with no server and no network
|
|
478
474
|
- The bundle has no `robots.txt`
|
|
479
475
|
- Keep the route in the URL hash
|
|
480
476
|
- On `file://`, `history.pushState` to another path throws
|
|
481
477
|
- `--log-level` (default: `warn`)
|
|
482
|
-
- How much Webpack
|
|
483
|
-
-
|
|
484
|
-
- Any
|
|
485
|
-
|
|
478
|
+
- How much Webpack prints
|
|
479
|
+
- `-- <webpack option>...`
|
|
480
|
+
- Any [`webpack build`](https://webpack.js.org/api/cli/) option
|
|
481
|
+
- `build` passes each one to Webpack unchanged
|
|
482
|
+
- eg. `-- --devtool source-map`, to write source maps
|
|
486
483
|
|
|
487
484
|
#### `vblocks eject`
|
|
488
485
|
|
|
@@ -504,39 +501,41 @@ npx vblocks eject postcss > postcss.config.js
|
|
|
504
501
|
npx vblocks eject swc > .swcrc
|
|
505
502
|
```
|
|
506
503
|
|
|
504
|
+
An ejected config loads its plugins and loaders from your project. Install them
|
|
505
|
+
in the project folder, eg. `postcss-preset-env` and `cssnano` for the PostCSS
|
|
506
|
+
config.
|
|
507
|
+
|
|
507
508
|
### Templates
|
|
508
509
|
|
|
509
|
-
|
|
510
|
-
template adds its own files, and sets the `<title>` of `src/index.html`. A
|
|
511
|
-
template's file replaces the common one of the same path, eg. `xyflow` has its
|
|
512
|
-
own `src/index.css`.
|
|
510
|
+
All templates scaffold `src/index.html`, `src/index.css` and `tsconfig.json`.
|
|
513
511
|
|
|
514
512
|
#### `plain`
|
|
515
513
|
|
|
516
|
-
`src/index.tsx
|
|
514
|
+
"Hello World!" in `src/index.tsx`.
|
|
515
|
+
|
|
516
|
+
- Adds no packages
|
|
517
517
|
|
|
518
518
|
#### `xyflow`
|
|
519
519
|
|
|
520
|
-
One diagram, and a details panel for the selected node or edge.
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
520
|
+
One diagram, and a details panel for the selected node or edge.
|
|
521
|
+
|
|
522
|
+
- Adds `@xyflow/react`, `tailwindcss`, `@tailwindcss/postcss` and `cssnano` to
|
|
523
|
+
the `package.json` of the project folder
|
|
524
|
+
- Writes a `postcss.config.js` that configures Tailwind
|
|
524
525
|
|
|
525
526
|
```text
|
|
526
527
|
src/
|
|
527
528
|
├── index.tsx # the layout: header, diagram, details panel, the selected id
|
|
528
529
|
├── diagram.tsx # the nodes and edges, placed and sized in grid cells
|
|
529
530
|
├── details.tsx # the panel for the selected node or edge
|
|
530
|
-
├── ui/zoom-level.tsx # the zoom level, and a Reset to 100%
|
|
531
531
|
└── utils/grid.ts # CELL_SIZE and toPixels
|
|
532
532
|
```
|
|
533
533
|
|
|
534
|
-
To show another topic, rewrite `diagram.tsx` and `details.tsx`.
|
|
535
|
-
|
|
536
534
|
#### `xyflow-tabs`
|
|
537
535
|
|
|
538
|
-
One tab per diagram, each with its own details panel.
|
|
539
|
-
|
|
536
|
+
One tab per diagram, each with its own details panel.
|
|
537
|
+
|
|
538
|
+
- Adds the same packages and `postcss.config.js` as `xyflow`
|
|
540
539
|
|
|
541
540
|
```text
|
|
542
541
|
src/
|
|
@@ -550,9 +549,6 @@ src/
|
|
|
550
549
|
└── utils/grid.ts # CELL_SIZE and toPixels
|
|
551
550
|
```
|
|
552
551
|
|
|
553
|
-
To add a tab, add a folder in `pages/` and add it to the tab list in
|
|
554
|
-
`index.tsx`.
|
|
555
|
-
|
|
556
552
|
## License
|
|
557
553
|
|
|
558
554
|
MIT
|
package/bin/vblocks
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
set -eu
|
|
4
|
+
|
|
5
|
+
# NAME
|
|
6
|
+
# vblocks - Zero-config React builds, as a static site or a single HTML file
|
|
7
|
+
#
|
|
8
|
+
# SYNOPSIS
|
|
9
|
+
# vblocks <command> [OPTIONS]
|
|
10
|
+
# vblocks -h | --help
|
|
11
|
+
#
|
|
12
|
+
# DESCRIPTION
|
|
13
|
+
# Each command prints its own help with --help.
|
|
14
|
+
#
|
|
15
|
+
# ARGUMENTS
|
|
16
|
+
# command init Write a template into a folder
|
|
17
|
+
# serve Start the development server of an app
|
|
18
|
+
# build Build an app into dist/ in its folder
|
|
19
|
+
# eject Print a default config of VBlocks
|
|
20
|
+
#
|
|
21
|
+
# OPTIONS
|
|
22
|
+
# -h, --help Print this help
|
|
23
|
+
#
|
|
24
|
+
# EXAMPLE
|
|
25
|
+
# npx @asd14/vblocks init my-app
|
|
26
|
+
# npx vblocks serve --help
|
|
27
|
+
#
|
|
28
|
+
# EXIT CODES
|
|
29
|
+
# 0 Done
|
|
30
|
+
# 2 No command, or an unknown command
|
|
31
|
+
#
|
|
32
|
+
# A command exits with the codes its help lists.
|
|
33
|
+
#
|
|
34
|
+
# SEE ALSO
|
|
35
|
+
# vblocks init, vblocks serve, vblocks build, vblocks eject
|
|
36
|
+
|
|
37
|
+
# npm links the command to this file, so "$0" names the link. realpath follows
|
|
38
|
+
# it to the package, where vblocks.d/ holds the commands
|
|
39
|
+
_SCRIPT_DIR="$(dirname "$(realpath "$0")")/vblocks.d"
|
|
40
|
+
# shellcheck source=vblocks.d/vblocks.sh
|
|
41
|
+
. "$_SCRIPT_DIR/vblocks.sh"
|
|
42
|
+
|
|
43
|
+
# ╭───
|
|
44
|
+
# │ Bootstrap
|
|
45
|
+
# ╰───
|
|
46
|
+
|
|
47
|
+
case "${1:-}" in
|
|
48
|
+
-h | --help)
|
|
49
|
+
_show_help "$0"
|
|
50
|
+
exit 0
|
|
51
|
+
;;
|
|
52
|
+
"")
|
|
53
|
+
_show_help "$0" >&2
|
|
54
|
+
exit 2
|
|
55
|
+
;;
|
|
56
|
+
esac
|
|
57
|
+
|
|
58
|
+
# ╭───
|
|
59
|
+
# │ Main
|
|
60
|
+
# ╰───
|
|
61
|
+
|
|
62
|
+
_COMMAND=$1
|
|
63
|
+
shift
|
|
64
|
+
|
|
65
|
+
case "$_COMMAND" in
|
|
66
|
+
init | serve | build | eject) ;;
|
|
67
|
+
*) _fail 2 -v command "$_COMMAND" -v available_commands "init,serve,build,eject" "Unknown command" ;;
|
|
68
|
+
esac
|
|
69
|
+
|
|
70
|
+
# sh runs the command file, whatever mode npm gave it
|
|
71
|
+
exec sh "$_SCRIPT_DIR/$_COMMAND" "$@"
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
# NAME
|
|
4
|
+
# vblocks build - Build an app into dist/ in its folder
|
|
5
|
+
#
|
|
6
|
+
# SYNOPSIS
|
|
7
|
+
# vblocks build
|
|
8
|
+
# [--mode <development|production>]
|
|
9
|
+
# [--prefix <directory>]
|
|
10
|
+
# [--single-file|--single]
|
|
11
|
+
# [--log-level <error|warn|info|verbose>]
|
|
12
|
+
# [-- <webpack option>...]
|
|
13
|
+
#
|
|
14
|
+
# DESCRIPTION
|
|
15
|
+
# The app folder holds src/index.tsx and src/index.html. A config in it,
|
|
16
|
+
# webpack.config.js, postcss.config.js or .swcrc, replaces the VBlocks
|
|
17
|
+
# default of the same name. So do src/public/robots.txt and
|
|
18
|
+
# src/public/favicon.svg.
|
|
19
|
+
#
|
|
20
|
+
# Print the app folder, the VBlocks folder and the files Webpack runs with,
|
|
21
|
+
# then build. Print each file in dist/, its size and the total.
|
|
22
|
+
#
|
|
23
|
+
# OPTIONS
|
|
24
|
+
# --mode <mode> The Webpack mode, development or production
|
|
25
|
+
# (default: production)
|
|
26
|
+
# --prefix <directory> The app folder, which must exist (default: the
|
|
27
|
+
# current folder)
|
|
28
|
+
# --single-file, --single Build one standalone dist/index.html, every
|
|
29
|
+
# asset inlined, with no robots.txt. An ejected
|
|
30
|
+
# webpack.config.js must read env.single
|
|
31
|
+
# --log-level <level> How much Webpack prints: error, warn, info or
|
|
32
|
+
# verbose (default: warn)
|
|
33
|
+
# -- <webpack option>... Pass each option to Webpack, unchanged
|
|
34
|
+
# -h, --help Print this help
|
|
35
|
+
#
|
|
36
|
+
# ENVIRONMENT
|
|
37
|
+
# NO_COLOR When non-empty, print without color, the icons or the header
|
|
38
|
+
#
|
|
39
|
+
# EXAMPLE
|
|
40
|
+
# npx vblocks build
|
|
41
|
+
# cd demos && npx vblocks build --prefix flow --single-file
|
|
42
|
+
# npx vblocks build -- --devtool source-map
|
|
43
|
+
#
|
|
44
|
+
# EXIT CODES
|
|
45
|
+
# 0 Done
|
|
46
|
+
# 2 Invalid usage, or Webpack rejected an option or the config
|
|
47
|
+
# 3 Could not run: a missing tool, or a failed Webpack run
|
|
48
|
+
#
|
|
49
|
+
# SEE ALSO
|
|
50
|
+
# vblocks, vblocks serve, vblocks eject, webpack
|
|
51
|
+
|
|
52
|
+
# vblocks runs this file. Never call it directly.
|
|
53
|
+
|
|
54
|
+
set -eu
|
|
55
|
+
|
|
56
|
+
_SCRIPT_DIR=$(dirname "$0")
|
|
57
|
+
# shellcheck source=vblocks.sh
|
|
58
|
+
. "$_SCRIPT_DIR/vblocks.sh"
|
|
59
|
+
# shellcheck source=webpack.sh
|
|
60
|
+
. "$_SCRIPT_DIR/webpack.sh"
|
|
61
|
+
|
|
62
|
+
# ╭───
|
|
63
|
+
# │ Settings
|
|
64
|
+
# ╰───
|
|
65
|
+
|
|
66
|
+
_PREFIX_DIR="" # --prefix, the app folder
|
|
67
|
+
_MODE="production" # --mode: development or production
|
|
68
|
+
_LOG_LEVEL="warn" # --log-level: error, warn, info or verbose
|
|
69
|
+
_IS_SINGLE_FILE="" # --single-file, "true" or ""
|
|
70
|
+
|
|
71
|
+
# ╭───
|
|
72
|
+
# │ Domain primitives
|
|
73
|
+
# ╰───
|
|
74
|
+
|
|
75
|
+
# _print_build_files <app-dir>
|
|
76
|
+
#
|
|
77
|
+
# Print each file in the dist/ of <app-dir> as $APP_DIR/dist/..., a tab and its
|
|
78
|
+
# size, then the total size. Webpack empties dist/ before each build, so every
|
|
79
|
+
# file there is from the last build.
|
|
80
|
+
_print_build_files() {
|
|
81
|
+
# An ejected config can write elsewhere
|
|
82
|
+
[ -d "$1/dist" ] || return 0
|
|
83
|
+
|
|
84
|
+
(cd -- "$1/dist" && find . -type f | LC_ALL=C sort) \
|
|
85
|
+
| while IFS= read -r pbf_file; do
|
|
86
|
+
printf '%s\t%s\n' "$(wc -c <"$1/dist/$pbf_file")" "${pbf_file#./}"
|
|
87
|
+
done \
|
|
88
|
+
| awk -F '\t' -v gray="$_GRAY" -v bold="$_BOLD" -v reset="$_RESET" '
|
|
89
|
+
function format_size(bytes) {
|
|
90
|
+
if (bytes < 1024) return bytes " B"
|
|
91
|
+
if (bytes < 1024 * 1024) return sprintf("%.1f KiB", bytes / 1024)
|
|
92
|
+
return sprintf("%.1f MiB", bytes / 1024 / 1024)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
{
|
|
96
|
+
total += $1
|
|
97
|
+
printf "$APP_DIR/dist/%s\t%s%s%s\n", $2, gray, format_size($1), reset
|
|
98
|
+
}
|
|
99
|
+
END { printf "\n%sTotal%s\t%s\n", bold, reset, format_size(total) }
|
|
100
|
+
'
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
# ╭───
|
|
104
|
+
# │ Flags and positionals
|
|
105
|
+
# ╰───
|
|
106
|
+
|
|
107
|
+
while [ "$#" -gt 0 ]; do
|
|
108
|
+
case "$1" in
|
|
109
|
+
-h | --help)
|
|
110
|
+
_show_help "$0"
|
|
111
|
+
exit 0
|
|
112
|
+
;;
|
|
113
|
+
--prefix)
|
|
114
|
+
[ "$#" -lt 2 ] && _fail 2 "--prefix needs a folder"
|
|
115
|
+
_PREFIX_DIR=$2
|
|
116
|
+
shift 2
|
|
117
|
+
;;
|
|
118
|
+
--mode)
|
|
119
|
+
_guard_mode "${2:-}"
|
|
120
|
+
_MODE=$2
|
|
121
|
+
shift 2
|
|
122
|
+
;;
|
|
123
|
+
--log-level)
|
|
124
|
+
_guard_log_level "${2:-}"
|
|
125
|
+
_LOG_LEVEL=$2
|
|
126
|
+
shift 2
|
|
127
|
+
;;
|
|
128
|
+
--single-file | --single)
|
|
129
|
+
_IS_SINGLE_FILE="true"
|
|
130
|
+
shift
|
|
131
|
+
;;
|
|
132
|
+
--analyze)
|
|
133
|
+
_fail 2 "--analyze works only with serve"
|
|
134
|
+
;;
|
|
135
|
+
--)
|
|
136
|
+
shift
|
|
137
|
+
break
|
|
138
|
+
;;
|
|
139
|
+
-?*)
|
|
140
|
+
_fail 2 -v flag "$1" "Unknown flag. For Webpack options, place them after --"
|
|
141
|
+
;;
|
|
142
|
+
*)
|
|
143
|
+
_fail 2 -v argument "$1" "build takes no positional"
|
|
144
|
+
;;
|
|
145
|
+
esac
|
|
146
|
+
done
|
|
147
|
+
|
|
148
|
+
if [ -n "$_PREFIX_DIR" ] && [ ! -d "$_PREFIX_DIR" ]; then
|
|
149
|
+
_fail 2 -v prefix "$_PREFIX_DIR" "--prefix is not a folder"
|
|
150
|
+
fi
|
|
151
|
+
|
|
152
|
+
# node runs webpack-cli
|
|
153
|
+
_require_cmd node
|
|
154
|
+
_export_version
|
|
155
|
+
|
|
156
|
+
# ╭───
|
|
157
|
+
# │ Main
|
|
158
|
+
# ╰───
|
|
159
|
+
|
|
160
|
+
_APP_DIR=$(cd -- "${_PREFIX_DIR:-.}" && pwd)
|
|
161
|
+
_WEBPACK_CONFIG=$(_pick_file "$_APP_DIR" webpack.config.js)
|
|
162
|
+
_POSTCSS_CONFIG=$(_pick_file "$_APP_DIR" postcss.config.js)
|
|
163
|
+
_SWC_CONFIG=$(_pick_file "$_APP_DIR" .swcrc)
|
|
164
|
+
# A single file has no robots.txt next to it. Webpack drops an --env with an
|
|
165
|
+
# empty value, so the config gets no robotsPath
|
|
166
|
+
_ROBOTS_FILE=""
|
|
167
|
+
if [ -z "$_IS_SINGLE_FILE" ]; then
|
|
168
|
+
_ROBOTS_FILE=$(_pick_file "$_APP_DIR" src/public/robots.txt)
|
|
169
|
+
fi
|
|
170
|
+
_FAVICON_FILE=$(_pick_file "$_APP_DIR" src/public/favicon.svg)
|
|
171
|
+
|
|
172
|
+
_ARTIFACT="SPA bundle"
|
|
173
|
+
if [ -n "$_IS_SINGLE_FILE" ]; then
|
|
174
|
+
_ARTIFACT="single file"
|
|
175
|
+
fi
|
|
176
|
+
|
|
177
|
+
_print_header "$VB_VERSION" "${_BOLD}build${_RESET}: $_MODE, $_ARTIFACT" >&2
|
|
178
|
+
_print_summary "$_APP_DIR" "$_WEBPACK_CONFIG" "$_POSTCSS_CONFIG" "$_SWC_CONFIG" \
|
|
179
|
+
"$_ROBOTS_FILE" "$_FAVICON_FILE"
|
|
180
|
+
|
|
181
|
+
# The default Webpack config reads env.single. An ejected config supports
|
|
182
|
+
# --single-file only if it reads env.single too
|
|
183
|
+
_run_webpack build "$_WEBPACK_CONFIG" \
|
|
184
|
+
--env "entryDir=$_APP_DIR" \
|
|
185
|
+
--env "postcssConfigPath=$_POSTCSS_CONFIG" \
|
|
186
|
+
--env "swcConfigPath=$_SWC_CONFIG" \
|
|
187
|
+
--env "robotsPath=$_ROBOTS_FILE" \
|
|
188
|
+
--env "faviconPath=$_FAVICON_FILE" \
|
|
189
|
+
--env "logLevel=$_LOG_LEVEL" \
|
|
190
|
+
--mode "$_MODE" ${_IS_SINGLE_FILE:+--env single} "$@"
|
|
191
|
+
printf '\n'
|
|
192
|
+
_print_build_files "$_APP_DIR"
|
|
193
|
+
exit 0
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
# NAME
|
|
4
|
+
# vblocks eject - Print a default config of VBlocks
|
|
5
|
+
#
|
|
6
|
+
# SYNOPSIS
|
|
7
|
+
# vblocks eject <config>
|
|
8
|
+
#
|
|
9
|
+
# DESCRIPTION
|
|
10
|
+
# Print the config to stdout. Save it in the app folder, and serve and
|
|
11
|
+
# build run with it in place of the VBlocks default.
|
|
12
|
+
#
|
|
13
|
+
# An ejected config loads its plugins and loaders from the project folder,
|
|
14
|
+
# not from VBlocks. Install them there.
|
|
15
|
+
#
|
|
16
|
+
# ARGUMENTS
|
|
17
|
+
# config webpack, postcss or swc. Save each as webpack.config.js,
|
|
18
|
+
# postcss.config.js or .swcrc
|
|
19
|
+
#
|
|
20
|
+
# OPTIONS
|
|
21
|
+
# -h, --help Print this help
|
|
22
|
+
#
|
|
23
|
+
# EXAMPLE
|
|
24
|
+
# npx vblocks eject postcss > postcss.config.js
|
|
25
|
+
#
|
|
26
|
+
# EXIT CODES
|
|
27
|
+
# 0 Done
|
|
28
|
+
# 2 Invalid usage
|
|
29
|
+
#
|
|
30
|
+
# SEE ALSO
|
|
31
|
+
# vblocks, vblocks serve, vblocks build
|
|
32
|
+
|
|
33
|
+
# vblocks runs this file. Never call it directly.
|
|
34
|
+
|
|
35
|
+
set -eu
|
|
36
|
+
|
|
37
|
+
_SCRIPT_DIR=$(dirname "$0")
|
|
38
|
+
# shellcheck source=vblocks.sh
|
|
39
|
+
. "$_SCRIPT_DIR/vblocks.sh"
|
|
40
|
+
|
|
41
|
+
# ╭───
|
|
42
|
+
# │ Settings
|
|
43
|
+
# ╰───
|
|
44
|
+
|
|
45
|
+
_EJECT_CONFIG="" # eject <config>
|
|
46
|
+
|
|
47
|
+
# ╭───
|
|
48
|
+
# │ Flags and positionals
|
|
49
|
+
# ╰───
|
|
50
|
+
|
|
51
|
+
[ "$#" -ne 1 ] && _fail 2 -v available_configs "webpack,postcss,swc" "eject needs one config"
|
|
52
|
+
|
|
53
|
+
case "$1" in
|
|
54
|
+
-h | --help)
|
|
55
|
+
_show_help "$0"
|
|
56
|
+
exit 0
|
|
57
|
+
;;
|
|
58
|
+
webpack) _EJECT_CONFIG="webpack.config.js" ;;
|
|
59
|
+
postcss) _EJECT_CONFIG="postcss.config.js" ;;
|
|
60
|
+
swc) _EJECT_CONFIG=".swcrc" ;;
|
|
61
|
+
*) _fail 2 -v config "$1" -v available_configs "webpack,postcss,swc" "Unknown config" ;;
|
|
62
|
+
esac
|
|
63
|
+
|
|
64
|
+
# ╭───
|
|
65
|
+
# │ Main
|
|
66
|
+
# ╰───
|
|
67
|
+
|
|
68
|
+
cat -- "$_VB_DIR/defaults/$_EJECT_CONFIG"
|
|
69
|
+
exit 0
|