@asd14/vblocks 6.4.0 → 7.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.
@@ -6,28 +6,38 @@
6
6
  # SYNOPSIS
7
7
  # vblocks serve
8
8
  # [--mode <development|production>]
9
- # [--prefix <directory>]
9
+ # [--prefix <folder>]
10
10
  # [--analyze]
11
11
  # [--log-level <error|warn|info|verbose>]
12
12
  # [-- <webpack option>...]
13
13
  #
14
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
15
+ # The app folder contains src/index.tsx and src/index.html. A config in it,
16
+ # webpack.config.js, postcss.config.js, .swcrc or .browserslistrc, replaces
17
+ # the VBlocks default of the same name. So do src/public/robots.txt and
18
18
  # src/public/favicon.svg.
19
19
  #
20
- # Print the app folder, the VBlocks folder and the files Webpack runs with,
21
- # then start the server.
20
+ # Print the app folder, the VBlocks folder, the files Webpack runs with and
21
+ # the source of the browsers, then start the server.
22
+ #
23
+ # SWC, Webpack and postcss-preset-env compile for the browsers of the app's
24
+ # browserslist config. browserslist reads BROWSERSLIST, BROWSERSLIST_CONFIG,
25
+ # then a .browserslistrc or the browserslist field of package.json, from the
26
+ # app folder up. Without any of them, browserslist reads the VBlocks default,
27
+ # defaults/.browserslistrc.
28
+ #
29
+ # The server runs at http://localhost:8080, or the next free port. It opens
30
+ # the page in the browser. It listens on localhost, so another device cannot
31
+ # open the page. Pass -- --host 0.0.0.0 to expose it to the network.
22
32
  #
23
33
  # OPTIONS
24
34
  # --mode <mode> The Webpack mode, development or production
25
35
  # (default: development)
26
- # --prefix <directory> The app folder, which must exist (default: the
36
+ # --prefix <folder> The app folder, which must exist (default: the
27
37
  # current folder)
28
38
  # --analyze Run the bundle analyzer, on a free port. An
29
- # ejected webpack.config.js must read
30
- # env.analyze
39
+ # ejected webpack.config.js runs the analyzer
40
+ # only if it reads env.analyze
31
41
  # --log-level <level> How much Webpack and its development server
32
42
  # print: error, warn, info or verbose (default:
33
43
  # warn)
@@ -35,7 +45,12 @@
35
45
  # -h, --help Print this help
36
46
  #
37
47
  # ENVIRONMENT
38
- # NO_COLOR When non-empty, print without color, the icons or the header
48
+ # NO_COLOR When non-empty, print without color, the icons or
49
+ # the header
50
+ # BROWSERSLIST The browsers, as a browserslist query. It overrides
51
+ # every config file
52
+ # BROWSERSLIST_CONFIG The path of a browserslist config, in place of the
53
+ # one browserslist finds from the app folder up
39
54
  #
40
55
  # EXAMPLE
41
56
  # npx vblocks serve
@@ -43,7 +58,8 @@
43
58
  #
44
59
  # EXIT CODES
45
60
  # 0 Done
46
- # 2 Invalid usage, or Webpack rejected an option or the config
61
+ # 2 Invalid usage, Webpack rejected an option or the config, or
62
+ # browserslist could not read a config
47
63
  # 3 Could not run: a missing tool, or a failed Webpack run
48
64
  #
49
65
  # SEE ALSO
@@ -63,6 +79,10 @@ _SCRIPT_DIR=$(dirname "$0")
63
79
  . "$_SCRIPT_DIR/lib/guard.sh"
64
80
  # shellcheck source=lib/help.sh
65
81
  . "$_SCRIPT_DIR/lib/help.sh"
82
+ # shellcheck source=lib/os.sh
83
+ . "$_SCRIPT_DIR/lib/os.sh"
84
+ # shellcheck source=lib/terminal.sh
85
+ . "$_SCRIPT_DIR/lib/terminal.sh"
66
86
  # shellcheck source=vblocks.sh
