@lynx-js/react-webpack-plugin 0.7.3 → 0.8.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/CHANGELOG.md +28 -0
- package/lib/ReactWebpackPlugin.d.ts +4 -0
- package/lib/ReactWebpackPlugin.js +52 -22
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @lynx-js/react-webpack-plugin
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- feat: add `globalPropsMode` option to `PluginReactLynxOptions` ([#2346](https://github.com/lynx-family/lynx-stack/pull/2346))
|
|
8
|
+
|
|
9
|
+
- When configured to `"event"`, `updateGlobalProps` will only trigger a global event and skip the `runWithForce` flow.
|
|
10
|
+
- Defaults to `"reactive"`, which means `updateGlobalProps` will trigger re-render automatically.
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Fix sourcemap misalignment when wrapping lazy bundle main-thread chunks. ([#2361](https://github.com/lynx-family/lynx-stack/pull/2361))
|
|
15
|
+
|
|
16
|
+
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`.
|
|
17
|
+
|
|
18
|
+
- With `experimental_isLazyBundle: true`, the wrapper is applied to lazy-bundle chunk groups.
|
|
19
|
+
- Without lazy bundle mode, the wrapper is applied to async main-thread chunk groups generated by dynamic import.
|
|
20
|
+
|
|
21
|
+
Injecting the wrapper in this stage keeps the emitted JS stable after optimization while still running before `DEV_TOOLING` sourcemap finalization, so the generated `.js` and `.js.map` stay aligned.
|
|
22
|
+
|
|
23
|
+
- Set `__DEV__` and `__PROFILE__` to `true` on `NODE_ENV === 'development'`. ([#2324](https://github.com/lynx-family/lynx-stack/pull/2324))
|
|
24
|
+
|
|
25
|
+
## 0.7.4
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Remove element api calls alog by default, and only enable it when `__ALOG_ELEMENT_API__` is defined to `true` or environment variable `REACT_ALOG_ELEMENT_API` is set to `true`. ([#2192](https://github.com/lynx-family/lynx-stack/pull/2192))
|
|
30
|
+
|
|
3
31
|
## 0.7.3
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
|
@@ -15,6 +15,10 @@ interface ReactWebpackPluginOptions {
|
|
|
15
15
|
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.firstScreenSyncTiming}
|
|
16
16
|
*/
|
|
17
17
|
firstScreenSyncTiming?: 'immediately' | 'jsReady';
|
|
18
|
+
/**
|
|
19
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.globalPropsMode}
|
|
20
|
+
*/
|
|
21
|
+
globalPropsMode?: 'reactive' | 'event';
|
|
18
22
|
/**
|
|
19
23
|
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.enableSSR}
|
|
20
24
|
*/
|
|
@@ -73,6 +73,7 @@ class ReactWebpackPlugin {
|
|
|
73
73
|
.freeze({
|
|
74
74
|
disableCreateSelectorQueryIncompatibleWarning: false,
|
|
75
75
|
firstScreenSyncTiming: 'immediately',
|
|
76
|
+
globalPropsMode: 'reactive',
|
|
76
77
|
enableSSR: false,
|
|
77
78
|
mainThreadChunks: [],
|
|
78
79
|
extractStr: false,
|
|
@@ -100,17 +101,22 @@ class ReactWebpackPlugin {
|
|
|
100
101
|
// Use undefined for variables that must be provided during bundling, or null if they are optional.
|
|
101
102
|
DEBUG: null,
|
|
102
103
|
}).apply(compiler);
|
|
104
|
+
const isDev = process.env['NODE_ENV'] === 'development'
|
|
105
|
+
|| compiler.options.mode === 'development';
|
|
103
106
|
new DefinePlugin({
|
|
104
|
-
__DEV__:
|
|
107
|
+
__DEV__: isDev,
|
|
105
108
|
// We enable profile by default in development.
|
|
106
109
|
// It can also be disabled by environment variable `REACT_PROFILE=false`
|
|
107
110
|
__PROFILE__: JSON.stringify(process.env['REACT_PROFILE']
|
|
108
111
|
?? options.profile
|
|
109
|
-
??
|
|
112
|
+
?? isDev),
|
|
110
113
|
// User can enable ALog by environment variable `REACT_ALOG=true`
|
|
111
114
|
__ALOG__: JSON.stringify(Boolean(process.env['REACT_ALOG'])),
|
|
115
|
+
// User can enable ALog of element API calls by environment variable `REACT_ALOG_ELEMENT_API=true`
|
|
116
|
+
__ALOG_ELEMENT_API__: JSON.stringify(Boolean(process.env['REACT_ALOG_ELEMENT_API'])),
|
|
112
117
|
__EXTRACT_STR__: JSON.stringify(Boolean(options.extractStr)),
|
|
113
118
|
__FIRST_SCREEN_SYNC_TIMING__: JSON.stringify(options.firstScreenSyncTiming),
|
|
119
|
+
__GLOBAL_PROPS_MODE__: JSON.stringify(options.globalPropsMode),
|
|
114
120
|
__ENABLE_SSR__: JSON.stringify(options.enableSSR),
|
|
115
121
|
__DISABLE_CREATE_SELECTOR_QUERY_INCOMPATIBLE_WARNING__: JSON.stringify(options.disableCreateSelectorQueryIncompatibleWarning),
|
|
116
122
|
}).apply(compiler);
|
|
@@ -166,26 +172,50 @@ class ReactWebpackPlugin {
|
|
|
166
172
|
}
|
|
167
173
|
return args;
|
|
168
174
|
});
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
175
|
+
if (compiler.options.plugins.some((p) => p instanceof LynxTemplatePlugin)) {
|
|
176
|
+
compilation.hooks.processAssets.tap({
|
|
177
|
+
name: this.constructor.name,
|
|
178
|
+
// This wrapper must be injected after size/minify optimizations have
|
|
179
|
+
// produced stable JS, but before devtool plugins finalize sourcemaps and
|
|
180
|
+
// later encode hooks consume the wrapped asset.
|
|
181
|
+
//
|
|
182
|
+
// - Too early (<= OPTIMIZE_SIZE): the wrapper is added before the
|
|
183
|
+
// minimizer runs. For lazy bundles, the minimizer can treat the wrapped
|
|
184
|
+
// content as removable and collapse the emitted asset down to empty code.
|
|
185
|
+
// - Too late (>= DEV_TOOLING): SourceMapDevToolPlugin emits `.map` assets
|
|
186
|
+
// and rewrites JS with `sourceMappingURL` in DEV_TOOLING. If we prepend
|
|
187
|
+
// wrapper lines after that point, the generated JS shifts but mappings do
|
|
188
|
+
// not.
|
|
189
|
+
//
|
|
190
|
+
// OPTIMIZE_SIZE + 1 is the safe window where both the emitted code and its
|
|
191
|
+
// sourcemap stay aligned.
|
|
192
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE
|
|
193
|
+
+ 1,
|
|
194
|
+
}, () => {
|
|
195
|
+
compilation.chunkGroups.forEach(chunkGroup => {
|
|
196
|
+
const isDynamicImport = !chunkGroup.isInitial()
|
|
197
|
+
&& chunkGroup.origins.every(origin => origin.module?.layer === LAYERS.MAIN_THREAD);
|
|
198
|
+
chunkGroup.chunks.forEach(chunk => {
|
|
199
|
+
for (const file of chunk.files) {
|
|
200
|
+
if (!file.endsWith('.js')) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const shouldInjectWrapper = isDynamicImport
|
|
204
|
+
|| (options.experimental_isLazyBundle
|
|
205
|
+
&& options.mainThreadChunks?.includes(file));
|
|
206
|
+
if (!shouldInjectWrapper) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const asset = compilation.getAsset(file);
|
|
210
|
+
if (!asset) {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
compilation.updateAsset(file, old => new ConcatSource(`(function (globDynamicComponentEntry) {\n`, ` const module = { exports: {} }\n`, ` const exports = module.exports;\n`, old, `\n ;return module.exports\n})`));
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
189
219
|
// The react-transform will add `-react__${LAYER}` to the webpackChunkName.
|
|
190
220
|
// We replace it with an empty string here to make sure main-thread & background chunk match.
|
|
191
221
|
hooks.asyncChunkName.tap(this.constructor.name, (chunkName) => chunkName
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/react-webpack-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A webpack plugin for ReactLynx",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
"@lynx-js/webpack-runtime-globals": "0.0.6"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@microsoft/api-extractor": "7.
|
|
41
|
-
"@rspack/core": "1.
|
|
42
|
-
"css-loader": "^7.1.
|
|
43
|
-
"swc-loader": "^0.2.
|
|
44
|
-
"webpack": "^5.
|
|
40
|
+
"@microsoft/api-extractor": "7.57.6",
|
|
41
|
+
"@rspack/core": "1.7.7",
|
|
42
|
+
"css-loader": "^7.1.4",
|
|
43
|
+
"swc-loader": "^0.2.7",
|
|
44
|
+
"webpack": "^5.105.2",
|
|
45
45
|
"@lynx-js/css-extract-webpack-plugin": "0.7.0",
|
|
46
|
-
"@lynx-js/react": "0.
|
|
47
|
-
"@lynx-js/template-webpack-plugin": "0.10.
|
|
46
|
+
"@lynx-js/react": "0.117.0",
|
|
47
|
+
"@lynx-js/template-webpack-plugin": "0.10.6",
|
|
48
48
|
"@lynx-js/test-tools": "0.0.0",
|
|
49
49
|
"@lynx-js/vitest-setup": "0.0.0"
|
|
50
50
|
},
|