@lynx-js/react-webpack-plugin-canary 0.9.4 → 0.9.5-canary-20260629-f332136e
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/CHANGELOG.md +28 -18
- package/lib/ReactWebpackPlugin.js +39 -4
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @lynx-js/react-webpack-plugin
|
|
2
2
|
|
|
3
|
+
## 0.9.5-canary-20260629122428-f332136ea2b83004f69231bee7b17b4254101f9f
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Support enabling preact devtools in production via the `REACT_DEVTOOL` environment variable. ([#2880](https://github.com/lynx-family/lynx-stack/pull/2880))
|
|
8
|
+
|
|
9
|
+
By default `@lynx-js/preact-devtools` is aliased away in production builds. Setting the `REACT_DEVTOOL` environment variable now:
|
|
10
|
+
1. keeps a user-imported `@lynx-js/preact-devtools` from being stripped;
|
|
11
|
+
2. defines `__REACT_DEVTOOL__`, which gates the dev-only runtime hooks devtools depends on (such as `injectLepusMethods`) so they also run in production;
|
|
12
|
+
3. keeps function/class names during minification (`keep_fnames`/`keep_classnames`), which devtools needs to resolve component names (`type.name`) and to reconstruct the hook tree (it matches minified stack frames by function name).
|
|
13
|
+
|
|
14
|
+
`@lynx-js/react/debug` remains development-only.
|
|
15
|
+
|
|
3
16
|
## 0.9.4
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -50,7 +63,6 @@
|
|
|
50
63
|
### Minor Changes
|
|
51
64
|
|
|
52
65
|
- feat: add `globalPropsMode` option to `PluginReactLynxOptions` ([#2346](https://github.com/lynx-family/lynx-stack/pull/2346))
|
|
53
|
-
|
|
54
66
|
- When configured to `"event"`, `updateGlobalProps` will only trigger a global event and skip the `runWithForce` flow.
|
|
55
67
|
- Defaults to `"reactive"`, which means `updateGlobalProps` will trigger re-render automatically.
|
|
56
68
|
|
|
@@ -59,7 +71,6 @@
|
|
|
59
71
|
- Fix sourcemap misalignment when wrapping lazy bundle main-thread chunks. ([#2361](https://github.com/lynx-family/lynx-stack/pull/2361))
|
|
60
72
|
|
|
61
73
|
The lazy bundle IIFE wrapper is now injected in `processAssets` at `PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1` by walking chunk groups instead of patching assets in `beforeEncode`.
|
|
62
|
-
|
|
63
74
|
- With `experimental_isLazyBundle: true`, the wrapper is applied to lazy-bundle chunk groups.
|
|
64
75
|
- Without lazy bundle mode, the wrapper is applied to async main-thread chunk groups generated by dynamic import.
|
|
65
76
|
|
|
@@ -139,16 +150,16 @@
|
|
|
139
150
|
type InlineChunkConfig =
|
|
140
151
|
| boolean
|
|
141
152
|
| InlineChunkTest
|
|
142
|
-
| { enable?: boolean |
|
|
153
|
+
| { enable?: boolean | "auto"; test: InlineChunkTest };
|
|
143
154
|
```
|
|
144
155
|
|
|
145
156
|
```ts
|
|
146
|
-
import { defineConfig } from
|
|
157
|
+
import { defineConfig } from "@lynx-js/rspeedy";
|
|
147
158
|
|
|
148
159
|
export default defineConfig({
|
|
149
160
|
output: {
|
|
150
161
|
inlineScripts: ({ name, size }) => {
|
|
151
|
-
return name.includes(
|
|
162
|
+
return name.includes("foo") && size < 1000;
|
|
152
163
|
},
|
|
153
164
|
},
|
|
154
165
|
});
|
|
@@ -203,7 +214,6 @@
|
|
|
203
214
|
- feat: fully support MTS ([#569](https://github.com/lynx-family/lynx-stack/pull/569))
|
|
204
215
|
|
|
205
216
|
Now use support the following usage
|
|
206
|
-
|
|
207
217
|
- mainthread event
|
|
208
218
|
- mainthread ref
|
|
209
219
|
- runOnMainThread/runOnBackground
|
|
@@ -232,7 +242,7 @@
|
|
|
232
242
|
- Shake `useImperativeHandle` on the main-thread by default. ([#153](https://github.com/lynx-family/lynx-stack/pull/153))
|
|
233
243
|
|
|
234
244
|
```js
|
|
235
|
-
import { forwardRef, useImperativeHandle } from
|
|
245
|
+
import { forwardRef, useImperativeHandle } from "@lynx-js/react";
|
|
236
246
|
|
|
237
247
|
export default forwardRef(function App(_, ref) {
|
|
238
248
|
useImperativeHandle(ref, () => {
|
|
@@ -240,7 +250,7 @@
|
|
|
240
250
|
return {
|
|
241
251
|
name() {
|
|
242
252
|
// This should be considered as background only
|
|
243
|
-
console.info(
|
|
253
|
+
console.info("This should not exist in main-thread");
|
|
244
254
|
},
|
|
245
255
|
};
|
|
246
256
|
});
|
|
@@ -300,14 +310,14 @@
|
|
|
300
310
|
- e8039f2: Add `defineDCE` in plugin options. Often used to define custom macros.
|
|
301
311
|
|
|
302
312
|
```js
|
|
303
|
-
import { pluginReactLynx } from
|
|
304
|
-
import { defineConfig } from
|
|
313
|
+
import { pluginReactLynx } from "@lynx-js/react-rsbuild-plugin";
|
|
314
|
+
import { defineConfig } from "@lynx-js/rspeedy";
|
|
305
315
|
|
|
306
316
|
export default defineConfig({
|
|
307
317
|
plugins: [
|
|
308
318
|
pluginReactLynx({
|
|
309
319
|
defineDCE: {
|
|
310
|
-
__SOME_FALSE_DEFINE__:
|
|
320
|
+
__SOME_FALSE_DEFINE__: "false",
|
|
311
321
|
},
|
|
312
322
|
}),
|
|
313
323
|
],
|
|
@@ -319,20 +329,20 @@
|
|
|
319
329
|
For example, `import` initialized by dead code will be removed:
|
|
320
330
|
|
|
321
331
|
```js
|
|
322
|
-
import { foo } from
|
|
332
|
+
import { foo } from "bar";
|
|
323
333
|
|
|
324
334
|
if (__SOME_FALSE_DEFINE__) {
|
|
325
335
|
foo();
|
|
326
|
-
console.log(
|
|
336
|
+
console.log("dead code");
|
|
327
337
|
} else {
|
|
328
|
-
console.log(
|
|
338
|
+
console.log("reachable code");
|
|
329
339
|
}
|
|
330
340
|
```
|
|
331
341
|
|
|
332
342
|
will be transformed to:
|
|
333
343
|
|
|
334
344
|
```js
|
|
335
|
-
console.log(
|
|
345
|
+
console.log("reachable code");
|
|
336
346
|
```
|
|
337
347
|
|
|
338
348
|
## 0.6.0
|
|
@@ -342,14 +352,14 @@
|
|
|
342
352
|
- a30c83d: Add `compat.removeComponentAttrRegex`.
|
|
343
353
|
|
|
344
354
|
```js
|
|
345
|
-
import { pluginReactLynx } from
|
|
346
|
-
import { defineConfig } from
|
|
355
|
+
import { pluginReactLynx } from "@lynx-js/react-rsbuild-plugin";
|
|
356
|
+
import { defineConfig } from "@lynx-js/rspeedy";
|
|
347
357
|
|
|
348
358
|
export default defineConfig({
|
|
349
359
|
plugins: [
|
|
350
360
|
pluginReactLynx({
|
|
351
361
|
compat: {
|
|
352
|
-
removeComponentAttrRegex:
|
|
362
|
+
removeComponentAttrRegex: "YOUR REGEX",
|
|
353
363
|
},
|
|
354
364
|
}),
|
|
355
365
|
],
|
|
@@ -68,6 +68,37 @@ export function mergeElementTemplatesFromModule(elementTemplates, module) {
|
|
|
68
68
|
mergeElementTemplate(elementTemplates, templateId, compiledTemplate);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Collect element templates for a single encoded bundle, scoped to the modules
|
|
73
|
+
* that belong to it. Iterating every module in the compilation would pull other
|
|
74
|
+
* bundles' modules — including dynamic components — into the result, duplicating
|
|
75
|
+
* their templates (e.g. a lazy component's template leaking into the main
|
|
76
|
+
* bundle). An entrypoint's chunk group contains only its initial chunks, so
|
|
77
|
+
* async (dynamic component) modules stay out of the main bundle, and each lazy
|
|
78
|
+
* bundle keeps just its own templates.
|
|
79
|
+
*
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export function collectElementTemplatesForEntries(entryNames, getChunkGroup, getChunkModules) {
|
|
83
|
+
const elementTemplates = {};
|
|
84
|
+
const visited = new Set();
|
|
85
|
+
for (const entryName of entryNames) {
|
|
86
|
+
const chunkGroup = getChunkGroup(entryName);
|
|
87
|
+
if (chunkGroup === undefined) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
for (const chunk of chunkGroup.chunks) {
|
|
91
|
+
for (const module of getChunkModules(chunk)) {
|
|
92
|
+
if (visited.has(module)) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
visited.add(module);
|
|
96
|
+
mergeElementTemplatesFromModule(elementTemplates, module);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return elementTemplates;
|
|
101
|
+
}
|
|
71
102
|
/**
|
|
72
103
|
* ReactWebpackPlugin allows using ReactLynx with webpack
|
|
73
104
|
*
|
|
@@ -166,6 +197,12 @@ class ReactWebpackPlugin {
|
|
|
166
197
|
|| compiler.options.mode === 'development';
|
|
167
198
|
new DefinePlugin({
|
|
168
199
|
__DEV__: isDev,
|
|
200
|
+
// Whether preact devtools is enabled. Enabled by default in development;
|
|
201
|
+
// in production it can be enabled by environment variable `REACT_DEVTOOL`
|
|
202
|
+
// (which also keeps `@lynx-js/preact-devtools` from being stripped). This
|
|
203
|
+
// gates the dev-only runtime hooks that devtools depends on
|
|
204
|
+
// (e.g. `injectLepusMethods`).
|
|
205
|
+
__REACT_DEVTOOL__: JSON.stringify(isDev || Boolean(process.env['REACT_DEVTOOL'])),
|
|
169
206
|
// We enable profile by default in development.
|
|
170
207
|
// It can also be disabled by environment variable `REACT_PROFILE=false`
|
|
171
208
|
__PROFILE__: JSON.stringify(process.env['REACT_PROFILE']
|
|
@@ -283,10 +320,8 @@ class ReactWebpackPlugin {
|
|
|
283
320
|
?.replaceAll(`-react__main-thread`, ''));
|
|
284
321
|
if (options.experimental_useElementTemplate) {
|
|
285
322
|
hooks.beforeEncode.tap(`${this.constructor.name}.ElementTemplate`, (args) => {
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
mergeElementTemplatesFromModule(elementTemplates, module);
|
|
289
|
-
}
|
|
323
|
+
const { chunkGraph } = compilation;
|
|
324
|
+
const elementTemplates = collectElementTemplatesForEntries(args.entryNames, (name) => compilation.namedChunkGroups.get(name), (chunk) => chunkGraph.getChunkModules(chunk));
|
|
290
325
|
args.encodeData.sourceContent.config['enableUnifyFixedBehavior'] =
|
|
291
326
|
true;
|
|
292
327
|
args.encodeData.elementTemplate = elementTemplates;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/react-webpack-plugin-canary",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5-canary-20260629-f332136e",
|
|
4
4
|
"description": "A webpack plugin for ReactLynx",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"css-loader": "^7.1.4",
|
|
46
46
|
"swc-loader": "^0.2.7",
|
|
47
47
|
"@lynx-js/css-extract-webpack-plugin": "npm:@lynx-js/css-extract-webpack-plugin-canary@0.8.0",
|
|
48
|
-
"@lynx-js/
|
|
48
|
+
"@lynx-js/template-webpack-plugin": "npm:@lynx-js/template-webpack-plugin-canary@0.12.1",
|
|
49
49
|
"@lynx-js/test-tools": "0.0.0",
|
|
50
|
-
"@lynx-js/
|
|
50
|
+
"@lynx-js/react": "npm:@lynx-js/react-canary@0.122.1-canary-20260629-f332136e"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@lynx-js/template-webpack-plugin": "*"
|