67
87
  . "$_SCRIPT_DIR/vblocks.sh"
68
88
  # shellcheck source=webpack.sh
@@ -140,10 +160,13 @@ _POSTCSS_CONFIG=$(_pick_file "$_APP_DIR" postcss.config.js)
140
160
  _SWC_CONFIG=$(_pick_file "$_APP_DIR" .swcrc)
141
161
  _ROBOTS_FILE=$(_pick_file "$_APP_DIR" src/public/robots.txt)
142
162
  _FAVICON_FILE=$(_pick_file "$_APP_DIR" src/public/favicon.svg)
163
+ _pick_browserslist "$_APP_DIR"
164
+ _BROWSERSLIST_SOURCE=$(_find_browserslist "$_APP_DIR")
165
+ _set_command_title serve "$(basename -- "$_APP_DIR")"
143
166
 
144
167
  _print_header "$VB_VERSION" "${_BOLD}serve${_RESET}: $_MODE${_SHOULD_ANALYZE:+, analyze}" >&2
145
168
  _print_summary "$_APP_DIR" "$_WEBPACK_CONFIG" "$_POSTCSS_CONFIG" "$_SWC_CONFIG" \
146
- "$_ROBOTS_FILE" "$_FAVICON_FILE"
169
+ "$_ROBOTS_FILE" "$_FAVICON_FILE" "$_BROWSERSLIST_SOURCE"
147
170
 
148
171
  # The default Webpack config reads env.analyze. An ejected config supports
149
172
  # --analyze only if it reads env.analyze too
@@ -1,9 +1,10 @@
1
1
  #!/bin/sh
2
2
 
3
3
  # vblocks.sh - What every command of vblocks shares:
4
- # - the folders, the styles of the output and the header
4
+ # - the folders, the styles of the output, the header and the window title
5
5
  #
6
- # Needs lib/log.sh. The command needs to source it before this file.
6
+ # Needs lib/log.sh. _set_command_title also needs lib/os.sh and
7
+ # lib/terminal.sh. The command sources them before this file.
7
8
 
8
9
  # The caller sets _SCRIPT_DIR to the folder of vblocks.sh, then sources it
9
10
  : "${_SCRIPT_DIR:?the caller sets _SCRIPT_DIR before it sources vblocks.sh}"
@@ -74,6 +75,16 @@ _print_header() {
74
75
  printf '╰──┤\n'
75
76
  }
76
77
 
78
+ # _set_command_title <command> <subject>
79
+ #
80
+ # Set the title of the terminal window to "<command> <subject> :: vblocks", eg.
81
+ # "serve flow :: vblocks", until the command exits. <subject> is what the
82
+ # command works on, eg. the app folder. It comes first, because a tab bar cuts
83
+ # a long title at its end.
84
+ _set_command_title() {
85
+ _set_title_until_exit "$1 $2 :: vblocks"
86
+ }
87
+
77
88
  # ╭───
78
89
  # │ Bootstrap
79
90
  # ╰───
@@ -48,6 +48,87 @@ _pick_file() {
48
48
  fi
49
49
  }
50
50
 
