@lynx-js/react-webpack-plugin 0.9.2 → 0.9.4
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 +19 -0
- package/lib/LynxProcessEvalResultRuntimeModule.js +1 -1
- package/lib/ReactWebpackPlugin.d.ts +17 -0
- package/lib/ReactWebpackPlugin.js +74 -3
- package/lib/loaders/main-thread.d.ts +1 -0
- package/lib/loaders/main-thread.js +8 -1
- package/lib/loaders/options.d.ts +8 -0
- package/lib/loaders/options.js +35 -4
- package/lib/loaders/testing.js +12 -3
- package/package.json +10 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @lynx-js/react-webpack-plugin
|
|
2
2
|
|
|
3
|
+
## 0.9.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Support the unified `debug-metadata.json` format and depend on `@lynx-js/debug-metadata`. ([#2642](https://github.com/lynx-family/lynx-stack/pull/2642))
|
|
8
|
+
|
|
9
|
+
- Prefix Lynx runtime module names with `webpack/runtime/` (e.g. `Lynx async chunks` → `webpack/runtime/lynx async chunks`), matching the path-structured naming of the bundler's built-in runtime modules. The previous bare names had no path segment, so when they appear as a source-map `sources` entry under a `file://` module-filename template they collapsed into an invalid URL authority (the space-containing name became the host) and broke `SourceMapConsumer` parsing. ([#2642](https://github.com/lynx-family/lynx-stack/pull/2642))
|
|
10
|
+
|
|
11
|
+
- Widen peer ranges to admit the new minor versions of `@lynx-js/template-webpack-plugin` (^0.12.0) and `@lynx-js/rspeedy` (^0.15.0) shipping with the unified `debug-metadata.json` feature. ([#2642](https://github.com/lynx-family/lynx-stack/pull/2642))
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`a839d59`](https://github.com/lynx-family/lynx-stack/commit/a839d59b7f477a86f2cd10215d0b754264e54425), [`d3201df`](https://github.com/lynx-family/lynx-stack/commit/d3201dfa57964bfe6c8c52a803aeeb0fca1f2d27), [`409594b`](https://github.com/lynx-family/lynx-stack/commit/409594b9c51bb0c13f01c7d3f16949b27ebfdced), [`353363e`](https://github.com/lynx-family/lynx-stack/commit/353363e52dca3b252b39b34a3a87ce840dd308f3)]:
|
|
14
|
+
- @lynx-js/debug-metadata@0.1.0
|
|
15
|
+
|
|
16
|
+
## 0.9.3
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Inject the `lynxProcessEvalResult` runtime module only into main-thread chunks. The previous guard checked the chunk name for `:background`, which never matched the actual chunk names (`main__background`, `foo.js-react__background`), so the runtime was duplicated into background and async background chunks. ([#2692](https://github.com/lynx-family/lynx-stack/pull/2692))
|
|
21
|
+
|
|
3
22
|
## 0.9.2
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -2,7 +2,7 @@ import { RuntimeGlobals as LynxRuntimeGlobals } from '@lynx-js/webpack-runtime-g
|
|
|
2
2
|
export function createLynxProcessEvalResultRuntimeModule(webpack) {
|
|
3
3
|
return class LynxProcessEvalResultRuntimeModule extends webpack.RuntimeModule {
|
|
4
4
|
constructor() {
|
|
5
|
-
super('
|
|
5
|
+
super('webpack/runtime/lynx process eval result', webpack.RuntimeModule.STAGE_ATTACH);
|
|
6
6
|
}
|
|
7
7
|
generate() {
|
|
8
8
|
const chunk = this.chunk;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { Compiler } from '@rspack/core';
|
|
2
2
|
import type { ExtractStrConfig } from '@lynx-js/react/transform';
|
|
3
3
|
import { LAYERS } from './layer.js';
|
|
4
|
+
interface ElementTemplateBuildInfo {
|
|
5
|
+
templateId: string;
|
|
6
|
+
compiledTemplate: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export interface ModuleWithElementTemplateBuildInfo {
|
|
9
|
+
buildInfo?: Record<string, unknown>;
|
|
10
|
+
modules?: Iterable<ModuleWithElementTemplateBuildInfo>;
|
|
11
|
+
}
|
|
12
|
+
export declare function collectElementTemplatesFromModule(module: ModuleWithElementTemplateBuildInfo): ElementTemplateBuildInfo[];
|
|
13
|
+
export declare function mergeElementTemplate(elementTemplates: Record<string, Record<string, unknown>>, templateId: string, compiledTemplate: Record<string, unknown>): void;
|
|
14
|
+
export declare function mergeElementTemplatesFromModule(elementTemplates: Record<string, Record<string, unknown>>, module: ModuleWithElementTemplateBuildInfo): void;
|
|
4
15
|
/**
|
|
5
16
|
* The options for ReactWebpackPlugin
|
|
6
17
|
*
|
|
@@ -50,6 +61,12 @@ interface ReactWebpackPluginOptions {
|
|
|
50
61
|
* The file path of `@lynx-js/react/worklet-runtime`.
|
|
51
62
|
*/
|
|
52
63
|
workletRuntimePath: string;
|
|
64
|
+
/**
|
|
65
|
+
* Whether to enable Element Template compilation.
|
|
66
|
+
*
|
|
67
|
+
* @experimental
|
|
68
|
+
*/
|
|
69
|
+
experimental_useElementTemplate?: boolean;
|
|
53
70
|
}
|
|
54
71
|
/**
|
|
55
72
|
* ReactWebpackPlugin allows using ReactLynx with webpack
|
|
@@ -7,8 +7,67 @@ import invariant from 'tiny-invariant';
|
|
|
7
7
|
import { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin';
|
|
8
8
|
import { RuntimeGlobals } from '@lynx-js/webpack-runtime-globals';
|
|
9
9
|
import { LAYERS } from './layer.js';
|
|
10
|
+
import { ELEMENT_TEMPLATE_BUILD_INFO } from './loaders/main-thread.js';
|
|
10
11
|
import { createLynxProcessEvalResultRuntimeModule } from './LynxProcessEvalResultRuntimeModule.js';
|
|
11
12
|
const require = createRequire(import.meta.url);
|
|
13
|
+
export function collectElementTemplatesFromModule(module) {
|
|
14
|
+
const elementTemplates = [];
|
|
15
|
+
const templates = module.buildInfo?.[ELEMENT_TEMPLATE_BUILD_INFO];
|
|
16
|
+
if (Array.isArray(templates)) {
|
|
17
|
+
elementTemplates.push(...templates);
|
|
18
|
+
}
|
|
19
|
+
if (module.modules) {
|
|
20
|
+
for (const nestedModule of module.modules) {
|
|
21
|
+
elementTemplates.push(...collectElementTemplatesFromModule(nestedModule));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return elementTemplates;
|
|
25
|
+
}
|
|
26
|
+
function isPlainRecord(value) {
|
|
27
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
28
|
+
}
|
|
29
|
+
function areCompiledTemplateValuesEqual(left, right) {
|
|
30
|
+
if (Object.is(left, right)) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
34
|
+
if (!Array.isArray(left)
|
|
35
|
+
|| !Array.isArray(right)
|
|
36
|
+
|| left.length !== right.length) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return left.every((value, index) => areCompiledTemplateValuesEqual(value, right[index]));
|
|
40
|
+
}
|
|
41
|
+
if (isPlainRecord(left) || isPlainRecord(right)) {
|
|
42
|
+
if (!isPlainRecord(left) || !isPlainRecord(right)) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const leftKeys = Object.keys(left).sort();
|
|
46
|
+
const rightKeys = Object.keys(right).sort();
|
|
47
|
+
if (leftKeys.length !== rightKeys.length) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return leftKeys.every((key, index) => key === rightKeys[index]
|
|
51
|
+
&& areCompiledTemplateValuesEqual(left[key], right[key]));
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
export function mergeElementTemplate(elementTemplates, templateId, compiledTemplate) {
|
|
56
|
+
const existingTemplate = elementTemplates[templateId];
|
|
57
|
+
if (!existingTemplate) {
|
|
58
|
+
elementTemplates[templateId] = compiledTemplate;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (areCompiledTemplateValuesEqual(existingTemplate, compiledTemplate)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`Element Template id collision for ${templateId}: same template id has different compiledTemplate content.`);
|
|
65
|
+
}
|
|
66
|
+
export function mergeElementTemplatesFromModule(elementTemplates, module) {
|
|
67
|
+
for (const { templateId, compiledTemplate } of collectElementTemplatesFromModule(module)) {
|
|
68
|
+
mergeElementTemplate(elementTemplates, templateId, compiledTemplate);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
12
71
|
/**
|
|
13
72
|
* ReactWebpackPlugin allows using ReactLynx with webpack
|
|
14
73
|
*
|
|
@@ -81,6 +140,7 @@ class ReactWebpackPlugin {
|
|
|
81
140
|
experimental_isLazyBundle: false,
|
|
82
141
|
profile: undefined,
|
|
83
142
|
workletRuntimePath: '',
|
|
143
|
+
experimental_useElementTemplate: false,
|
|
84
144
|
}); }
|
|
85
145
|
/**
|
|
86
146
|
* The entry point of a webpack plugin.
|
|
@@ -120,6 +180,7 @@ class ReactWebpackPlugin {
|
|
|
120
180
|
__GLOBAL_PROPS_MODE__: JSON.stringify(options.globalPropsMode),
|
|
121
181
|
__ENABLE_SSR__: JSON.stringify(options.enableSSR),
|
|
122
182
|
__DISABLE_CREATE_SELECTOR_QUERY_INCOMPATIBLE_WARNING__: JSON.stringify(options.disableCreateSelectorQueryIncompatibleWarning),
|
|
183
|
+
__USE_ELEMENT_TEMPLATE__: JSON.stringify(options.experimental_useElementTemplate),
|
|
123
184
|
}).apply(compiler);
|
|
124
185
|
compiler.hooks.thisCompilation.tap(this.constructor.name, compilation => {
|
|
125
186
|
const onceForChunkSet = new WeakSet();
|
|
@@ -131,7 +192,7 @@ class ReactWebpackPlugin {
|
|
|
131
192
|
return;
|
|
132
193
|
}
|
|
133
194
|
onceForChunkSet.add(chunk);
|
|
134
|
-
if (chunk.name?.includes('
|
|
195
|
+
if (!chunk.name?.includes('__main-thread')) {
|
|
135
196
|
return;
|
|
136
197
|
}
|
|
137
198
|
const LynxProcessEvalResultRuntimeModule = createLynxProcessEvalResultRuntimeModule(compiler.webpack);
|
|
@@ -156,8 +217,6 @@ class ReactWebpackPlugin {
|
|
|
156
217
|
.forEach(name => this.#updateMainThreadInfo(compilation, name));
|
|
157
218
|
});
|
|
158
219
|
});
|
|
159
|
-
// TODO: replace LynxTemplatePlugin types with Rspack
|
|
160
|
-
// @ts-expect-error Rspack x Webpack compilation not match
|
|
161
220
|
const hooks = LynxTemplatePlugin.getLynxTemplatePluginHooks(compilation);
|
|
162
221
|
const { RawSource, ConcatSource } = compiler.webpack.sources;
|
|
163
222
|
hooks.beforeEncode.tap(this.constructor.name, (args) => {
|
|
@@ -222,6 +281,18 @@ class ReactWebpackPlugin {
|
|
|
222
281
|
hooks.asyncChunkName.tap(this.constructor.name, (chunkName) => chunkName
|
|
223
282
|
?.replaceAll(`-react__background`, '')
|
|
224
283
|
?.replaceAll(`-react__main-thread`, ''));
|
|
284
|
+
if (options.experimental_useElementTemplate) {
|
|
285
|
+
hooks.beforeEncode.tap(`${this.constructor.name}.ElementTemplate`, (args) => {
|
|
286
|
+
const elementTemplates = {};
|
|
287
|
+
for (const module of compilation.modules) {
|
|
288
|
+
mergeElementTemplatesFromModule(elementTemplates, module);
|
|
289
|
+
}
|
|
290
|
+
args.encodeData.sourceContent.config['enableUnifyFixedBehavior'] =
|
|
291
|
+
true;
|
|
292
|
+
args.encodeData.elementTemplate = elementTemplates;
|
|
293
|
+
return args;
|
|
294
|
+
});
|
|
295
|
+
}
|
|
225
296
|
});
|
|
226
297
|
}
|
|
227
298
|
#updateMainThreadInfo(compilation, name) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { LoaderDefinitionFunction } from '@rspack/core';
|
|
2
2
|
import type { ReactLoaderOptions } from './options.js';
|
|
3
|
+
export declare const ELEMENT_TEMPLATE_BUILD_INFO = "lynx:element-templates";
|
|
3
4
|
declare const mainThreadLoader: LoaderDefinitionFunction<ReactLoaderOptions>;
|
|
4
5
|
export default mainThreadLoader;
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
|
-
import { UI_SOURCE_MAP_RECORDS_BUILD_INFO } from '@lynx-js/
|
|
5
|
+
import { UI_SOURCE_MAP_RECORDS_BUILD_INFO } from '@lynx-js/debug-metadata';
|
|
6
6
|
import { getMainThreadTransformOptions } from './options.js';
|
|
7
|
+
export const ELEMENT_TEMPLATE_BUILD_INFO = 'lynx:element-templates';
|
|
7
8
|
const mainThreadLoader = function (content, sourceMap) {
|
|
8
9
|
const require = createRequire(import.meta.url);
|
|
9
10
|
const { transformPath = '@lynx-js/react/transform' } = this.getOptions();
|
|
@@ -80,6 +81,12 @@ const mainThreadLoader = function (content, sourceMap) {
|
|
|
80
81
|
const buildInfo = currentModule?.buildInfo;
|
|
81
82
|
if (buildInfo) {
|
|
82
83
|
buildInfo[UI_SOURCE_MAP_RECORDS_BUILD_INFO] = result.uiSourceMapRecords;
|
|
84
|
+
if (result.elementTemplates && result.elementTemplates.length > 0) {
|
|
85
|
+
buildInfo[ELEMENT_TEMPLATE_BUILD_INFO] = result.elementTemplates;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
delete buildInfo[ELEMENT_TEMPLATE_BUILD_INFO];
|
|
89
|
+
}
|
|
83
90
|
}
|
|
84
91
|
this.callback(null, result.code + (this.hot
|
|
85
92
|
// TODO: temporary fix LEPUS error `$RefreshReg$ is not defined`
|
package/lib/loaders/options.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ import type { CompatVisitorConfig, DefineDceVisitorConfig, JsxTransformerConfig,
|
|
|
3
3
|
export declare const JSX_IMPORT_SOURCE: {
|
|
4
4
|
MAIN_THREAD: string;
|
|
5
5
|
BACKGROUND: string;
|
|
6
|
+
ELEMENT_TEMPLATE: string;
|
|
6
7
|
};
|
|
7
8
|
export declare const RUNTIME_PKG = "@lynx-js/react/internal";
|
|
9
|
+
export declare const ELEMENT_TEMPLATE_RUNTIME_PKG = "@lynx-js/react/element-template";
|
|
8
10
|
/**
|
|
9
11
|
* The options of the ReactLynx plugin.
|
|
10
12
|
* @public
|
|
@@ -46,6 +48,12 @@ export interface ReactLoaderOptions {
|
|
|
46
48
|
* The engine version.
|
|
47
49
|
*/
|
|
48
50
|
engineVersion?: string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Whether to enable Element Template compilation.
|
|
53
|
+
*
|
|
54
|
+
* @experimental
|
|
55
|
+
*/
|
|
56
|
+
experimental_useElementTemplate?: boolean | undefined;
|
|
49
57
|
}
|
|
50
58
|
export declare function getMainThreadTransformOptions(this: LoaderContext<ReactLoaderOptions>, inputSourceMap: string | undefined): TransformNodiffOptions;
|
|
51
59
|
export declare function getBackgroundTransformOptions(this: LoaderContext<ReactLoaderOptions>, inputSourceMap: string | undefined): TransformNodiffOptions;
|
package/lib/loaders/options.js
CHANGED
|
@@ -6,9 +6,11 @@ const PLUGIN_NAME = 'react:webpack';
|
|
|
6
6
|
export const JSX_IMPORT_SOURCE = {
|
|
7
7
|
MAIN_THREAD: '@lynx-js/react/lepus',
|
|
8
8
|
BACKGROUND: '@lynx-js/react',
|
|
9
|
+
ELEMENT_TEMPLATE: '@lynx-js/react/element-template',
|
|
9
10
|
};
|
|
10
11
|
const PUBLIC_RUNTIME_PKG = '@lynx-js/react';
|
|
11
12
|
export const RUNTIME_PKG = '@lynx-js/react/internal';
|
|
13
|
+
export const ELEMENT_TEMPLATE_RUNTIME_PKG = '@lynx-js/react/element-template';
|
|
12
14
|
const OLD_RUNTIME_PKG = '@lynx-js/react-runtime';
|
|
13
15
|
const COMPONENT_PKG = '@lynx-js/react-components';
|
|
14
16
|
function normalizeSlashes(file) {
|
|
@@ -16,7 +18,8 @@ function normalizeSlashes(file) {
|
|
|
16
18
|
}
|
|
17
19
|
function getCommonOptions(inputSourceMap) {
|
|
18
20
|
const filename = normalizeSlashes(path.relative(this.rootContext, this.resourcePath));
|
|
19
|
-
const { compat, enableRemoveCSSScope, enableUiSourceMap, inlineSourcesContent, isDynamicComponent, engineVersion, defineDCE = { define: {} }, } = this.getOptions();
|
|
21
|
+
const { compat, enableRemoveCSSScope, enableUiSourceMap, inlineSourcesContent, isDynamicComponent, engineVersion, experimental_useElementTemplate, defineDCE = { define: {} }, } = this.getOptions();
|
|
22
|
+
const useElementTemplate = experimental_useElementTemplate === true;
|
|
20
23
|
const syntax = (/\.[mc]?tsx?$/.exec(this.resourcePath))
|
|
21
24
|
? 'typescript'
|
|
22
25
|
: 'ecmascript';
|
|
@@ -61,7 +64,7 @@ function getCommonOptions(inputSourceMap) {
|
|
|
61
64
|
...(inputSourceMap && { inputSourceMap }),
|
|
62
65
|
sourceMapColumns: this.sourceMap && !this.hot,
|
|
63
66
|
inlineSourcesContent: inlineSourcesContent ?? !this.hot,
|
|
64
|
-
snapshot: {
|
|
67
|
+
snapshot: useElementTemplate ? false : {
|
|
65
68
|
// TODO: config
|
|
66
69
|
preserveJsx: false,
|
|
67
70
|
// In standalone lazy bundle mode, we do not support HMR now.
|
|
@@ -75,6 +78,16 @@ function getCommonOptions(inputSourceMap) {
|
|
|
75
78
|
filename,
|
|
76
79
|
isDynamicComponent: isDynamicComponent ?? false,
|
|
77
80
|
},
|
|
81
|
+
elementTemplate: useElementTemplate
|
|
82
|
+
? {
|
|
83
|
+
preserveJsx: false,
|
|
84
|
+
runtimePkg: ELEMENT_TEMPLATE_RUNTIME_PKG,
|
|
85
|
+
jsxImportSource: JSX_IMPORT_SOURCE.ELEMENT_TEMPLATE,
|
|
86
|
+
filename,
|
|
87
|
+
target: 'JS',
|
|
88
|
+
isDynamicComponent: isDynamicComponent ?? false,
|
|
89
|
+
}
|
|
90
|
+
: false,
|
|
78
91
|
engineVersion: engineVersion ?? '',
|
|
79
92
|
syntaxConfig: JSON.stringify({
|
|
80
93
|
syntax,
|
|
@@ -100,6 +113,7 @@ function getCommonOptions(inputSourceMap) {
|
|
|
100
113
|
export function getMainThreadTransformOptions(inputSourceMap) {
|
|
101
114
|
const commonOptions = getCommonOptions.call(this, inputSourceMap);
|
|
102
115
|
const { shake } = this.getOptions();
|
|
116
|
+
const useElementTemplate = typeof commonOptions.elementTemplate === 'object';
|
|
103
117
|
return {
|
|
104
118
|
...commonOptions,
|
|
105
119
|
compat: typeof commonOptions.compat === 'object'
|
|
@@ -108,11 +122,18 @@ export function getMainThreadTransformOptions(inputSourceMap) {
|
|
|
108
122
|
target: 'LEPUS',
|
|
109
123
|
}
|
|
110
124
|
: false,
|
|
111
|
-
snapshot: {
|
|
125
|
+
snapshot: useElementTemplate ? false : {
|
|
112
126
|
...commonOptions.snapshot,
|
|
113
127
|
jsxImportSource: JSX_IMPORT_SOURCE.MAIN_THREAD,
|
|
114
128
|
target: 'LEPUS',
|
|
115
129
|
},
|
|
130
|
+
elementTemplate: useElementTemplate
|
|
131
|
+
? {
|
|
132
|
+
...commonOptions.elementTemplate,
|
|
133
|
+
jsxImportSource: JSX_IMPORT_SOURCE.ELEMENT_TEMPLATE,
|
|
134
|
+
target: 'LEPUS',
|
|
135
|
+
}
|
|
136
|
+
: false,
|
|
116
137
|
dynamicImport: {
|
|
117
138
|
layer: `react__main-thread`,
|
|
118
139
|
runtimePkg: RUNTIME_PKG,
|
|
@@ -141,6 +162,8 @@ export function getMainThreadTransformOptions(inputSourceMap) {
|
|
|
141
162
|
PUBLIC_RUNTIME_PKG,
|
|
142
163
|
`${PUBLIC_RUNTIME_PKG}/legacy-react-runtime`,
|
|
143
164
|
RUNTIME_PKG,
|
|
165
|
+
ELEMENT_TEMPLATE_RUNTIME_PKG,
|
|
166
|
+
`${ELEMENT_TEMPLATE_RUNTIME_PKG}/internal`,
|
|
144
167
|
...typeof commonOptions.compat === 'object'
|
|
145
168
|
? commonOptions.compat.oldRuntimePkg
|
|
146
169
|
: [],
|
|
@@ -178,6 +201,7 @@ export function getMainThreadTransformOptions(inputSourceMap) {
|
|
|
178
201
|
}
|
|
179
202
|
export function getBackgroundTransformOptions(inputSourceMap) {
|
|
180
203
|
const commonOptions = getCommonOptions.call(this, inputSourceMap);
|
|
204
|
+
const useElementTemplate = typeof commonOptions.elementTemplate === 'object';
|
|
181
205
|
return {
|
|
182
206
|
...commonOptions,
|
|
183
207
|
compat: typeof commonOptions.compat === 'object'
|
|
@@ -190,10 +214,17 @@ export function getBackgroundTransformOptions(inputSourceMap) {
|
|
|
190
214
|
layer: `react__background`,
|
|
191
215
|
runtimePkg: RUNTIME_PKG,
|
|
192
216
|
},
|
|
193
|
-
snapshot: {
|
|
217
|
+
snapshot: useElementTemplate ? false : {
|
|
194
218
|
...commonOptions.snapshot,
|
|
195
219
|
jsxImportSource: JSX_IMPORT_SOURCE.BACKGROUND,
|
|
196
220
|
},
|
|
221
|
+
elementTemplate: useElementTemplate
|
|
222
|
+
? {
|
|
223
|
+
...commonOptions.elementTemplate,
|
|
224
|
+
jsxImportSource: JSX_IMPORT_SOURCE.BACKGROUND,
|
|
225
|
+
target: 'JS',
|
|
226
|
+
}
|
|
227
|
+
: false,
|
|
197
228
|
defineDCE: {
|
|
198
229
|
define: {
|
|
199
230
|
...commonOptions.defineDCE?.define,
|
package/lib/loaders/testing.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
-
import { JSX_IMPORT_SOURCE, RUNTIME_PKG } from './options.js';
|
|
6
|
+
import { ELEMENT_TEMPLATE_RUNTIME_PKG, JSX_IMPORT_SOURCE, RUNTIME_PKG, } from './options.js';
|
|
7
7
|
function normalizeSlashes(file) {
|
|
8
8
|
return file.replaceAll(path.win32.sep, '/');
|
|
9
9
|
}
|
|
10
10
|
function testingLoader(content) {
|
|
11
11
|
const require = createRequire(import.meta.url);
|
|
12
|
-
const { compat = false, defineDCE = { define: {} }, engineVersion = '', shake = false, transformPath = '@lynx-js/react/transform', } = this.getOptions();
|
|
12
|
+
const { compat = false, defineDCE = { define: {} }, engineVersion = '', experimental_useElementTemplate = false, shake = false, transformPath = '@lynx-js/react/transform', } = this.getOptions();
|
|
13
13
|
const { transformReactLynxSync } = require(transformPath);
|
|
14
14
|
const filename = normalizeSlashes(path.relative(this.rootContext, this.resourcePath));
|
|
15
15
|
const normalizedCompat = typeof compat === 'object'
|
|
@@ -33,13 +33,22 @@ function testingLoader(content) {
|
|
|
33
33
|
pluginName: '',
|
|
34
34
|
filename: this.resourcePath,
|
|
35
35
|
sourcemap: true,
|
|
36
|
-
snapshot: {
|
|
36
|
+
snapshot: experimental_useElementTemplate ? false : {
|
|
37
37
|
preserveJsx: false,
|
|
38
38
|
runtimePkg: RUNTIME_PKG,
|
|
39
39
|
jsxImportSource: JSX_IMPORT_SOURCE.BACKGROUND,
|
|
40
40
|
filename,
|
|
41
41
|
target: 'MIXED',
|
|
42
42
|
},
|
|
43
|
+
elementTemplate: experimental_useElementTemplate
|
|
44
|
+
? {
|
|
45
|
+
preserveJsx: false,
|
|
46
|
+
runtimePkg: ELEMENT_TEMPLATE_RUNTIME_PKG,
|
|
47
|
+
jsxImportSource: JSX_IMPORT_SOURCE.ELEMENT_TEMPLATE,
|
|
48
|
+
filename,
|
|
49
|
+
target: 'MIXED',
|
|
50
|
+
}
|
|
51
|
+
: false,
|
|
43
52
|
// snapshot: true,
|
|
44
53
|
directiveDCE: false,
|
|
45
54
|
defineDCE,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/react-webpack-plugin",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"description": "A webpack plugin for ReactLynx",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -34,22 +34,23 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"tiny-invariant": "^1.3.3",
|
|
37
|
+
"@lynx-js/debug-metadata": "^0.1.0",
|
|
37
38
|
"@lynx-js/webpack-runtime-globals": "0.0.6"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@microsoft/api-extractor": "7.58.2",
|
|
41
|
-
"@rspack/core": "
|
|
42
|
+
"@rspack/core": "2.0.8",
|
|
43
|
+
"@rspack/lite-tapable": "1.1.0",
|
|
44
|
+
"@rstest/core": "0.10.5",
|
|
42
45
|
"css-loader": "^7.1.4",
|
|
43
46
|
"swc-loader": "^0.2.7",
|
|
44
|
-
"webpack": "
|
|
45
|
-
"@lynx-js/
|
|
46
|
-
"@lynx-js/react": "0.120.0",
|
|
47
|
-
"@lynx-js/template-webpack-plugin": "0.11.0",
|
|
47
|
+
"@lynx-js/css-extract-webpack-plugin": "0.8.0",
|
|
48
|
+
"@lynx-js/react": "0.121.2",
|
|
48
49
|
"@lynx-js/test-tools": "0.0.0",
|
|
49
|
-
"@lynx-js/
|
|
50
|
+
"@lynx-js/template-webpack-plugin": "0.12.0"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
52
|
-
"@lynx-js/template-webpack-plugin": "^0.4.0 || ^0.5.0 || ^0.6.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0"
|
|
53
|
+
"@lynx-js/template-webpack-plugin": "^0.4.0 || ^0.5.0 || ^0.6.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0"
|
|
53
54
|
},
|
|
54
55
|
"peerDependenciesMeta": {
|
|
55
56
|
"@lynx-js/react": {
|
|
@@ -61,6 +62,6 @@
|
|
|
61
62
|
},
|
|
62
63
|
"scripts": {
|
|
63
64
|
"api-extractor": "api-extractor run --verbose",
|
|
64
|
-
"test": "
|
|
65
|
+
"test": "rstest"
|
|
65
66
|
}
|
|
66
67
|
}
|