@xh/hoist-dev-utils 16.4.2 → 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 +15 -0
- package/lib/common.js +2 -0
- package/package.json +1 -1
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
|
@@ -171,6 +171,12 @@ const hoistReactPkg = resolveAppPackage('@xh/hoist', basePath),
|
|
|
171
171
|
* cannot be hot-swapped (the equivalent of webpack-dev-server's `--no-live-reload`). Hot-swaps of CSS and
|
|
172
172
|
* Fast-Refresh-eligible components still apply; other edits are rebuilt but not applied until a manual
|
|
173
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.
|
|
174
180
|
* @param {(boolean|Object)} [env.devHttps] - `true` to run the dev server locally over SSL with an auto-generated
|
|
175
181
|
* self-signed cert (browser will warn). Or provide an object of Node `https.createServer` options to enable SSL
|
|
176
182
|
* while specifying a custom cert/key. Default `false` runs locally over HTTP only. Dev-mode only.
|
|
@@ -195,6 +201,8 @@ async function configureRsbuild(env) {
|
|
|
195
201
|
minify = parseFlag(env.minify, true) === true,
|
|
196
202
|
devClientOverlay = env.devClientOverlay ?? {errors: true, runtimeErrors: false},
|
|
197
203
|
devLiveReload = parseFlag(env.devLiveReload, true) === true,
|
|
204
|
+
devHmr = parseFlag(env.devHmr, true) === true,
|
|
205
|
+
devFastRefresh = devHmr && parseFlag(env.devFastRefresh, true) === true,
|
|
198
206
|
devHost = env.devHost ? env.devHost.toLowerCase() : 'localhost',
|
|
199
207
|
devHttps = prodBuild ? null : _.isPlainObject(env.devHttps) ? env.devHttps : !!env.devHttps,
|
|
200
208
|
devGrailsPort = env.devGrailsPort || 8080,
|
|
@@ -418,6 +426,8 @@ async function configureRsbuild(env) {
|
|
|
418
426
|
swcReactOptions: {runtime: HOIST_SWC.reactRuntime},
|
|
419
427
|
// Rsbuild's React-specific vendor chunking is tied to its own split presets.
|
|
420
428
|
splitChunks: false,
|
|
429
|
+
// Off, JS edits fall back to a full reload while CSS still hot-swaps.
|
|
430
|
+
fastRefresh: devFastRefresh,
|
|
421
431
|
reactRefreshOptions: {
|
|
422
432
|
// Refresh app source, hoist-react (raw TS in node_modules) and custom packages.
|
|
423
433
|
include: [srcPath, hoistPath, ...inlineSrcPaths, ...extraIncludePaths],
|
|
@@ -604,6 +614,9 @@ async function configureRsbuild(env) {
|
|
|
604
614
|
? undefined
|
|
605
615
|
: {
|
|
606
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,
|
|
607
620
|
// Full-page fallback when an update cannot be hot-applied (models, element-factory
|
|
608
621
|
// modules) - off for webpack-dev-server's `--no-live-reload` workflow.
|
|
609
622
|
liveReload: devLiveReload,
|
|
@@ -909,6 +922,8 @@ function readCliEnv(processEnv = process.env) {
|
|
|
909
922
|
XH_DEV_GRAILS_PORT: 'devGrailsPort',
|
|
910
923
|
XH_DEV_PORT: 'devWebpackPort',
|
|
911
924
|
XH_DEV_LIVE_RELOAD: 'devLiveReload',
|
|
925
|
+
XH_DEV_FAST_REFRESH: 'devFastRefresh',
|
|
926
|
+
XH_DEV_HMR: 'devHmr',
|
|
912
927
|
XH_LOG_LEVEL: 'logLevel'
|
|
913
928
|
};
|
|
914
929
|
const ret = {};
|
package/lib/common.js
CHANGED