51
+ # _resolve_vblocks_file <request>
52
+ #
53
+ # Print the absolute path of <request>, eg. `webpack-cli/bin/cli.js`, as Node
54
+ # resolves it from the VBlocks folder. npm nests or hoists each dependency of
55
+ # VBlocks so that this lookup finds it.
56
+ _resolve_vblocks_file() {
57
+ node -p 'require.resolve(process.argv[1], { paths: [process.argv[2]] })' \
58
+ "$1" "$_VB_DIR"
59
+ }
60
+
61
+ # _find_browserslist <app-dir>
62
+ #
63
+ # Print the first source browserslist finds for the browsers of <app-dir>:
64
+ # BROWSERSLIST=<query>, BROWSERSLIST_CONFIG=<file>, or the config file from
65
+ # <app-dir> up. Print nothing when browserslist finds none.
66
+ #
67
+ # EXIT
68
+ # 2 browserslist could not read a config, eg. one folder has both a
69
+ # .browserslistrc and the browserslist field of package.json
70
+ # 3 Could not find the browserslist of VBlocks
71
+ _find_browserslist() {
72
+ fb_lib_file=$(_resolve_vblocks_file browserslist) ||
73
+ _fail 3 "Could not find the browserslist of VBlocks"
74
+
75
+ # loadConfig follows the order of browserslist, so VBlocks does not repeat
76
+ # it. VBlocks reads the two variables only to label the source. loadConfig
77
+ # reads them before any file, so the first one set is the source
78
+ # shellcheck disable=SC2016 # JavaScript, not shell
79
+ fb_source=$(node -e '
80
+ const browserslist = require(process.argv[1])
81
+ const appDir = process.argv[2]
82
+ try {
83
+ if (browserslist.loadConfig({ path: appDir }) === undefined) {
84
+ console.log("none")
85
+ } else if (process.env.BROWSERSLIST) {
86
+ console.log(`BROWSERSLIST=${process.env.BROWSERSLIST}`)
87
+ } else if (process.env.BROWSERSLIST_CONFIG) {
88
+ console.log(`BROWSERSLIST_CONFIG=${process.env.BROWSERSLIST_CONFIG}`)
89
+ } else {
90
+ console.log(browserslist.findConfigFile(appDir))
91
+ }
92
+ } catch (error) {
93
+ console.log(`error ${error.message}`)
94
+ }
95
+ ' "$fb_lib_file" "$1")
96
+
97
+ case "$fb_source" in
98
+ none) ;;
99
+ "error "*) _fail 2 -v reason "${fb_source#error }" "browserslist could not read the browsers of the app" ;;
100
+ *) printf '%s\n' "$fb_source" ;;
101
+ esac
102
+ }
103
+
104
+ # _pick_browserslist <app-dir>
105
+ #
106
+ # Export BROWSERSLIST_CONFIG with the VBlocks default, when browserslist finds
107
+ # no config for <app-dir>. SWC, Webpack and postcss-preset-env then read it.
108
+ #
109
+ # EXIT
110
+ # 2 browserslist could not read a config, see _find_browserslist
111
+ # 3 Could not find the browserslist of VBlocks
112
+ _pick_browserslist() {
113
+ pb_source=$(_find_browserslist "$1")
114
+ if [ -z "$pb_source" ]; then
115
+ BROWSERSLIST_CONFIG="$_VB_DIR/defaults/.browserslistrc"
116
+ export BROWSERSLIST_CONFIG
117
+ fi
118
+ }
119
+
120
+ # _print_browserslist_source <source> <app-dir>
121
+ #
122
+ # Print <source>, what _find_browserslist prints: a file as _print_file_path
123
+ # does, the VBlocks default in gray, and a variable the User set as it is.
124
+ _print_browserslist_source() {
125
+ case "$1" in
126
+ BROWSERSLIST_CONFIG="$_VB_DIR/defaults/.browserslistrc") _print_file_path "${1#BROWSERSLIST_CONFIG=}" "$2" ;;
127
+ BROWSERSLIST=* | BROWSERSLIST_CONFIG=*) printf '%s\n' "$1" ;;
128
+ *) _print_file_path "$1" "$2" ;;
129
+ esac
130
+ }
131
+
51
132
  # _print_file_path <file> <app-dir>
52
133
  #
53
134
  # Print the path of <file>, its folder as $APP_DIR, or as $VBLOCKS_DIR in gray
@@ -60,20 +141,22 @@ _print_file_path() {
60
141
  esac
61
142
  }
62
143
 
63
- # _print_summary <app-dir> <webpack-config> <postcss-config> <swc-config> <robots-file> <favicon-file>
144
+ # _print_summary <app-dir> <webpack-config> <postcss-config> <swc-config> <robots-file> <favicon-file> <browserslist-source>
64
145
  #
