@xh/hoist-dev-utils 16.4.1 → 16.5.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 +10 -3
- package/configureRsbuild.d.ts +10 -0
- package/configureRsbuild.js +23 -11
- package/lib/common.js +16 -7
- package/lib/hoistCompile.js +17 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -70,6 +70,12 @@ Run with `rsbuild dev` / `rsbuild build --env-mode prod`. Build-time options rea
|
|
|
70
70
|
`startWith...` script variants. Only `PUBLIC_`-prefixed variables are exposed to client code;
|
|
71
71
|
`XH_*` values stay build-time.
|
|
72
72
|
|
|
73
|
+
In dev, CSS edits hot-swap and React Fast Refresh hot-swaps components. Two variables change this
|
|
74
|
+
for a developer who prefers full reloads:
|
|
75
|
+
|
|
76
|
+
* `XH_DEV_FAST_REFRESH=false` - every JS/TS edit reloads the page. CSS edits still hot-swap.
|
|
77
|
+
* `XH_DEV_HMR=false` - every edit reloads the page, CSS included.
|
|
78
|
+
|
|
73
79
|
Typical `package.json` scripts:
|
|
74
80
|
|
|
75
81
|
```json
|
|
@@ -106,8 +112,8 @@ XH_HOIST_REACT_PATH=~/dev/hoist-react-worktrees/my-feature pnpm startWithHoist
|
|
|
106
112
|
```
|
|
107
113
|
|
|
108
114
|
Set it in the shell, not in a dotenv file. The `startWithHoist` and `testWithHoist` scripts read it
|
|
109
|
-
to install the checkout's dependencies, and Rsbuild's dotenv files do not reach them.
|
|
110
|
-
direnv or mise can set it per worktree.
|
|
115
|
+
to install the checkout's dependencies, and Rsbuild's dotenv files do not reach them. Vitest does not
|
|
116
|
+
load dotenv files either. A tool such as direnv or mise can set it per worktree.
|
|
111
117
|
|
|
112
118
|
Inline mode fails fast when the path holds no hoist-react checkout. The Rsbuild build banner shows
|
|
113
119
|
the path and branch it builds from.
|
|
@@ -132,7 +138,8 @@ XH_INLINE_PACKAGES=@xh/hoist-chat-kit=$HOME/dev/hoist-chat-kit-worktrees/my-feat
|
|
|
132
138
|
```
|
|
133
139
|
|
|
134
140
|
`readCliEnv()` maps the variable onto the `inlinePackages` option, and `configureVitest()` reads it
|
|
135
|
-
too. An app config needs no change.
|
|
141
|
+
too. An app config needs no change. Set it in the shell. A dotenv file reaches the build but not
|
|
142
|
+
Vitest. Production builds ignore it, with a warning.
|
|
136
143
|
|
|
137
144
|
A checkout installs its own dependencies, which hold a second copy of Hoist and React for its tests
|
|
138
145
|
and type checks. Two copies of either break the app, so the build shares one copy of these with the
|
package/configureRsbuild.d.ts
CHANGED
|
@@ -194,6 +194,16 @@ declare namespace configureRsbuild {
|
|
|
194
194
|
* Default true. Dev-mode only.
|
|
195
195
|
*/
|
|
196
196
|
devLiveReload?: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* False to turn off React Fast Refresh. CSS edits still hot-swap, but every JS/TS edit
|
|
199
|
+
* reloads the page. Default true. Dev-mode only.
|
|
200
|
+
*/
|
|
201
|
+
devFastRefresh?: boolean;
|
|
202
|
+
/**
|
|
203
|
+
* False to turn off hot module replacement, CSS included, so every edit reloads the page.
|
|
204
|
+
* Implies `devFastRefresh: false`. Default true. Dev-mode only.
|
|
205
|
+
*/
|
|
206
|
+
devHmr?: boolean;
|
|
197
207
|
/** Options to spread onto the defaults for Rsbuild's `server` config. Dev-mode only. */
|
|
198
208
|
devServerOptions?: Record<string, any>;
|
|
199
209
|
}
|
package/configureRsbuild.js
CHANGED
|
@@ -39,7 +39,13 @@ const {
|
|
|
39
39
|
logMsg
|
|
40
40
|
} = require('./lib/common');
|
|
41
41
|
|
|
42
|
-
const {
|
|
42
|
+
const {
|
|
43
|
+
HOIST_SWC,
|
|
44
|
+
hoistMinifyOptions,
|
|
45
|
+
resolveAppIdentity,
|
|
46
|
+
resolveHoistPath,
|
|
47
|
+
xhDefines
|
|
48
|
+
} = require('./lib/hoistCompile');
|
|
43
49
|
|
|
44
50
|
const {
|
|
45
51
|
INLINE_PACKAGES_VAR,
|
|
@@ -165,6 +171,12 @@ const hoistReactPkg = resolveAppPackage('@xh/hoist', basePath),
|
|
|
165
171
|
* cannot be hot-swapped (the equivalent of webpack-dev-server's `--no-live-reload`). Hot-swaps of CSS and
|
|
166
172
|
* Fast-Refresh-eligible components still apply; other edits are rebuilt but not applied until a manual
|
|
167
173
|
* reload. Dev-mode only.
|
|
174
|
+
* @param {boolean} [env.devFastRefresh=true] - false to turn off React Fast Refresh. CSS edits still
|
|
175
|
+
* hot-swap, but every JS/TS edit reloads the page, so no component keeps stale state across an
|
|
176
|
+
* edit. Dev-mode only.
|
|
177
|
+
* @param {boolean} [env.devHmr=true] - false to turn off hot module replacement entirely, CSS included.
|
|
178
|
+
* Every edit reloads the page. Implies `devFastRefresh: false`. With `devLiveReload: false` as
|
|
179
|
+
* well, edits reach the page only on a manual reload. Dev-mode only.
|
|
168
180
|
* @param {(boolean|Object)} [env.devHttps] - `true` to run the dev server locally over SSL with an auto-generated
|
|
169
181
|
* self-signed cert (browser will warn). Or provide an object of Node `https.createServer` options to enable SSL
|
|
170
182
|
* while specifying a custom cert/key. Default `false` runs locally over HTTP only. Dev-mode only.
|
|
@@ -189,6 +201,8 @@ async function configureRsbuild(env) {
|
|
|
189
201
|
minify = parseFlag(env.minify, true) === true,
|
|
190
202
|
devClientOverlay = env.devClientOverlay ?? {errors: true, runtimeErrors: false},
|
|
191
203
|
devLiveReload = parseFlag(env.devLiveReload, true) === true,
|
|
204
|
+
devHmr = parseFlag(env.devHmr, true) === true,
|
|
205
|
+
devFastRefresh = devHmr && parseFlag(env.devFastRefresh, true) === true,
|
|
192
206
|
devHost = env.devHost ? env.devHost.toLowerCase() : 'localhost',
|
|
193
207
|
devHttps = prodBuild ? null : _.isPlainObject(env.devHttps) ? env.devHttps : !!env.devHttps,
|
|
194
208
|
devGrailsPort = env.devGrailsPort || 8080,
|
|
@@ -412,6 +426,8 @@ async function configureRsbuild(env) {
|
|
|
412
426
|
swcReactOptions: {runtime: HOIST_SWC.reactRuntime},
|
|
413
427
|
// Rsbuild's React-specific vendor chunking is tied to its own split presets.
|
|
414
428
|
splitChunks: false,
|
|
429
|
+
// Off, JS edits fall back to a full reload while CSS still hot-swaps.
|
|
430
|
+
fastRefresh: devFastRefresh,
|
|
415
431
|
reactRefreshOptions: {
|
|
416
432
|
// Refresh app source, hoist-react (raw TS in node_modules) and custom packages.
|
|
417
433
|
include: [srcPath, hoistPath, ...inlineSrcPaths, ...extraIncludePaths],
|
|
@@ -550,16 +566,7 @@ async function configureRsbuild(env) {
|
|
|
550
566
|
js: prodBuild && minify,
|
|
551
567
|
css: prodBuild && minify,
|
|
552
568
|
jsOptions: {
|
|
553
|
-
minimizerOptions: _.merge(
|
|
554
|
-
{
|
|
555
|
-
// Mangling renames local identifiers for meaningfully smaller bundles.
|
|
556
|
-
// Function and class names are kept - relied upon for error messages,
|
|
557
|
-
// logging, and debugging of deployed builds.
|
|
558
|
-
compress: {keep_classnames: true, keep_fnames: true},
|
|
559
|
-
mangle: {keep_classnames: true, keep_fnames: true}
|
|
560
|
-
},
|
|
561
|
-
minifyOptions
|
|
562
|
-
)
|
|
569
|
+
minimizerOptions: _.merge(hoistMinifyOptions(), minifyOptions)
|
|
563
570
|
}
|
|
564
571
|
}
|
|
565
572
|
},
|
|
@@ -607,6 +614,9 @@ async function configureRsbuild(env) {
|
|
|
607
614
|
? undefined
|
|
608
615
|
: {
|
|
609
616
|
progressBar: true,
|
|
617
|
+
// Off, every edit (CSS included) falls back to `liveReload`. Also turns off Fast
|
|
618
|
+
// Refresh, which needs HMR.
|
|
619
|
+
hmr: devHmr,
|
|
610
620
|
// Full-page fallback when an update cannot be hot-applied (models, element-factory
|
|
611
621
|
// modules) - off for webpack-dev-server's `--no-live-reload` workflow.
|
|
612
622
|
liveReload: devLiveReload,
|
|
@@ -912,6 +922,8 @@ function readCliEnv(processEnv = process.env) {
|
|
|
912
922
|
XH_DEV_GRAILS_PORT: 'devGrailsPort',
|
|
913
923
|
XH_DEV_PORT: 'devWebpackPort',
|
|
914
924
|
XH_DEV_LIVE_RELOAD: 'devLiveReload',
|
|
925
|
+
XH_DEV_FAST_REFRESH: 'devFastRefresh',
|
|
926
|
+
XH_DEV_HMR: 'devHmr',
|
|
915
927
|
XH_LOG_LEVEL: 'logLevel'
|
|
916
928
|
};
|
|
917
929
|
const ret = {};
|
package/lib/common.js
CHANGED
|
@@ -68,15 +68,22 @@ function checkHoistReactVersion(hoistReactPkg, inlineHoist) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
// Rspack releases that break Hoist builds, each with the reason
|
|
72
|
-
//
|
|
71
|
+
// Rspack releases that break Hoist builds, each with the reason. A published version never
|
|
72
|
+
// changes, so blocking an exact version is permanent and safe. Both bugs come from the SWC
|
|
73
|
+
// minifier with keep_classnames set, and production builds crash on load.
|
|
73
74
|
const BLOCKED_RSPACK_VERSIONS = {
|
|
74
75
|
'2.3.2':
|
|
75
|
-
'Its minifier breaks classes that reference themselves in a static initializer
|
|
76
|
-
'
|
|
77
|
-
|
|
76
|
+
'Its minifier breaks classes that reference themselves in a static initializer ' +
|
|
77
|
+
'(web-infra-dev/rspack#16586, xh/hoist-dev-utils#85).',
|
|
78
|
+
'2.3.3':
|
|
79
|
+
'Its minifier can give a local variable the same name as a kept class name, so code ' +
|
|
80
|
+
'inside the class reads the wrong value. Highcharts fails to render charts ' +
|
|
81
|
+
'(web-infra-dev/rspack#16695, swc-project/swc#12770).'
|
|
78
82
|
};
|
|
79
83
|
|
|
84
|
+
// Newest Rspack release known to minify Hoist builds correctly, named in the blocked-version error.
|
|
85
|
+
const SAFE_RSPACK_VERSION = '2.3.1';
|
|
86
|
+
|
|
80
87
|
/**
|
|
81
88
|
* Fail the build, or the dev server, on an Rspack release known to break Hoist builds. The dev
|
|
82
89
|
* server fails too, even where it would run, so the problem shows up on the first local run rather
|
|
@@ -86,8 +93,8 @@ function checkRspackVersion(rspackVersion) {
|
|
|
86
93
|
const detail = BLOCKED_RSPACK_VERSIONS[rspackVersion];
|
|
87
94
|
if (detail) {
|
|
88
95
|
throw (
|
|
89
|
-
`@rspack/core v${rspackVersion} is not supported by hoist-dev-utils
|
|
90
|
-
`
|
|
96
|
+
`@rspack/core v${rspackVersion} is not supported by hoist-dev-utils. ${detail} ` +
|
|
97
|
+
`Pin "@rspack/core": "${SAFE_RSPACK_VERSION}" with a pnpm override in the app.`
|
|
91
98
|
);
|
|
92
99
|
}
|
|
93
100
|
}
|
|
@@ -452,6 +459,8 @@ const KNOWN_OPTIONS = [
|
|
|
452
459
|
'devServerOpenPage',
|
|
453
460
|
'devHttps',
|
|
454
461
|
'devLiveReload',
|
|
462
|
+
'devFastRefresh',
|
|
463
|
+
'devHmr',
|
|
455
464
|
'devServerOptions'
|
|
456
465
|
];
|
|
457
466
|
|
package/lib/hoistCompile.js
CHANGED
|
@@ -37,6 +37,22 @@ function hoistSwcTransform() {
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* SWC minifier options for production builds, before any `minifyOptions` from the app. Mangling
|
|
42
|
+
* renames locals for smaller bundles. Class names must be kept: Hoist installs and looks up
|
|
43
|
+
* services, and matches model selectors, by class name. Function names are kept for readable
|
|
44
|
+
* errors and stack traces in deployed builds. Returns a new object, safe to merge into.
|
|
45
|
+
*
|
|
46
|
+
* Two Rspack releases mangle wrongly with these options: see `BLOCKED_RSPACK_VERSIONS` in
|
|
47
|
+
* `lib/common.js`. `test/minify.test.js` runs both bugs against the installed Rspack.
|
|
48
|
+
*/
|
|
49
|
+
function hoistMinifyOptions() {
|
|
50
|
+
return {
|
|
51
|
+
compress: {keep_classnames: true, keep_fnames: true},
|
|
52
|
+
mangle: {keep_classnames: true, keep_fnames: true}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
40
56
|
/** App identity from `env`, with the `configureRsbuild()` defaults. `appCode` is required. */
|
|
41
57
|
function resolveAppIdentity(env) {
|
|
42
58
|
const {appCode} = env;
|
|
@@ -134,6 +150,7 @@ function readPackageName(dir) {
|
|
|
134
150
|
module.exports = {
|
|
135
151
|
HOIST_SWC,
|
|
136
152
|
hoistSwcTransform,
|
|
153
|
+
hoistMinifyOptions,
|
|
137
154
|
resolveAppIdentity,
|
|
138
155
|
xhDefines,
|
|
139
156
|
INLINE_HOIST_SINGLETONS,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xh/hoist-dev-utils",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.5.0",
|
|
4
4
|
"description": "Rsbuild (Rspack + SWC) build configuration and shared dev dependencies for Hoist React applications.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"node": ">=22.15.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@rsbuild/core": "
|
|
28
|
+
"@rsbuild/core": "2.3.1",
|
|
29
29
|
"@rsbuild/plugin-basic-ssl": "~2.0.0",
|
|
30
30
|
"@rsbuild/plugin-react": "~2.1.1",
|
|
31
31
|
"@rsbuild/plugin-sass": "~2.0.1",
|