@lynx-js/react-webpack-plugin-canary 0.9.0 → 0.9.1-canary-20260413-b1ad1b98
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 +24 -18
- package/lib/ReactWebpackPlugin.d.ts +1 -1
- package/lib/ReactWebpackPlugin.js +1 -0
- package/lib/loaders/options.d.ts +5 -0
- package/lib/loaders/options.js +2 -2
- package/lib/loaders/testing.d.ts +4 -0
- package/lib/loaders/testing.js +102 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @lynx-js/react-webpack-plugin
|
|
2
2
|
|
|
3
|
+
## 0.9.1-canary-20260413082204-b1ad1b98ed8d4635ad89fac42fe2fbb7e8e56c39
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Support rstest for testing library using a dedicated testing loader. ([#2328](https://github.com/lynx-family/lynx-stack/pull/2328))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies []:
|
|
10
|
+
- @lynx-js/template-webpack-plugin@0.10.9-canary-20260413082204-b1ad1b98ed8d4635ad89fac42fe2fbb7e8e56c39
|
|
11
|
+
|
|
3
12
|
## 0.9.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
|
@@ -13,7 +22,6 @@
|
|
|
13
22
|
### Minor Changes
|
|
14
23
|
|
|
15
24
|
- feat: add `globalPropsMode` option to `PluginReactLynxOptions` ([#2346](https://github.com/lynx-family/lynx-stack/pull/2346))
|
|
16
|
-
|
|
17
25
|
- When configured to `"event"`, `updateGlobalProps` will only trigger a global event and skip the `runWithForce` flow.
|
|
18
26
|
- Defaults to `"reactive"`, which means `updateGlobalProps` will trigger re-render automatically.
|
|
19
27
|
|
|
@@ -22,7 +30,6 @@
|
|
|
22
30
|
- Fix sourcemap misalignment when wrapping lazy bundle main-thread chunks. ([#2361](https://github.com/lynx-family/lynx-stack/pull/2361))
|
|
23
31
|
|
|
24
32
|
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`.
|
|
25
|
-
|
|
26
33
|
- With `experimental_isLazyBundle: true`, the wrapper is applied to lazy-bundle chunk groups.
|
|
27
34
|
- Without lazy bundle mode, the wrapper is applied to async main-thread chunk groups generated by dynamic import.
|
|
28
35
|
|
|
@@ -102,16 +109,16 @@
|
|
|
102
109
|
type InlineChunkConfig =
|
|
103
110
|
| boolean
|
|
104
111
|
| InlineChunkTest
|
|
105
|
-
| { enable?: boolean |
|
|
112
|
+
| { enable?: boolean | "auto"; test: InlineChunkTest };
|
|
106
113
|
```
|
|
107
114
|
|
|
108
115
|
```ts
|
|
109
|
-
import { defineConfig } from
|
|
116
|
+
import { defineConfig } from "@lynx-js/rspeedy";
|
|
110
117
|
|
|
111
118
|
export default defineConfig({
|
|
112
119
|
output: {
|
|
113
120
|
inlineScripts: ({ name, size }) => {
|
|
114
|
-
return name.includes(
|
|
121
|
+
return name.includes("foo") && size < 1000;
|
|
115
122
|
},
|
|
116
123
|
},
|
|
117
124
|
});
|
|
@@ -166,7 +173,6 @@
|
|
|
166
173
|
- feat: fully support MTS ([#569](https://github.com/lynx-family/lynx-stack/pull/569))
|
|
167
174
|
|
|
168
175
|
Now use support the following usage
|
|
169
|
-
|
|
170
176
|
- mainthread event
|
|
171
177
|
- mainthread ref
|
|
172
178
|
- runOnMainThread/runOnBackground
|
|
@@ -195,7 +201,7 @@
|
|
|
195
201
|
- Shake `useImperativeHandle` on the main-thread by default. ([#153](https://github.com/lynx-family/lynx-stack/pull/153))
|
|
196
202
|
|
|
197
203
|
```js
|
|
198
|
-
import { forwardRef, useImperativeHandle } from
|
|
204
|
+
import { forwardRef, useImperativeHandle } from "@lynx-js/react";
|
|
199
205
|
|
|
200
206
|
export default forwardRef(function App(_, ref) {
|
|
201
207
|
useImperativeHandle(ref, () => {
|
|
@@ -203,7 +209,7 @@
|
|
|
203
209
|
return {
|
|
204
210
|
name() {
|
|
205
211
|
// This should be considered as background only
|
|
206
|
-
console.info(
|
|
212
|
+
console.info("This should not exist in main-thread");
|
|
207
213
|
},
|
|
208
214
|
};
|
|
209
215
|
});
|
|
@@ -263,14 +269,14 @@
|
|
|
263
269
|
- e8039f2: Add `defineDCE` in plugin options. Often used to define custom macros.
|
|
264
270
|
|
|
265
271
|
```js
|
|
266
|
-
import { pluginReactLynx } from
|
|
267
|
-
import { defineConfig } from
|
|
272
|
+
import { pluginReactLynx } from "@lynx-js/react-rsbuild-plugin";
|
|
273
|
+
import { defineConfig } from "@lynx-js/rspeedy";
|
|
268
274
|
|
|
269
275
|
export default defineConfig({
|
|
270
276
|
plugins: [
|
|
271
277
|
pluginReactLynx({
|
|
272
278
|
defineDCE: {
|
|
273
|
-
__SOME_FALSE_DEFINE__:
|
|
279
|
+
__SOME_FALSE_DEFINE__: "false",
|
|
274
280
|
},
|
|
275
281
|
}),
|
|
276
282
|
],
|
|
@@ -282,20 +288,20 @@
|
|
|
282
288
|
For example, `import` initialized by dead code will be removed:
|
|
283
289
|
|
|
284
290
|
```js
|
|
285
|
-
import { foo } from
|
|
291
|
+
import { foo } from "bar";
|
|
286
292
|
|
|
287
293
|
if (__SOME_FALSE_DEFINE__) {
|
|
288
294
|
foo();
|
|
289
|
-
console.log(
|
|
295
|
+
console.log("dead code");
|
|
290
296
|
} else {
|
|
291
|
-
console.log(
|
|
297
|
+
console.log("reachable code");
|
|
292
298
|
}
|
|
293
299
|
```
|
|
294
300
|
|
|
295
301
|
will be transformed to:
|
|
296
302
|
|
|
297
303
|
```js
|
|
298
|
-
console.log(
|
|
304
|
+
console.log("reachable code");
|
|
299
305
|
```
|
|
300
306
|
|
|
301
307
|
## 0.6.0
|
|
@@ -305,14 +311,14 @@
|
|
|
305
311
|
- a30c83d: Add `compat.removeComponentAttrRegex`.
|
|
306
312
|
|
|
307
313
|
```js
|
|
308
|
-
import { pluginReactLynx } from
|
|
309
|
-
import { defineConfig } from
|
|
314
|
+
import { pluginReactLynx } from "@lynx-js/react-rsbuild-plugin";
|
|
315
|
+
import { defineConfig } from "@lynx-js/rspeedy";
|
|
310
316
|
|
|
311
317
|
export default defineConfig({
|
|
312
318
|
plugins: [
|
|
313
319
|
pluginReactLynx({
|
|
314
320
|
compat: {
|
|
315
|
-
removeComponentAttrRegex:
|
|
321
|
+
removeComponentAttrRegex: "YOUR REGEX",
|
|
316
322
|
},
|
|
317
323
|
}),
|
|
318
324
|
],
|
|
@@ -101,7 +101,7 @@ declare class ReactWebpackPlugin {
|
|
|
101
101
|
*
|
|
102
102
|
* @public
|
|
103
103
|
*/
|
|
104
|
-
static loaders: Record<keyof typeof LAYERS, string>;
|
|
104
|
+
static loaders: Record<keyof typeof LAYERS | 'TESTING', string>;
|
|
105
105
|
constructor(options?: ReactWebpackPluginOptions | undefined);
|
|
106
106
|
/**
|
|
107
107
|
* `defaultOptions` is the default options that the {@link ReactWebpackPlugin} uses.
|
|
@@ -60,6 +60,7 @@ class ReactWebpackPlugin {
|
|
|
60
60
|
static { this.loaders = {
|
|
61
61
|
BACKGROUND: require.resolve('../lib/loaders/background.js'),
|
|
62
62
|
MAIN_THREAD: require.resolve('../lib/loaders/main-thread.js'),
|
|
63
|
+
TESTING: require.resolve('../lib/loaders/testing.js'),
|
|
63
64
|
}; }
|
|
64
65
|
constructor(options) {
|
|
65
66
|
this.options = options;
|
package/lib/loaders/options.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { LoaderContext } from '@rspack/core';
|
|
2
2
|
import type { CompatVisitorConfig, DefineDceVisitorConfig, JsxTransformerConfig, ShakeVisitorConfig, TransformNodiffOptions } from '@lynx-js/react/transform';
|
|
3
|
+
export declare const JSX_IMPORT_SOURCE: {
|
|
4
|
+
MAIN_THREAD: string;
|
|
5
|
+
BACKGROUND: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const RUNTIME_PKG = "@lynx-js/react/internal";
|
|
3
8
|
/**
|
|
4
9
|
* The options of the ReactLynx plugin.
|
|
5
10
|
* @public
|
package/lib/loaders/options.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
const PLUGIN_NAME = 'react:webpack';
|
|
6
|
-
const JSX_IMPORT_SOURCE = {
|
|
6
|
+
export const JSX_IMPORT_SOURCE = {
|
|
7
7
|
MAIN_THREAD: '@lynx-js/react/lepus',
|
|
8
8
|
BACKGROUND: '@lynx-js/react',
|
|
9
9
|
};
|
|
10
10
|
const PUBLIC_RUNTIME_PKG = '@lynx-js/react';
|
|
11
|
-
const RUNTIME_PKG = '@lynx-js/react/internal';
|
|
11
|
+
export const RUNTIME_PKG = '@lynx-js/react/internal';
|
|
12
12
|
const OLD_RUNTIME_PKG = '@lynx-js/react-runtime';
|
|
13
13
|
const COMPONENT_PKG = '@lynx-js/react-components';
|
|
14
14
|
function normalizeSlashes(file) {
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { JSX_IMPORT_SOURCE, RUNTIME_PKG } from './options.js';
|
|
7
|
+
function normalizeSlashes(file) {
|
|
8
|
+
return file.replaceAll(path.win32.sep, '/');
|
|
9
|
+
}
|
|
10
|
+
function testingLoader(content) {
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
const { compat = false, defineDCE = { define: {} }, engineVersion = '', shake = false, transformPath = '@lynx-js/react/transform', } = this.getOptions();
|
|
13
|
+
const { transformReactLynxSync } = require(transformPath);
|
|
14
|
+
const filename = normalizeSlashes(path.relative(this.rootContext, this.resourcePath));
|
|
15
|
+
const result = transformReactLynxSync(content, {
|
|
16
|
+
mode: 'test',
|
|
17
|
+
pluginName: '',
|
|
18
|
+
filename: this.resourcePath,
|
|
19
|
+
sourcemap: true,
|
|
20
|
+
snapshot: {
|
|
21
|
+
preserveJsx: false,
|
|
22
|
+
runtimePkg: RUNTIME_PKG,
|
|
23
|
+
jsxImportSource: JSX_IMPORT_SOURCE.BACKGROUND,
|
|
24
|
+
filename,
|
|
25
|
+
target: 'MIXED',
|
|
26
|
+
},
|
|
27
|
+
// snapshot: true,
|
|
28
|
+
directiveDCE: false,
|
|
29
|
+
defineDCE,
|
|
30
|
+
shake,
|
|
31
|
+
compat,
|
|
32
|
+
engineVersion,
|
|
33
|
+
worklet: {
|
|
34
|
+
filename,
|
|
35
|
+
runtimePkg: RUNTIME_PKG,
|
|
36
|
+
target: 'MIXED',
|
|
37
|
+
},
|
|
38
|
+
refresh: false,
|
|
39
|
+
cssScope: false,
|
|
40
|
+
});
|
|
41
|
+
if (result.errors.length > 0) {
|
|
42
|
+
for (const error of result.errors) {
|
|
43
|
+
if (this.experiments?.emitDiagnostic) {
|
|
44
|
+
// Rspack with `emitDiagnostic` API
|
|
45
|
+
try {
|
|
46
|
+
this.experiments.emitDiagnostic({
|
|
47
|
+
message: error.text,
|
|
48
|
+
sourceCode: content,
|
|
49
|
+
location: {
|
|
50
|
+
line: error.location?.line ?? 1,
|
|
51
|
+
column: error.location?.column ?? 0,
|
|
52
|
+
length: error.location?.length ?? 0,
|
|
53
|
+
text: error.text ?? '',
|
|
54
|
+
},
|
|
55
|
+
severity: 'error',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Rspack may throw on invalid line & column when containing UTF-8.
|
|
60
|
+
// We catch it up here.
|
|
61
|
+
this.emitError(new Error(error.text));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// Webpack or legacy Rspack
|
|
66
|
+
this.emitError(new Error(error.text));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
this.callback(new Error('react-transform failed'));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
for (const warning of result.warnings) {
|
|
73
|
+
if (this.experiments?.emitDiagnostic) {
|
|
74
|
+
// Rspack with `emitDiagnostic` API
|
|
75
|
+
try {
|
|
76
|
+
this.experiments.emitDiagnostic({
|
|
77
|
+
message: warning.text,
|
|
78
|
+
sourceCode: content,
|
|
79
|
+
location: {
|
|
80
|
+
line: warning.location?.line ?? 1,
|
|
81
|
+
column: warning.location?.column ?? 0,
|
|
82
|
+
length: warning.location?.length ?? 0,
|
|
83
|
+
text: warning.text ?? '',
|
|
84
|
+
},
|
|
85
|
+
severity: 'warning',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Rspack may throw on invalid line & column when containing UTF-8.
|
|
90
|
+
// We catch it up here.
|
|
91
|
+
this.emitWarning(new Error(warning.text));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// Webpack or legacy Rspack
|
|
96
|
+
this.emitWarning(new Error(warning.text));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
this.callback(null, result.code, result.map);
|
|
100
|
+
}
|
|
101
|
+
export default testingLoader;
|
|
102
|
+
//# sourceMappingURL=testing.js.map
|
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.1-canary-20260413-b1ad1b98",
|
|
4
4
|
"description": "A webpack plugin for ReactLynx",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"swc-loader": "^0.2.7",
|
|
44
44
|
"webpack": "^5.105.2",
|
|
45
45
|
"@lynx-js/css-extract-webpack-plugin": "npm:@lynx-js/css-extract-webpack-plugin-canary@0.7.0",
|
|
46
|
-
"@lynx-js/
|
|
47
|
-
"@lynx-js/
|
|
46
|
+
"@lynx-js/template-webpack-plugin": "npm:@lynx-js/template-webpack-plugin-canary@0.10.9-canary-20260413-b1ad1b98",
|
|
47
|
+
"@lynx-js/vitest-setup": "0.0.0",
|
|
48
48
|
"@lynx-js/test-tools": "0.0.0",
|
|
49
|
-
"@lynx-js/
|
|
49
|
+
"@lynx-js/react": "npm:@lynx-js/react-canary@0.118.1-canary-20260413-b1ad1b98"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@lynx-js/template-webpack-plugin": "*"
|