@asd14/vblocks 6.0.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 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](src/types/client.d.ts) declare `process.env` and nothing
210
- > else from Node, because Webpack replaces nothing else.
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](src/types/client.d.ts) declare `.css`, image and font
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
 
@@ -297,10 +296,11 @@ app folder:
297
296
  > The `xyflow` and `xyflow-tabs` templates of [`vblocks init`](#vblocks-init)
298
297
  > have this setup.
299
298
 
300
- 1. **Install Tailwind and the Tailwind plugin for PostCSS**
299
+ 1. **Install Tailwind, the Tailwind plugin for PostCSS and cssnano, which the
300
+ ejected config imports**
301
301
 
302
302
  ```sh
303
- npm install --save-dev tailwindcss @tailwindcss/postcss
303
+ npm install --save-dev tailwindcss @tailwindcss/postcss cssnano
304
304
  ```
305
305
 
306
306
  2. **Eject the default PostCSS config into your app folder**
@@ -312,18 +312,16 @@ app folder:
312
312
  3. **Replace `postcss-preset-env` with the Tailwind plugin**
313
313
 
314
314
  ```diff
315
+ +import tailwindcss from "@tailwindcss/postcss"
316
+ import cssnano from "cssnano"
317
+ -import postcssPresetEnv from "postcss-preset-env"
318
+
315
319
  export default ({ mode }) => ({
316
- plugins: {
317
- - "postcss-preset-env": {
318
- - stage: 2,
319
- - },
320
- + "@tailwindcss/postcss": {
321
- + optimize: mode === "production",
322
- + },
323
- "cssnano": mode === "production" && {
324
- preset: "default",
325
- },
326
- },
320
+ plugins: [
321
+ - postcssPresetEnv({ stage: 2 }),
322
+ + tailwindcss({ optimize: mode === "production" }),
323
+ ...(mode === "production" ? [cssnano({ preset: "default" })] : []),
324
+ ],
327
325
  })
328
326
  ```
329
327
 
@@ -355,7 +353,7 @@ app folder:
355
353
  npm install --save-dev @asd14/vblocks # needs react and react-dom ^18 or ^19
356
354
  ```
357
355
 
358
- 2. **Add the [client types](src/types/client.d.ts) and the
356
+ 2. **Add the [client types](types/client.d.ts) and the
359
357
  [`@self`](#stop-using--everywhere) alias to your `tsconfig.json`**
360
358
 
361
359
  ```diff
@@ -384,6 +382,8 @@ app folder:
384
382
 
385
383
  ### Commands
386
384
 
385
+ Each command prints its own help with `--help`, eg. `npx vblocks serve --help`.
386
+
387
387
  #### `vblocks init`
388
388
 
389
389
  Write a template's plumbing, app, or both into `<directory>`.
@@ -457,7 +457,7 @@ By default, `build`:
457
457
  vblocks build
458
458
  [--mode <development|production>]
459
459
  [--prefix <directory>]
460
- [--single-file]
460
+ [--single-file|--single]
461
461
  [--log-level <error|warn|info|verbose>]
462
462
  [-- <webpack option>...]
463
463
  ```
@@ -468,7 +468,7 @@ vblocks build
468
468
  config, CSS
469
469
  - `--prefix` (default: the current folder)
470
470
  - The [app folder](#vocabulary), which must exist
471
- - `--single-file`
471
+ - `--single-file|--single`
472
472
  - Write one standalone `dist/index.html`, every asset inlined
473
473
  - A browser opens the file from disk, with no server and no network
474
474
  - The bundle has no `robots.txt`
@@ -501,6 +501,10 @@ npx vblocks eject postcss > postcss.config.js
501
501
  npx vblocks eject swc > .swcrc
502
502
  ```
503
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
+
504
508
  ### Templates
505
509
 
506
510
  All templates scaffold `src/index.html`, `src/index.css` and `tsconfig.json`.
@@ -515,8 +519,8 @@ All templates scaffold `src/index.html`, `src/index.css` and `tsconfig.json`.
515
519
 
516
520
  One diagram, and a details panel for the selected node or edge.
517
521
 
518
- - Adds `@xyflow/react`, `tailwindcss` and `@tailwindcss/postcss` to the
519
- `package.json` of the project folder
522
+ - Adds `@xyflow/react`, `tailwindcss`, `@tailwindcss/postcss` and `cssnano` to
523
+ the `package.json` of the project folder
520
524
  - Writes a `postcss.config.js` that configures Tailwind
521
525
 
522
526
  ```text
package/bin/vblocks CHANGED
@@ -3,85 +3,36 @@
3
3
  set -eu
4
4
 
5
5
  # NAME
6
- # vblocks - Write a project or an app, then serve or build it with Webpack
6
+ # vblocks - Zero-config React builds, as a static site or a single HTML file
7
7
  #
8
8
  # SYNOPSIS
9
- # vblocks init <directory>
10
- # [--template <plain|xyflow|xyflow-tabs>]
11
- # [--only <app|plumbing>]
12
- # vblocks serve
13
- # [--mode <development|production>]
14
- # [--prefix <directory>]
15
- # [--analyze]
16
- # [--log-level <error|warn|info|verbose>]
17
- # [-- <webpack option>...]
18
- # vblocks build
19
- # [--mode <development|production>]
20
- # [--prefix <directory>]
21
- # [--single-file]
22
- # [--log-level <error|warn|info|verbose>]
23
- # [-- <webpack option>...]
24
- # vblocks eject <webpack|postcss|swc>
9
+ # vblocks <command> [OPTIONS]
25
10
  # vblocks -h | --help
26
11
  #
27
12
  # DESCRIPTION
28
- # The app folder holds src/index.tsx and src/index.html. A config in it,
29
- # webpack.config.js, postcss.config.js or .swcrc, replaces the VBlocks
30
- # default of the same name.
13
+ # Each command prints its own help with --help.
31
14
  #
32
- # init Write a template into <directory>, which must be missing or
33
- # empty. A template has two parts: the plumbing, which holds
34
- # the files of the project folder, and the app. Without --only,
35
- # write both.
36
- # After each part, run its post-init hooks in <directory>.
37
- # Print each file it adds, updates or drops, then the next
38
- # steps.
39
- # serve Start the development server
40
- # build Build the app into dist/ in the app folder. Print each file
41
- # in dist/, its size and the total
42
- # eject Print a default config, to save in the app folder
43
- #
44
- # serve and build pass every option after -- to Webpack, unchanged.
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
45
20
  #
46
21
  # OPTIONS
47
- # --template <name> init: plain, xyflow or xyflow-tabs (default: plain)
48
- # --only <app|plumbing> init: write only the app or only the plumbing.
49
- # With app, init adds the app's dependencies to
50
- # the package.json in the parent folder of
51
- # <directory>. Without that file, init exits 3
52
- # --mode <mode> serve, build: the Webpack mode, development or
53
- # production (default: development for serve,
54
- # production for build)
55
- # --prefix <directory> serve, build: the app folder (default: the
56
- # current folder)
57
- # --single-file build: one standalone dist/index.html, every
58
- # asset inlined
59
- # --analyze serve: run the bundle analyzer, on a free port
60
- # --log-level <level> serve, build: how much Webpack and its dev server
61
- # print: error, warn, info or verbose (default:
62
- # warn)
63
- # -h, --help Print this help
64
- #
65
- # ENVIRONMENT
66
- # NO_COLOR When non-empty, print without color, the tool icons or the
67
- # header
22
+ # -h, --help Print this help
68
23
  #
69
24
  # EXAMPLE
70
25
  # npx @asd14/vblocks init my-app
71
- # npx @asd14/vblocks init demos --only plumbing
72
- # npx @asd14/vblocks init demos/flow --template xyflow --only app
73
- # cd demos && npx vblocks build --prefix flow --single-file
74
- # npx vblocks serve -- --host 0.0.0.0
75
- # npx vblocks eject postcss > postcss.config.js
26
+ # npx vblocks serve --help
76
27
  #
77
28
  # EXIT CODES
78
29
  # 0 Done
79
- # 2 Invalid usage, or Webpack rejected an option or the config
80
- # 3 Could not run: a missing tool or parent package.json, a folder init
81
- # could not add, or a failed copy, hook or Webpack run
30
+ # 2 No command, or an unknown command
31
+ #
32
+ # A command exits with the codes its help lists.
82
33
  #
83
34
  # SEE ALSO
84
- # node, npm, webpack
35
+ # vblocks init, vblocks serve, vblocks build, vblocks eject
85
36
 
86
37
  # npm links the command to this file, so "$0" names the link. realpath follows
87
38
  # it to the package, where vblocks.d/ holds the commands
@@ -1,9 +1,55 @@
1
1
  #!/bin/sh
2
2
 
3
- # vblocks build [OPTIONS] [-- <webpack option>...]
3
+ # NAME
4
+ # vblocks build - Build an app into dist/ in its folder
4
5
  #
5
- # Build the app into dist/ in the app folder, then print
6
- # each file in it. vblocks runs this file. Never call it directly.
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.
7
53
 
8
54
  set -eu
9
55
 
@@ -60,6 +106,10 @@ _print_build_files() {
60
106
 
61
107
  while [ "$#" -gt 0 ]; do
62
108
  case "$1" in
109
+ -h | --help)
110
+ _show_help "$0"
111
+ exit 0
112
+ ;;
63
113
  --prefix)
64
114
  [ "$#" -lt 2 ] && _fail 2 "--prefix needs a folder"
65
115
  _PREFIX_DIR=$2
@@ -108,18 +158,16 @@ _export_version
108
158
  # ╰───
109
159
 
110
160
  _APP_DIR=$(cd -- "${_PREFIX_DIR:-.}" && pwd)
111
- _WEBPACK_CONFIG=$(_pick_config "$_APP_DIR" webpack.config.js)
112
- _POSTCSS_CONFIG=$(_pick_config "$_APP_DIR" postcss.config.js)
113
- _SWC_CONFIG=$(_pick_config "$_APP_DIR" .swcrc)
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)
114
164
  # A single file has no robots.txt next to it. Webpack drops an --env with an
115
165
  # empty value, so the config gets no robotsPath
116
166
  _ROBOTS_FILE=""
117
167
  if [ -z "$_IS_SINGLE_FILE" ]; then
118
- _ROBOTS_FILE=$(_pick_file \
119
- "$_APP_DIR/src/public/robots.txt" "$_VB_DIR/src/public/robots.txt")
168
+ _ROBOTS_FILE=$(_pick_file "$_APP_DIR" src/public/robots.txt)
120
169
  fi
121
- _FAVICON_FILE=$(_pick_file \
122
- "$_APP_DIR/src/public/favicon.svg" "$_VB_DIR/src/public/favicon.svg")
170
+ _FAVICON_FILE=$(_pick_file "$_APP_DIR" src/public/favicon.svg)
123
171
 
124
172
  _ARTIFACT="SPA bundle"
125
173
  if [ -n "$_IS_SINGLE_FILE" ]; then
@@ -1,9 +1,36 @@
1
1
  #!/bin/sh
2
2
 
3
- # vblocks eject <webpack|postcss|swc>
3
+ # NAME
4
+ # vblocks eject - Print a default config of VBlocks
4
5
  #
5
- # Print a default config, to save in the app folder. vblocks runs this file.
6
- # Never call it directly.
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.
7
34
 
8
35
  set -eu
9
36
 
@@ -24,6 +51,10 @@ _EJECT_CONFIG="" # eject <config>
24
51
  [ "$#" -ne 1 ] && _fail 2 -v available_configs "webpack,postcss,swc" "eject needs one config"
25
52
 
26
53
  case "$1" in
54
+ -h | --help)
55
+ _show_help "$0"
56
+ exit 0
57
+ ;;
27
58
  webpack) _EJECT_CONFIG="webpack.config.js" ;;
28
59
  postcss) _EJECT_CONFIG="postcss.config.js" ;;
29
60
  swc) _EJECT_CONFIG=".swcrc" ;;
@@ -34,5 +65,5 @@ esac
34
65
  # │ Main
35
66
  # ╰───
36
67
 
37
- cat -- "$_VB_DIR/src/$_EJECT_CONFIG"
68
+ cat -- "$_VB_DIR/defaults/$_EJECT_CONFIG"
38
69
  exit 0
@@ -1,9 +1,53 @@
1
1
  #!/bin/sh
2
2
 
3
- # vblocks init <directory> [--template <name>] [--only <app|plumbing>]
3
+ # NAME
4
+ # vblocks init - Write a template into a folder
4
5
  #
5
- # Write a template into <directory>, then print each file it adds, updates or
6
- # drops. vblocks runs this file. Never call it directly.
6
+ # SYNOPSIS
7
+ # vblocks init <directory>
8
+ # [--template <plain|xyflow|xyflow-tabs>]
9
+ # [--only <app|plumbing>]
10
+ #
11
+ # DESCRIPTION
12
+ # A template has two parts: the plumbing, which holds the files of the
13
+ # project folder, and the app, which holds the files of the app folder.
14
+ # After each part, run its post-init hooks in <directory>.
15
+ #
16
+ # Print the project folder and each file init adds, updates or drops, then
17
+ # the next steps.
18
+ #
19
+ # ARGUMENTS
20
+ # directory The folder to write into, missing or empty
21
+ #
22
+ # OPTIONS
23
+ # --template <name> The template, plain, xyflow or xyflow-tabs (default:
24
+ # plain)
25
+ # --only <part> Write only the app or only the plumbing (default:
26
+ # both). With app, init adds the template's
27
+ # dependencies to the package.json of the project
28
+ # folder, the parent of <directory>. That package.json
29
+ # must exist
30
+ # -h, --help Print this help
31
+ #
32
+ # ENVIRONMENT
33
+ # NO_COLOR When non-empty, print without color or the header
34
+ #
35
+ # EXAMPLE
36
+ # npx @asd14/vblocks init my-app
37
+ # npx @asd14/vblocks init demos --only plumbing
38
+ # npx @asd14/vblocks init demos/flow --template xyflow --only app
39
+ #
40
+ # EXIT CODES
41
+ # 0 Done
42
+ # 2 Invalid usage, an unknown template, or a <directory> that is not empty
43
+ # or not a folder
44
+ # 3 Could not run: a missing tool, no package.json in the project folder,
45
+ # a folder init could not add, or a failed copy or hook
46
+ #
47
+ # SEE ALSO
48
+ # vblocks, vblocks serve, node, npm
49
+
50
+ # vblocks runs this file. Never call it directly.
7
51
 
8
52
  set -eu
9
53
 
@@ -35,6 +79,21 @@ _shorten_path() {
35
79
  esac
36
80
  }
37
81
 
82
+ # _quote_path <path>
83
+ #
84
+ # Print <path> in single quotes, so a shell reads it back as one word. A
85
+ # leading "~/" stays out of the quotes, so the shell still expands it.
86
+ _quote_path() {
87
+ # shellcheck disable=SC2088 # a literal "~", for display
88
+ case "$1" in
89
+ "~/"*) qp_home="~/" qp_path=${1#"~/"} ;;
90
+ *) qp_home="" qp_path=$1 ;;
91
+ esac
92
+
93
+ # End the quotes, add an escaped quote, open them again: ' becomes '\''
94
+ printf "%s'%s'\n" "$qp_home" "$(printf '%s' "$qp_path" | sed "s/'/'\\\\''/g")"
95
+ }
96
+
38
97
  # ╭───
39
98
  # │ Domain primitives
40
99
  # ╰───
@@ -157,27 +216,27 @@ _print_init_summary() {
157
216
 
158
217
  # _print_next_steps <parts> <init-dir> <project-dir> <init-abs-dir>
159
218
  #
160
- # Print the commands that run the new project. <init-dir> is the folder as the
161
- # user typed it, <init-abs-dir> its absolute path.
219
+ # Print the next step and its command, in one line: for the plumbing, the init
220
+ # of an app, otherwise the install and the serve of the app. <init-dir> is
221
+ # <directory> as init prints it. <project-dir> and <init-abs-dir> are the
222
+ # absolute paths of the project folder and of <directory>.
162
223
  _print_next_steps() {
163
224
  case "$1" in
164
225
  plumbing)
165
- printf '\nNext, add an app:\n'
166
- printf ' npx @asd14/vblocks init %s/<app> --only app\n' "$2"
226
+ _info -v add_cmd "npx @asd14/vblocks init $(_quote_path "$2")/your-app-name --only app" \
227
+ "Next, add an app"
167
228
  ;;
168
229
  app)
169
- printf '\nNext:\n'
230
+ pns_cd=""
170
231
  if [ "$3" != "$PWD" ]; then
171
- printf ' cd %s\n' "$(_shorten_path "$3")"
232
+ pns_cd="cd $(_quote_path "$(_shorten_path "$3")") && "
172
233
  fi
173
- printf ' npm install\n'
174
- printf ' npx vblocks serve --prefix %s\n' "${4#"$3"/}"
234
+ _info -v serve_cmd "${pns_cd}npm install && npx vblocks serve --prefix $(_quote_path "${4#"$3"/}")" \
235
+ "Next, serve the app"
175
236
  ;;
176
237
  *)
177
- printf '\nNext:\n'
178
- printf ' cd %s\n' "$2"
179
- printf ' npm install\n'
180
- printf ' npx vblocks serve\n'
238
+ _info -v serve_cmd "cd $(_quote_path "$2") && npm install && npx vblocks serve" \
239
+ "Next, serve the app"
181
240
  ;;
182
241
  esac
183
242
  }
@@ -188,6 +247,10 @@ _print_next_steps() {
188
247
 
189
248
  while [ "$#" -gt 0 ]; do
190
249
  case "$1" in
250
+ -h | --help)
251
+ _show_help "$0"
252
+ exit 0
253
+ ;;
191
254
  --template)
192
255
  [ "$#" -lt 2 ] && _fail 2 -v available_templates "$(_list_templates)" "--template needs a name"
193
256
  _TEMPLATE=$2
@@ -1,8 +1,55 @@
1
1
  #!/bin/sh
2
2
 
3
- # vblocks serve [OPTIONS] [-- <webpack option>...]
3
+ # NAME
4
+ # vblocks serve - Start the development server of an app
4
5
  #
5
- # Start the development server. vblocks runs this file. Never call it directly.
6
+ # SYNOPSIS
7
+ # vblocks serve
8
+ # [--mode <development|production>]
9
+ # [--prefix <directory>]
10
+ # [--analyze]
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 start the server.
22
+ #
23
+ # OPTIONS
24
+ # --mode <mode> The Webpack mode, development or production
25
+ # (default: development)
26
+ # --prefix <directory> The app folder, which must exist (default: the
27
+ # current folder)
28
+ # --analyze Run the bundle analyzer, on a free port. An
29
+ # ejected webpack.config.js must read
30
+ # env.analyze
31
+ # --log-level <level> How much Webpack and its development server
32
+ # print: error, warn, info or verbose (default:
33
+ # warn)
34
+ # -- <webpack option>... Pass each option to Webpack, unchanged
35
+ # -h, --help Print this help
36
+ #
37
+ # ENVIRONMENT
38
+ # NO_COLOR When non-empty, print without color, the icons or the header
39
+ #
40
+ # EXAMPLE
41
+ # npx vblocks serve
42
+ # npx vblocks serve --prefix flow -- --host 0.0.0.0
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 build, vblocks eject, webpack
51
+
52
+ # vblocks runs this file. Never call it directly.
6
53
 
7
54
  set -eu
8
55
 
@@ -27,6 +74,10 @@ _SHOULD_ANALYZE="" # --analyze, "true" or ""
27
74
 
28
75
  while [ "$#" -gt 0 ]; do
29
76
  case "$1" in
77
+ -h | --help)
78
+ _show_help "$0"
79
+ exit 0
80
+ ;;
30
81
  --prefix)
31
82
  [ "$#" -lt 2 ] && _fail 2 "--prefix needs a folder"
32
83
  _PREFIX_DIR=$2
@@ -75,13 +126,11 @@ _export_version
75
126
  # ╰───
76
127
 
77
128
  _APP_DIR=$(cd -- "${_PREFIX_DIR:-.}" && pwd)
78
- _WEBPACK_CONFIG=$(_pick_config "$_APP_DIR" webpack.config.js)
79
- _POSTCSS_CONFIG=$(_pick_config "$_APP_DIR" postcss.config.js)
80
- _SWC_CONFIG=$(_pick_config "$_APP_DIR" .swcrc)
81
- _ROBOTS_FILE=$(_pick_file \
82
- "$_APP_DIR/src/public/robots.txt" "$_VB_DIR/src/public/robots.txt")
83
- _FAVICON_FILE=$(_pick_file \
84
- "$_APP_DIR/src/public/favicon.svg" "$_VB_DIR/src/public/favicon.svg")
129
+ _WEBPACK_CONFIG=$(_pick_file "$_APP_DIR" webpack.config.js)
130
+ _POSTCSS_CONFIG=$(_pick_file "$_APP_DIR" postcss.config.js)
131
+ _SWC_CONFIG=$(_pick_file "$_APP_DIR" .swcrc)
132
+ _ROBOTS_FILE=$(_pick_file "$_APP_DIR" src/public/robots.txt)
133
+ _FAVICON_FILE=$(_pick_file "$_APP_DIR" src/public/favicon.svg)
85
134
 
86
135
  _print_header "$VB_VERSION" "${_BOLD}serve${_RESET}: $_MODE${_SHOULD_ANALYZE:+, analyze}" >&2
87
136
  _print_summary "$_APP_DIR" "$_WEBPACK_CONFIG" "$_POSTCSS_CONFIG" "$_SWC_CONFIG" \
@@ -13,8 +13,11 @@ _VB_DIR=$(dirname "$(dirname "$_SCRIPT_DIR")")
13
13
  # shellcheck source=lib.sh
14
14
  . "$_SCRIPT_DIR/lib.sh"
15
15
 
16
- # _log reads LOG_NAMESPACE, LOG_LEVEL and NO_LOG_TIME. VBlocks logs only errors,
17
- # through _fail. The time adds no fact to an error
16
+ # _log reads LOG_NAMESPACE, LOG_LEVEL and NO_LOG_TIME.
17
+ #
18
+ # - NO_LOG_TIME drops the time, which adds no fact to a message
19
+ # - Send each stderr message through _ok, _info, _warn or _fail
20
+ # - Only the header, the summaries and `help` print on their own
18
21
  LOG_NAMESPACE="vblocks"
19
22
  LOG_LEVEL="info"
20
23
  NO_LOG_TIME="true"
@@ -1,22 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
- # webpack.sh - The primitives of serve and build: the --log-level guard, the
4
- # configs, the summary and the Webpack run
5
-
6
- # ╭───
7
- # │ Primitives
8
- # ╰───
9
-
10
- # _pick_file <file> <default-file>
11
- #
12
- # Print <file> when it exists, otherwise <default-file>.
13
- _pick_file() {
14
- if [ -f "$1" ]; then
15
- printf '%s\n' "$1"
16
- else
17
- printf '%s\n' "$2"
18
- fi
19
- }
3
+ # webpack.sh - The primitives of serve and build: the --mode and --log-level
4
+ # guards, the defaults, the summary and the Webpack run
20
5
 
21
6
  # ╭───
22
7
  # │ Domain primitives
@@ -48,12 +33,17 @@ _guard_mode() {
48
33
  esac
49
34
  }
50
35
 
51
- # _pick_config <app-dir> <file>
36
+ # _pick_file <app-dir> <path>
52
37
  #
53
- # Print <file> in <app-dir> when it exists, otherwise the default of VBlocks in
54
- # src/.
55
- _pick_config() {
56
- _pick_file "$1/$2" "$_VB_DIR/src/$2"
38
+ # Print <path> in <app-dir> when the file exists, otherwise the default of
39
+ # VBlocks at the same <path> in defaults/. defaults/ is laid out like an app
40
+ # folder.
41
+ _pick_file() {
42
+ if [ -f "$1/$2" ]; then
43
+ printf '%s\n' "$1/$2"
44
+ else
45
+ printf '%s\n' "$_VB_DIR/defaults/$2"
46
+ fi
57
47
  }
58
48
 
59
49
  # _print_file_path <file> <app-dir>
@@ -0,0 +1,14 @@
1
+ import cssnano from "cssnano"
2
+ import postcssPresetEnv from "postcss-preset-env"
3
+
4
+ /**
5
+ * Import the plugins, so Node resolves them from this file's folder
6
+ *
7
+ * @param {{ mode: "production" | "development" | "none" }} api
8
+ */
9
+ export default ({ mode }) => ({
10
+ plugins: [
11
+ postcssPresetEnv({ stage: 2 }),
12
+ ...(mode === "production" ? [cssnano({ preset: "default" })] : []),
13
+ ],
14
+ })
@@ -1,6 +1,8 @@
1
1
  /** @typedef {import("webpack").Configuration} WebpackConfiguration */
2
2
 
3
3
  import fs from "node:fs"
4
+ import { createRequire } from "node:module"
5
+ import path from "node:path"
4
6
  import "webpack-dev-server"
5
7
  import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin"
6
8
  import CopyPlugin from "copy-webpack-plugin"
@@ -507,6 +509,12 @@ export default (
507
509
  extensions: [".tsx", ".ts", ".jsx", ".js"],
508
510
  alias: {
509
511
  "@self": `${entryDir}/src`,
512
+ // React Refresh imports the dev server's client. Use the one VBlocks runs
513
+ "webpack-dev-server": path.dirname(
514
+ createRequire(import.meta.url).resolve(
515
+ "webpack-dev-server/package.json"
516
+ )
517
+ ),
510
518
  },
511
519
  },
512
520
 
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": "6.0.0",
4
+ "version": "6.1.0",
5
5
  "description": "Zero-config React builds, as a static site or a single HTML file",
6
6
  "keywords": [
7
7
  "react",
@@ -34,13 +34,14 @@
34
34
  },
35
35
  "files": [
36
36
  "bin",
37
- "src",
38
- "template"
37
+ "defaults",
38
+ "template",
39
+ "types"
39
40
  ],
40
41
  "type": "module",
41
42
  "exports": {
42
43
  "./client": {
43
- "types": "./src/types/client.d.ts"
44
+ "types": "./types/client.d.ts"
44
45
  },
45
46
  "./package.json": "./package.json"
46
47
  },
@@ -53,7 +54,9 @@
53
54
  "format": "eslint --fix .",
54
55
  "----CODE-QA": "",
55
56
  "lint": "eslint .",
56
- "typecheck": "tsc --noEmit",
57
+ "typecheck:code": "tsc --noEmit --project ./.tsconfig/code.json",
58
+ "typecheck:client-types": "tsc --noEmit --project ./.tsconfig/client-types.json",
59
+ "typecheck": "npm run typecheck:code && npm run typecheck:client-types",
57
60
  "unit-test:template": "tools/verify-templates",
58
61
  "unit-test": "npm run unit-test:template"
59
62
  },
@@ -61,32 +64,33 @@
61
64
  "@mdx-js/loader": "^3.1.1",
62
65
  "@pmmmwh/react-refresh-webpack-plugin": "^0.6.3",
63
66
  "@swc/helpers": "^0.5.23",
64
- "browserslist": "^4.29.3",
67
+ "browserslist": "^4.29.4",
65
68
  "copy-webpack-plugin": "^14.0.0",
66
69
  "css-loader": "^7.1.5",
67
70
  "cssnano": "^9.9.0",
68
71
  "dotenv-webpack": "^9.0.0",
69
72
  "html-webpack-plugin": "^5.6.8",
70
73
  "mini-css-extract-plugin": "^2.10.2",
71
- "postcss": "^8.5.30",
74
+ "postcss": "^8.5.31",
72
75
  "postcss-loader": "^8.2.1",
73
76
  "postcss-preset-env": "^11.6.1",
74
77
  "react-refresh": "^0.19.0",
75
78
  "swc-loader": "^0.2.7",
76
- "webpack": "^5.112.0",
79
+ "webpack": "^5.112.1",
77
80
  "webpack-bundle-analyzer": "^5.4.0",
78
81
  "webpack-cli": "^7.2.3",
79
- "webpack-dev-server": "^6.0.0"
82
+ "webpack-dev-server": "^6.1.0"
80
83
  },
81
84
  "devDependencies": {
82
- "@asd14/eslint-config": "^16.0.0",
85
+ "@asd14/eslint-config": "^16.2.0",
83
86
  "@asd14/prettier-config": "^1.5.0",
84
- "@asd14/semantic-release-config": "^1.0.1",
87
+ "@asd14/semantic-release-config": "^1.1.0",
85
88
  "@asd14/ts-config": "^1.6.0",
86
- "@commitlint/cli": "^21.2.3",
87
- "@commitlint/config-conventional": "^21.2.3",
89
+ "@commitlint/cli": "^21.2.4",
90
+ "@commitlint/config-conventional": "^21.2.4",
88
91
  "@tailwindcss/postcss": "^4.3.3",
89
92
  "@types/dotenv-webpack": "^7.0.8",
93
+ "@types/react": "^19.3.0",
90
94
  "@types/webpack-bundle-analyzer": "^4.7.0",
91
95
  "@xyflow/react": "^12.12.0",
92
96
  "eslint": "^9.39.5",
@@ -1,13 +1,14 @@
1
+ import tailwindcss from "@tailwindcss/postcss"
2
+ import cssnano from "cssnano"
3
+
1
4
  /**
5
+ * Import the plugins, so Node resolves them from this file's folder
6
+ *
2
7
  * @param {{ mode: "production" | "development" | "none" }} api
3
8
  */
4
9
  export default ({ mode }) => ({
5
- plugins: {
6
- "@tailwindcss/postcss": {
7
- optimize: mode === "production",
8
- },
9
- "cssnano": mode === "production" && {
10
- preset: "default",
11
- },
12
- },
10
+ plugins: [
11
+ tailwindcss({ optimize: mode === "production" }),
12
+ ...(mode === "production" ? [cssnano({ preset: "default" })] : []),
13
+ ],
13
14
  })
@@ -8,6 +8,7 @@ set -eu
8
8
  npm pkg set \
9
9
  "dependencies.@xyflow/react=^12" \
10
10
  "devDependencies.@tailwindcss/postcss=^4" \
11
+ "devDependencies.cssnano=^9" \
11
12
  "devDependencies.tailwindcss=^4"
12
13
 
13
14
  # Name the page in the browser tab.
@@ -1,13 +1,14 @@
1
+ import tailwindcss from "@tailwindcss/postcss"
2
+ import cssnano from "cssnano"
3
+
1
4
  /**
5
+ * Import the plugins, so Node resolves them from this file's folder
6
+ *
2
7
  * @param {{ mode: "production" | "development" | "none" }} api
3
8
  */
4
9
  export default ({ mode }) => ({
5
- plugins: {
6
- "@tailwindcss/postcss": {
7
- optimize: mode === "production",
8
- },
9
- "cssnano": mode === "production" && {
10
- preset: "default",
11
- },
12
- },
10
+ plugins: [
11
+ tailwindcss({ optimize: mode === "production" }),
12
+ ...(mode === "production" ? [cssnano({ preset: "default" })] : []),
13
+ ],
13
14
  })
@@ -8,6 +8,7 @@ set -eu
8
8
  npm pkg set \
9
9
  "dependencies.@xyflow/react=^12" \
10
10
  "devDependencies.@tailwindcss/postcss=^4" \
11
+ "devDependencies.cssnano=^9" \
11
12
  "devDependencies.tailwindcss=^4"
12
13
 
13
14
  # Name the page in the browser tab.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Types for the files `../webpack.config.js` teaches `import` to load.
2
+ * Types for the files `../defaults/webpack.config.js` teaches `import` to load.
3
3
  *
4
4
  * @example
5
5
  * // tsconfig.json
@@ -1,13 +0,0 @@
1
- /**
2
- * @param {{ mode: "production" | "development" | "none" }} api
3
- */
4
- export default ({ mode }) => ({
5
- plugins: {
6
- "postcss-preset-env": {
7
- stage: 2,
8
- },
9
- "cssnano": mode === "production" && {
10
- preset: "default",
11
- },
12
- },
13
- })
File without changes
File without changes
File without changes