65
- # Print the app folder, the VBlocks folder and the files Webpack runs with. An
66
- # empty <robots-file> prints no Robots line.
146
+ # Print the app folder, the VBlocks folder, the files Webpack runs with and the
147
+ # source of the browsers. An empty <robots-file> prints no Robots line.
148
+ # <browserslist-source> is what _find_browserslist prints.
67
149
  _print_summary() {
68
150
  # The icons of the tools and the files, only on a terminal
69
151
  ps_webpack_icon="" ps_postcss_icon="" ps_swc_icon=""
70
- ps_robots_icon="" ps_favicon_icon=""
152
+ ps_robots_icon="" ps_favicon_icon="" ps_browsers_icon=""
71
153
  if [ -n "$_IS_TERMINAL" ]; then
72
154
  ps_webpack_icon=" "
73
155
  ps_postcss_icon=" "
74
156
  ps_swc_icon="󱡮 "
75
157
  ps_robots_icon="󰚩 "
76
158
  ps_favicon_icon=" "
159
+ ps_browsers_icon="󰖟 "
77
160
  fi
78
161
 
79
162
  printf '%s\t%s\n' "${_BOLD}\$APP_DIR${_RESET}" "$(_shorten_home "$1")"
@@ -82,6 +165,7 @@ _print_summary() {
82
165
  printf '%s\t%s\n' "${ps_webpack_icon}${_BOLD}Webpack${_RESET}" "$(_print_file_path "$2" "$1")"
83
166
  printf '%s\t%s\n' "${ps_postcss_icon}${_BOLD}PostCSS${_RESET}" "$(_print_file_path "$3" "$1")"
84
167
  printf '%s\t%s\n' "${ps_swc_icon}${_BOLD}SWC${_RESET}" "$(_print_file_path "$4" "$1")"
168
+ printf '%s\t%s\n' "${ps_browsers_icon}${_BOLD}Browsers${_RESET}" "$(_print_browserslist_source "$7" "$1")"
85
169
  if [ -n "$5" ]; then
86
170
  printf '%s\t%s\n' "${ps_robots_icon}${_BOLD}Robots${_RESET}" "$(_print_file_path "$5" "$1")"
87
171
  fi
@@ -91,12 +175,12 @@ _print_summary() {
91
175
 
92
176
  # _run_webpack <action> <webpack-config> [<webpack option>...]
93
177
  #
94
- # Run `webpack <action>` with <webpack-config> and the options, through the
95
- # webpack-cli of VBlocks.
178
+ # Run `webpack <action>` with <webpack-config> and the options. Use the
179
+ # webpack-cli, the webpack and the webpack-dev-server of VBlocks.
96
180
  #
97
181
  # EXIT
98
182
  # 2 Webpack rejected an option or the config
99
- # 3 Webpack failed
183
+ # 3 Could not find a package of VBlocks, or Webpack failed
100
184
  _run_webpack() {
101
185
  rw_action=$1
102
186
  rw_config=$2
@@ -105,12 +189,27 @@ _run_webpack() {
105
189
  # Run the webpack-cli of VBlocks, the version VBlocks depends on. npx
106
190
  # would run the first one it finds from the current folder, or offer to
107
191
  # install one
108
- rw_cli_file=$(node -p \
109
- 'require.resolve("webpack-cli/bin/cli.js", { paths: [process.argv[1]] })' \
110
- "$_VB_DIR") || _fail 3 "Could not find the webpack-cli of VBlocks"
192
+ rw_cli_file=$(_resolve_vblocks_file webpack-cli/bin/cli.js) ||
193
+ _fail 3 "Could not find the webpack-cli of VBlocks"
194
+
195
+ # Pass webpack-cli the webpack and the webpack-dev-server of VBlocks.
196
+ # webpack-cli resolves both from its own folder, where npm can place another
197
+ # copy. webpack-cli declares webpack-dev-server only as an optional peer, so
198
+ # npm can place none there
199
+ rw_webpack_file=$(_resolve_vblocks_file webpack) ||
200
+ _fail 3 "Could not find the webpack of VBlocks"
201
+ rw_dev_server_file=$(_resolve_vblocks_file webpack-dev-server) ||
202
+ _fail 3 "Could not find the webpack-dev-server of VBlocks"
111
203
 
204
+ # The path picks the copy of VBlocks, but that copy first resolves
205
+ # webpack-cli from the current folder, and runs any other copy it finds.
206
+ # WEBPACK_CLI_SKIP_IMPORT_LOCAL skips that check
112
207
  rw_status=0
113
- node "$rw_cli_file" "$rw_action" --config "$rw_config" "$@" || rw_status=$?
208
+ WEBPACK_CLI_SKIP_IMPORT_LOCAL=true \
209
+ WEBPACK_PACKAGE=$rw_webpack_file \
210
+ WEBPACK_DEV_SERVER_PACKAGE=$rw_dev_server_file \
211
+ node "$rw_cli_file" "$rw_action" --config "$rw_config" "$@" ||
212
+ rw_status=$?
114
213
 
115
214
  # webpack-cli exits 1 when the build has errors, 2 when an option or the
116
215
  # config is wrong
@@ -0,0 +1,2 @@
1
+ # The browsers SWC, Webpack and postcss-preset-env compile for
2
+ > 0.25%, not dead
package/defaults/.swcrc CHANGED
@@ -4,8 +4,7 @@
4
4
  "sourceMaps": true,
5
5
  "env": {
6
6
  "mode": "entry",
7
- "coreJs": "3.22",
8
- "targets": "> 0.25%, not dead"
7
+ "coreJs": "3.22"
9
8
  },
10
9
  "jsc": {
11
10
  "externalHelpers": true,
@@ -1,28 +1,32 @@
1
+ /// <reference types="webpack-dev-server" />
1
2
  /** @typedef {import("webpack").Configuration} WebpackConfiguration */
2
3
 
3
4
  import fs from "node:fs"
4
5
  import { createRequire } from "node:module"
5
6
  import path from "node:path"
6
- import "webpack-dev-server"
7
7
  import { buildLogger } from "@asd14/fancy-logger/node"
8
8
  import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin"
9
9
  import CopyPlugin from "copy-webpack-plugin"
10
10
  import DotenvPlugin from "dotenv-webpack"
11
11
  import HtmlWebPackPlugin from "html-webpack-plugin"
12
12
  import MiniCssExtractPlugin from "mini-css-extract-plugin"
13
- import webpack from "webpack"
13
+ import postcss from "postcss"
14
14
  import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer"
15
15
 
16
16
  const logger = buildLogger({ namespace: "vblocks", level: "info" })
17
17
 
18
+ // Resolve each package from this file's folder. Webpack would resolve a loader
19
+ // name from its `context`, the current folder by default
20
+ const require = createRequire(import.meta.url)
21
+
18
22
  /**
19
- * Read the SWC config, set the browser targets it lacks, and turn on React
20
- * Refresh when `hasReactRefresh` is true
23
+ * Read the SWC config, point SWC at the browserslist config from `entryDir` up,
24
+ * and turn on React Refresh when `hasReactRefresh` is true
21
25
  *
22
26
  * @param {string} path
23
- * @param {{ hasReactRefresh: boolean }} options
27
+ * @param {{ hasReactRefresh: boolean, entryDir: string }} options
24
28
  */
25
- const loadSwcConfig = (path, { hasReactRefresh }) => {
29
+ const loadSwcConfig = (path, { hasReactRefresh, entryDir }) => {
26
30
  const content = fs.readFileSync(path, "utf8")
27
31
  const config = /** @type {unknown} */ (JSON.parse(content))
28
32
  const typedConfig = /** @type {import("@swc/core").Config} */ (config)
@@ -33,8 +37,11 @@ const loadSwcConfig = (path, { hasReactRefresh }) => {
33
37
  // this, SWC also reads the .swcrc of the folder VBlocks runs in, eg. the
34
38
  // package around the app
35
39
  swcrc: false,
40
+ // SWC reads the browserslist config from this folder up, as Webpack and
41
+ // postcss-preset-env do. Without one, `serve` and `build` give it the
42
+ // VBlocks default
36
43
  env: {
37
- targets: "> 0.25%, not dead",
44
+ path: entryDir,
38
45
  ...typedConfig.env,
39
46
  },
40
47
  jsc: {
@@ -64,7 +71,7 @@ const getCssModuleOptions = isProduction => ({
64
71
  // import * as styles from './styles.module.css'
65
72
  namedExport: false,
66
73
 
67
- // Map `.my-class` in CSS to `styles.myClass` in JavaScript
74
+ // Map `.my-class` in CSS to `styles["myClass"]` in JavaScript
68
75
  exportLocalsConvention: "camelCase",
69
76
 
70
77
  // Production names a class by its hash alone. Development puts the class
@@ -87,7 +94,7 @@ const getCssLoaders = ({ classScope, isProduction, postcssConfigPath }) => [
87
94
  loader: MiniCssExtractPlugin.loader,
88
95
  },
89
96
  {
90
- loader: "css-loader",
97
+ loader: require.resolve("css-loader"),
91
98
  options: {
92
99
  // Resolve @import in CSS files
93
100
  import: true,
@@ -102,8 +109,11 @@ const getCssLoaders = ({ classScope, isProduction, postcssConfigPath }) => [
102
109
  },
103
110
  },
104
111
  {
105
- loader: "postcss-loader",
112
+ loader: require.resolve("postcss-loader"),
106
113
  options: {
114
+ // Run the PostCSS this file imports, not the one postcss-loader resolves
115
+ // from its own folder
116
+ implementation: postcss,
107
117
  postcssOptions: {
108
118
  config: postcssConfigPath,
109
119
  },
@@ -258,6 +268,7 @@ const inlineAssets = compiler => {
258
268
  * @property {boolean} [single] - Build one standalone index.html, every asset inlined
259
269
  * @property {boolean} [analyze] - Run the bundle analyzer next to the dev server
260
270
  * @property {"error"|"warn"|"info"|"verbose"} [logLevel] - How much Webpack and its dev server print
271
+ * @property {boolean} [WEBPACK_SERVE] - webpack-cli sets it for `serve`, and its aliases `server` and `s`
261
272
  */
262
273
 
263
274
  /**
@@ -296,15 +307,31 @@ export default (
296
307
  single,
297
308
  analyze,
298
309
  logLevel = "warn",
310
+ WEBPACK_SERVE,
299
311
  },
300
312
  { mode }
301
313
  ) => {
302
314
  const isProduction = mode === "production"
303
- const isServe = process.argv[2] == "serve"
315
+ const isServe = Boolean(WEBPACK_SERVE)
304
316
  const isSingle = Boolean(single) && !isServe
305
317
  const isAnalyze = Boolean(analyze) && isServe
306
318
  const hasReactRefresh = isServe && mode === "development"
307
- const swcConfig = loadSwcConfig(swcConfigPath, { hasReactRefresh })
319
+ const swcConfig = loadSwcConfig(swcConfigPath, { hasReactRefresh, entryDir })
320
+ const swcLoader = {
321
+ loader: require.resolve("swc-loader"),
322
+ options: swcConfig,
323
+ }
324
+
325
+ // With `jsc.externalHelpers` (see default .swcrc), SWC imports its helpers
326
+ // into each app file it compiles.
327
+ // Resolve them from this file's folder, not from the app file's
328
+ const swcResolve = {
329
+ alias: {
330
+ "@swc/helpers": path.dirname(
331
+ require.resolve("@swc/helpers/package.json")
332
+ ),
333
+ },
334
+ }
308
335
 
309
336
  const paths = {
310
337
  appEntry: `${entryDir}/src/index.tsx`,
@@ -348,9 +375,11 @@ export default (
348
375
 
349
376
  devtool: isServe ? "eval-source-map" : false,
350
377
 
351
- // Webpack builds for the browser targets of the SWC config, so both tools
352
- // agree
353
- target: `browserslist:${swcConfig.env.targets}`,
378
+ // Webpack reads the browserslist config from `context` up, as SWC and
379
+ // postcss-preset-env do. Without one, `serve` and `build` give Webpack the
380
+ // VBlocks default
381
+ context: entryDir,
382
+ target: "browserslist",
354
383
 
355
384
  module: {
356
385
  rules: [
@@ -363,19 +392,15 @@ export default (
363
392
  test: /\.(ts|tsx)$/,
364
393
  exclude: /node_modules/,
365
394
  resourceQuery: { not: [RAW_QUERY] },
366
- use: {
367
- loader: "swc-loader",
368
- options: swcConfig,
369
- },
395
+ resolve: swcResolve,
396
+ use: swcLoader,
370
397
  },
371
398
  {
372
399
  test: /\.mdx?$/,
373
400
  exclude: /node_modules/,
374
401
  resourceQuery: { not: [RAW_QUERY] },
375
- use: [
376
- { loader: "swc-loader", options: swcConfig },
377
- { loader: "@mdx-js/loader" },
378
- ],
402
+ resolve: swcResolve,
403
+ use: [swcLoader, { loader: require.resolve("@mdx-js/loader") }],
379
404
  },
380
405
  {
381
406
  test: /\.module\.css$/,
@@ -509,8 +534,16 @@ export default (
509
534
  ],
510
535
  }),
511
536
 
512
- // Without it, Webpack emits a second file for each dynamic `import()`
513
- isSingle && new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
537
+ // Without it, Webpack emits a second file for each dynamic `import()`.
538
+ // Take the plugin from the compiler, the Webpack that runs this config
539
+ isSingle &&
540
+ /** @type {import("webpack").WebpackPluginFunction} */ (
541
+ compiler => {
542
+ new compiler.webpack.optimize.LimitChunkCountPlugin({
543
+ maxChunks: 1,
544
+ }).apply(compiler)
545
+ }
546
+ ),
514
547
 
515
548
  isSingle && inlineAssets,
516
549
 
@@ -531,13 +564,16 @@ export default (
531
564
  // A TypeScript import names the file tsc emits, eg. `./button.js` for
532
565
  // `button.tsx`. Find the source behind it, as Vite does
533
566
  extensionAlias: { ".js": [".ts", ".tsx", ".js"] },
567
+ // No alias for `react/jsx-runtime` or `react-refresh`. The app owns
568
+ // React, and the React Refresh plugin loads its own copy by path. A
569
+ // second copy of either keeps its own state, eg. React throws on each
570
+ // hook call
534
571
  alias: {
535
572
  "@self": `${entryDir}/src`,
536
- // React Refresh imports the dev server's client. Use the one VBlocks runs
573
+ // React Refresh imports the dev server's client by name. Resolve it
574
+ // from this file's folder
537
575
  "webpack-dev-server": path.dirname(
538
- createRequire(import.meta.url).resolve(
539
- "webpack-dev-server/package.json"
540
- )
576
+ require.resolve("webpack-dev-server/package.json")
541
577
  ),
542
578
  },
543
579
  },
@@ -0,0 +1,4 @@
1
+ # Decisions - @asd14/vblocks
2
+
3
+ - [02. Read the browsers from the browserslist config](decisions/02.read-browserslist-config.md)
4
+ - [01. Resolve each dependency from the VBlocks folder](decisions/01.resolve-dependency-vblocks-folder.md)