@lynx-js/react-webpack-plugin 0.6.6

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 ADDED
@@ -0,0 +1,134 @@
1
+ # @lynx-js/react-webpack-plugin
2
+
3
+ ## 0.6.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 1abf8f0: Be compat with `@lynx-js/react` v0.105.0
8
+ - 1abf8f0: Improve compilation performance by avoid using `compilation.updateAsset`.
9
+
10
+ ## 0.6.5
11
+
12
+ ### Patch Changes
13
+
14
+ - 94419fb: Support `@lynx-js/react` v0.104.0
15
+ - 1bf9271: fix(react): default `compat` in transform to `false`
16
+
17
+ ## 0.6.4
18
+
19
+ ### Patch Changes
20
+
21
+ - 0d3b44c: Support `@lynx-js/template-webpack-plugin` v0.6.0.
22
+ - 74e0ea3: Supports new `__MAIN_THREAD__` and `__BACKGROUND__` macro as an alternative to `__LEPUS__` and `__JS__`.
23
+
24
+ ## 0.6.3
25
+
26
+ ### Patch Changes
27
+
28
+ - 65ecd41: Fix `module` is not defined when using lazy bundle.
29
+
30
+ ## 0.6.2
31
+
32
+ ### Patch Changes
33
+
34
+ - 3bf5830: Add `lynxProcessEvalResult`.
35
+ - Updated dependencies [3bf5830]
36
+ - @lynx-js/webpack-runtime-globals@0.0.4
37
+
38
+ ## 0.6.1
39
+
40
+ ### Patch Changes
41
+
42
+ - e8039f2: Add `defineDCE` in plugin options. Often used to define custom macros.
43
+
44
+ ```js
45
+ import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin';
46
+ import { defineConfig } from '@lynx-js/rspeedy';
47
+
48
+ export default defineConfig({
49
+ plugins: [
50
+ pluginReactLynx({
51
+ defineDCE: {
52
+ __SOME_FALSE_DEFINE__: 'false',
53
+ },
54
+ }),
55
+ ],
56
+ });
57
+ ```
58
+
59
+ Different from `define` provided by bundlers like webpack, `defineDCE` works at transform time and a extra DCE (Dead Code Elimination) pass will be performed.
60
+
61
+ For example, `import` initialized by dead code will be removed:
62
+
63
+ ```js
64
+ import { foo } from 'bar';
65
+
66
+ if (__SOME_FALSE_DEFINE__) {
67
+ foo();
68
+ console.log('dead code');
69
+ } else {
70
+ console.log('reachable code');
71
+ }
72
+ ```
73
+
74
+ will be transformed to:
75
+
76
+ ```js
77
+ console.log('reachable code');
78
+ ```
79
+
80
+ ## 0.6.0
81
+
82
+ ### Minor Changes
83
+
84
+ - a30c83d: Add `compat.removeComponentAttrRegex`.
85
+
86
+ ```js
87
+ import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin';
88
+ import { defineConfig } from '@lynx-js/rspeedy';
89
+
90
+ export default defineConfig({
91
+ plugins: [
92
+ pluginReactLynx({
93
+ compat: {
94
+ removeComponentAttrRegex: 'YOUR REGEX',
95
+ },
96
+ }),
97
+ ],
98
+ });
99
+ ```
100
+
101
+ NOTE: This feature is deprecated and will be removed in the future. Use codemod instead.
102
+
103
+ - 5f8d492: **BREAKING CHANGE**: Require `@lynx-js/react` v0.103.0.
104
+ - 5f8d492: Deprecate `compat.simplifyCtorLikeReactLynx2`
105
+
106
+ ## 0.5.2
107
+
108
+ ### Patch Changes
109
+
110
+ - e3be842: Support `@lynx-js/react` v0.102.0
111
+ - 21dba89: Add `options.shake` to allow custom package names to be shaken.
112
+
113
+ ## 0.5.1
114
+
115
+ ### Patch Changes
116
+
117
+ - 6730c58: Support `@lynx-js/react` v0.101.0
118
+ - 63f40cc: Inject `globDynamicComponentEntry` for all main thread script.
119
+
120
+ | | Before | After |
121
+ | :---------: | :-------------: | :------------: |
122
+ | Main Bundle | Not defined | Defined(local) |
123
+ | Lazy Bundle | Defined(params) | Defined(local) |
124
+
125
+ ## 0.5.0
126
+
127
+ ### Minor Changes
128
+
129
+ - 587a782: **BRAKING CHANGE**: Require `@lynx-js/react` v0.100.0
130
+
131
+ ### Patch Changes
132
+
133
+ - 1938bb1: Add `transformPath` to loader option
134
+ - 1938bb1: Make peerDependencies of `@lynx-js/react` optional.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,4 @@
1
+ import type { RuntimeModule } from '@rspack/core';
2
+ type LynxProcessEvalResultRuntimeModule = new () => RuntimeModule;
3
+ export declare function createLynxProcessEvalResultRuntimeModule(webpack: typeof import('@rspack/core').rspack): LynxProcessEvalResultRuntimeModule;
4
+ export {};
@@ -0,0 +1,30 @@
1
+ import { RuntimeGlobals as LynxRuntimeGlobals } from '@lynx-js/webpack-runtime-globals';
2
+ export function createLynxProcessEvalResultRuntimeModule(webpack) {
3
+ return class LynxProcessEvalResultRuntimeModule extends webpack.RuntimeModule {
4
+ constructor() {
5
+ super('Lynx process eval result', webpack.RuntimeModule.STAGE_ATTACH);
6
+ }
7
+ generate() {
8
+ const chunk = this.chunk;
9
+ const compilation = this.compilation;
10
+ if (!chunk || !compilation) {
11
+ return '';
12
+ }
13
+ return `
14
+ ${LynxRuntimeGlobals.lynxProcessEvalResult} = function (result, schema) {
15
+ var chunk = result(schema);
16
+ if (chunk.ids && chunk.modules) {
17
+ // We only deal with webpack chunk
18
+ ${webpack.RuntimeGlobals.externalInstallChunk}(chunk);
19
+ // TODO: sort with preOrderIndex. See: https://github.com/web-infra-dev/rspack/pull/8588
20
+ for (var moduleId in chunk.modules) {
21
+ ${webpack.RuntimeGlobals.require}(moduleId);
22
+ }
23
+ return chunk;
24
+ }
25
+ }
26
+ `;
27
+ }
28
+ };
29
+ }
30
+ //# sourceMappingURL=LynxProcessEvalResultRuntimeModule.js.map
@@ -0,0 +1,87 @@
1
+ import type { Compiler } from '@rspack/core';
2
+ import { LAYERS } from './layer.js';
3
+ /**
4
+ * The options for ReactWebpackPlugin
5
+ *
6
+ * @public
7
+ */
8
+ interface ReactWebpackPluginOptions {
9
+ /**
10
+ * {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.compat.disableCreateSelectorQueryIncompatibleWarning}
11
+ */
12
+ disableCreateSelectorQueryIncompatibleWarning?: boolean | undefined;
13
+ /**
14
+ * {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.firstScreenSyncTiming}
15
+ */
16
+ firstScreenSyncTiming?: 'immediately' | 'jsReady';
17
+ /**
18
+ * The chunk names to be considered as main thread chunks.
19
+ */
20
+ mainThreadChunks?: string[] | undefined;
21
+ }
22
+ /**
23
+ * ReactWebpackPlugin allows using ReactLynx with webpack
24
+ *
25
+ * @example
26
+ * ```js
27
+ * // webpack.config.js
28
+ * import { ReactWebpackPlugin } from '@lynx-js/react-webpack-plugin'
29
+ * export default {
30
+ * plugins: [new ReactWebpackPlugin()],
31
+ * }
32
+ * ```
33
+ *
34
+ * @public
35
+ */
36
+ declare class ReactWebpackPlugin {
37
+ #private;
38
+ private readonly options?;
39
+ /**
40
+ * The loaders for ReactLynx.
41
+ *
42
+ * @remarks
43
+ * Note that this loader will only transform JSX/TSX to valid JavaScript.
44
+ * For `.tsx` files, the type annotations would not be eliminated.
45
+ * You should use `babel-loader` or `swc-loader` to load TypeScript files.
46
+ *
47
+ * @example
48
+ * ```js
49
+ * // webpack.config.js
50
+ * import { ReactWebpackPlugin, LAYERS } from '@lynx-js/react-webpack-plugin'
51
+ * export default {
52
+ * module: {
53
+ * rules: [
54
+ * {
55
+ * test: /\.tsx?$/,
56
+ * layer: LAYERS.MAIN_THREAD,
57
+ * use: ['swc-loader', ReactWebpackPlugin.loaders.MAIN_THREAD]
58
+ * },
59
+ * {
60
+ * test: /\.tsx?$/,
61
+ * layer: LAYERS.BACKGROUND,
62
+ * use: ['swc-loader', ReactWebpackPlugin.loaders.BACKGROUND]
63
+ * },
64
+ * ],
65
+ * },
66
+ * plugins: [new ReactWebpackPlugin()],
67
+ * }
68
+ * ```
69
+ *
70
+ * @public
71
+ */
72
+ static loaders: Record<keyof typeof LAYERS, string>;
73
+ constructor(options?: ReactWebpackPluginOptions | undefined);
74
+ /**
75
+ * `defaultOptions` is the default options that the {@link ReactWebpackPlugin} uses.
76
+ *
77
+ * @public
78
+ */
79
+ static defaultOptions: Readonly<Required<ReactWebpackPluginOptions>>;
80
+ /**
81
+ * The entry point of a webpack plugin.
82
+ * @param compiler - the webpack compiler
83
+ */
84
+ apply(compiler: Compiler): void;
85
+ }
86
+ export { ReactWebpackPlugin as ReactWebpackPlugin };
87
+ export type { ReactWebpackPluginOptions };
@@ -0,0 +1,200 @@
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 * as fs from 'node:fs';
5
+ import { createRequire } from 'node:module';
6
+ import invariant from 'tiny-invariant';
7
+ import { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin';
8
+ import { RuntimeGlobals } from '@lynx-js/webpack-runtime-globals';
9
+ import { LAYERS } from './layer.js';
10
+ import { createLynxProcessEvalResultRuntimeModule } from './LynxProcessEvalResultRuntimeModule.js';
11
+ const require = createRequire(import.meta.url);
12
+ /**
13
+ * ReactWebpackPlugin allows using ReactLynx with webpack
14
+ *
15
+ * @example
16
+ * ```js
17
+ * // webpack.config.js
18
+ * import { ReactWebpackPlugin } from '@lynx-js/react-webpack-plugin'
19
+ * export default {
20
+ * plugins: [new ReactWebpackPlugin()],
21
+ * }
22
+ * ```
23
+ *
24
+ * @public
25
+ */
26
+ class ReactWebpackPlugin {
27
+ /**
28
+ * The loaders for ReactLynx.
29
+ *
30
+ * @remarks
31
+ * Note that this loader will only transform JSX/TSX to valid JavaScript.
32
+ * For `.tsx` files, the type annotations would not be eliminated.
33
+ * You should use `babel-loader` or `swc-loader` to load TypeScript files.
34
+ *
35
+ * @example
36
+ * ```js
37
+ * // webpack.config.js
38
+ * import { ReactWebpackPlugin, LAYERS } from '@lynx-js/react-webpack-plugin'
39
+ * export default {
40
+ * module: {
41
+ * rules: [
42
+ * {
43
+ * test: /\.tsx?$/,
44
+ * layer: LAYERS.MAIN_THREAD,
45
+ * use: ['swc-loader', ReactWebpackPlugin.loaders.MAIN_THREAD]
46
+ * },
47
+ * {
48
+ * test: /\.tsx?$/,
49
+ * layer: LAYERS.BACKGROUND,
50
+ * use: ['swc-loader', ReactWebpackPlugin.loaders.BACKGROUND]
51
+ * },
52
+ * ],
53
+ * },
54
+ * plugins: [new ReactWebpackPlugin()],
55
+ * }
56
+ * ```
57
+ *
58
+ * @public
59
+ */
60
+ static { this.loaders = {
61
+ BACKGROUND: require.resolve('../lib/loaders/background.js'),
62
+ MAIN_THREAD: require.resolve('../lib/loaders/main-thread.js'),
63
+ }; }
64
+ constructor(options) {
65
+ this.options = options;
66
+ }
67
+ /**
68
+ * `defaultOptions` is the default options that the {@link ReactWebpackPlugin} uses.
69
+ *
70
+ * @public
71
+ */
72
+ static { this.defaultOptions = Object
73
+ .freeze({
74
+ disableCreateSelectorQueryIncompatibleWarning: false,
75
+ firstScreenSyncTiming: 'immediately',
76
+ mainThreadChunks: [],
77
+ }); }
78
+ /**
79
+ * The entry point of a webpack plugin.
80
+ * @param compiler - the webpack compiler
81
+ */
82
+ apply(compiler) {
83
+ const options = Object.assign({}, ReactWebpackPlugin.defaultOptions, this.options);
84
+ const { BannerPlugin, DefinePlugin, EnvironmentPlugin } = compiler.webpack;
85
+ new BannerPlugin({
86
+ // TODO: handle cases that do not have `'use strict'`
87
+ banner: `'use strict';var globDynamicComponentEntry=globDynamicComponentEntry||'__Card__';`,
88
+ raw: true,
89
+ test: options.mainThreadChunks,
90
+ }).apply(compiler);
91
+ new EnvironmentPlugin({
92
+ // Default values of null and undefined behave differently.
93
+ // Use undefined for variables that must be provided during bundling, or null if they are optional.
94
+ NODE_ENV: null,
95
+ DEBUG: null,
96
+ }).apply(compiler);
97
+ new DefinePlugin({
98
+ __DEV__: JSON.stringify(compiler.options.mode === 'development'),
99
+ // We enable profile by default in development.
100
+ // It can also be disabled by environment variable `REACT_PROFILE=false`
101
+ __PROFILE__: JSON.stringify(process.env['REACT_PROFILE'] ?? compiler.options.mode === 'development'),
102
+ // TODO: config
103
+ __EXTRACT_STR__: JSON.stringify(false),
104
+ __FIRST_SCREEN_SYNC_TIMING__: JSON.stringify(options.firstScreenSyncTiming),
105
+ __DISABLE_CREATE_SELECTOR_QUERY_INCOMPATIBLE_WARNING__: JSON.stringify(options.disableCreateSelectorQueryIncompatibleWarning),
106
+ }).apply(compiler);
107
+ compiler.hooks.thisCompilation.tap(this.constructor.name, compilation => {
108
+ const onceForChunkSet = new WeakSet();
109
+ compilation.hooks.runtimeRequirementInTree.for(compiler.webpack.RuntimeGlobals.ensureChunkHandlers).tap('ReactWebpackPlugin', (_, runtimeRequirements) => {
110
+ runtimeRequirements.add(RuntimeGlobals.lynxProcessEvalResult);
111
+ });
112
+ compilation.hooks.runtimeRequirementInTree.for(RuntimeGlobals.lynxProcessEvalResult).tap('ReactWebpackPlugin', (chunk) => {
113
+ if (onceForChunkSet.has(chunk)) {
114
+ return;
115
+ }
116
+ onceForChunkSet.add(chunk);
117
+ if (chunk.name?.includes(':background')) {
118
+ return;
119
+ }
120
+ const LynxProcessEvalResultRuntimeModule = createLynxProcessEvalResultRuntimeModule(compiler.webpack);
121
+ compilation.addRuntimeModule(chunk, new LynxProcessEvalResultRuntimeModule());
122
+ });
123
+ compilation.hooks.processAssets.tap({
124
+ name: this.constructor.name,
125
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
126
+ }, () => {
127
+ for (const name of options.mainThreadChunks ?? []) {
128
+ this.#updateMainThreadInfo(compilation, name);
129
+ }
130
+ compilation.chunkGroups
131
+ // Async ChunkGroups
132
+ .filter(cg => !cg.isInitial())
133
+ // MainThread ChunkGroups
134
+ .filter(cg => cg.origins.every(origin => origin.module?.layer === LAYERS.MAIN_THREAD))
135
+ .forEach(cg => {
136
+ const files = cg.getFiles();
137
+ files
138
+ .filter(name => name.endsWith('.js'))
139
+ .forEach(name => this.#updateMainThreadInfo(compilation, name));
140
+ });
141
+ });
142
+ // TODO: replace LynxTemplatePlugin types with Rspack
143
+ // @ts-expect-error Rspack x Webpack compilation not match
144
+ const hooks = LynxTemplatePlugin.getLynxTemplatePluginHooks(compilation);
145
+ const { RawSource, ConcatSource } = compiler.webpack.sources;
146
+ hooks.beforeEncode.tap(this.constructor.name, (args) => {
147
+ const lepusCode = args.encodeData.lepusCode;
148
+ if (lepusCode.root?.source.source().toString()?.includes('registerWorkletInternal')) {
149
+ const path = compiler.options.mode === 'development'
150
+ ? '@lynx-js/react/worklet-dev-runtime'
151
+ : '@lynx-js/react/worklet-runtime';
152
+ const runtimeFile = require.resolve(path);
153
+ lepusCode.chunks.push({
154
+ name: 'worklet-runtime',
155
+ source: new RawSource(fs.readFileSync(runtimeFile, 'utf8')),
156
+ info: {
157
+ ['lynx:main-thread']: true,
158
+ },
159
+ });
160
+ }
161
+ return args;
162
+ });
163
+ // Inject `module.exports` for async main-thread chunks
164
+ hooks.beforeEncode.tap(this.constructor.name, (args) => {
165
+ const { encodeData } = args;
166
+ // A lazy bundle may not have main-thread code
167
+ if (!encodeData.lepusCode.root) {
168
+ return args;
169
+ }
170
+ if (encodeData.sourceContent.appType === 'card') {
171
+ return args;
172
+ }
173
+ // We inject `module.exports` for each async template.
174
+ compilation.updateAsset(encodeData.lepusCode.root.name, (old) => new ConcatSource(`\
175
+ (function (globDynamicComponentEntry) {
176
+ const module = { exports: {} }
177
+ const exports = module.exports
178
+ `, old, `\
179
+ return module.exports
180
+ })`));
181
+ return args;
182
+ });
183
+ // The react-transform will add `-${LAYER}` to the webpackChunkName.
184
+ // We replace it with an empty string here to make sure main-thread & background chunk match.
185
+ hooks.asyncChunkName.tap(this.constructor.name, (chunkName) => chunkName
186
+ ?.replaceAll(`-${LAYERS.BACKGROUND}`, '')
187
+ ?.replaceAll(`-${LAYERS.MAIN_THREAD}`, ''));
188
+ });
189
+ }
190
+ #updateMainThreadInfo(compilation, name) {
191
+ const asset = compilation.getAsset(name);
192
+ invariant(asset, `Should have main thread asset ${name}`);
193
+ compilation.updateAsset(asset.name, asset.source, {
194
+ ...asset.info,
195
+ 'lynx:main-thread': true,
196
+ });
197
+ }
198
+ }
199
+ export { ReactWebpackPlugin as ReactWebpackPlugin };
200
+ //# sourceMappingURL=ReactWebpackPlugin.js.map
package/lib/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * A webpack plugin to integrate webpack with ReactLynx.
5
+ */
6
+ export { ReactWebpackPlugin } from './ReactWebpackPlugin.js';
7
+ export type { ReactWebpackPluginOptions } from './ReactWebpackPlugin.js';
8
+ export { LAYERS } from './layer.js';
9
+ export type { ReactLoaderOptions } from './loaders/options.js';
package/lib/index.js ADDED
@@ -0,0 +1,11 @@
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
+ /**
5
+ * @packageDocumentation
6
+ *
7
+ * A webpack plugin to integrate webpack with ReactLynx.
8
+ */
9
+ export { ReactWebpackPlugin } from './ReactWebpackPlugin.js';
10
+ export { LAYERS } from './layer.js';
11
+ //# sourceMappingURL=index.js.map
package/lib/layer.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare const LAYERS: {
2
+ readonly BACKGROUND: "react:background";
3
+ readonly MAIN_THREAD: "react:main-thread";
4
+ };
package/lib/layer.js ADDED
@@ -0,0 +1,8 @@
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
+ export const LAYERS = {
5
+ BACKGROUND: 'react:background',
6
+ MAIN_THREAD: 'react:main-thread',
7
+ };
8
+ //# sourceMappingURL=layer.js.map
@@ -0,0 +1,4 @@
1
+ import type { LoaderContext } from '@rspack/core';
2
+ import type { ReactLoaderOptions } from './options.js';
3
+ declare function backgroundLoader(this: LoaderContext<ReactLoaderOptions>, content: string): void;
4
+ export default backgroundLoader;
@@ -0,0 +1,72 @@
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 { getBackgroundTransformOptions } from './options.js';
6
+ function backgroundLoader(content) {
7
+ const require = createRequire(import.meta.url);
8
+ const { transformPath = '@lynx-js/react/transform' } = this.getOptions();
9
+ const { transformReactLynxSync } = require(transformPath);
10
+ const result = transformReactLynxSync(content, getBackgroundTransformOptions.call(this));
11
+ if (result.errors.length > 0) {
12
+ for (const error of result.errors) {
13
+ if (this.experiments?.emitDiagnostic) {
14
+ // Rspack with `emitDiagnostic` API
15
+ try {
16
+ this.experiments.emitDiagnostic({
17
+ message: error.text,
18
+ sourceCode: content,
19
+ location: {
20
+ line: error.location?.line ?? 1,
21
+ column: error.location?.column ?? 0,
22
+ length: error.location?.length ?? 0,
23
+ text: error.text ?? '',
24
+ },
25
+ severity: 'error',
26
+ });
27
+ }
28
+ catch {
29
+ // Rspack may throw on invalid line & column when containing UTF-8.
30
+ // We catch it up here.
31
+ this.emitError(new Error(error.text));
32
+ }
33
+ }
34
+ else {
35
+ // Webpack or legacy Rspack
36
+ this.emitError(new Error(error.text));
37
+ }
38
+ }
39
+ this.callback(new Error('react-transform failed'));
40
+ return;
41
+ }
42
+ for (const warning of result.warnings) {
43
+ if (this.experiments?.emitDiagnostic) {
44
+ // Rspack with `emitDiagnostic` API
45
+ try {
46
+ this.experiments.emitDiagnostic({
47
+ message: warning.text,
48
+ sourceCode: content,
49
+ location: {
50
+ line: warning.location?.line ?? 1,
51
+ column: warning.location?.column ?? 0,
52
+ length: warning.location?.length ?? 0,
53
+ text: warning.text ?? '',
54
+ },
55
+ severity: 'warning',
56
+ });
57
+ }
58
+ catch {
59
+ // Rspack may throw on invalid line & column when containing UTF-8.
60
+ // We catch it up here.
61
+ this.emitWarning(new Error(warning.text));
62
+ }
63
+ }
64
+ else {
65
+ // Webpack or legacy Rspack
66
+ this.emitWarning(new Error(warning.text));
67
+ }
68
+ }
69
+ this.callback(null, result.code, result.map);
70
+ }
71
+ export default backgroundLoader;
72
+ //# sourceMappingURL=background.js.map
@@ -0,0 +1,4 @@
1
+ import type { LoaderContext } from '@rspack/core';
2
+ import type { ReactLoaderOptions } from './options.js';
3
+ declare function mainThreadLoader(this: LoaderContext<ReactLoaderOptions>, content: string): void;
4
+ export default mainThreadLoader;
@@ -0,0 +1,86 @@
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 { getMainThreadTransformOptions } from './options.js';
6
+ function mainThreadLoader(content) {
7
+ const require = createRequire(import.meta.url);
8
+ const { transformPath = '@lynx-js/react/transform' } = this.getOptions();
9
+ const { transformReactLynxSync } = require(transformPath);
10
+ const result = transformReactLynxSync(content, getMainThreadTransformOptions.call(this));
11
+ if (result.errors.length > 0) {
12
+ for (const error of result.errors) {
13
+ if (this.experiments?.emitDiagnostic) {
14
+ // Rspack with `emitDiagnostic` API
15
+ try {
16
+ this.experiments.emitDiagnostic({
17
+ message: error.text,
18
+ sourceCode: content,
19
+ location: {
20
+ line: error.location?.line ?? 1,
21
+ column: error.location?.column ?? 0,
22
+ length: error.location?.length ?? 0,
23
+ text: error.text ?? '',
24
+ },
25
+ severity: 'error',
26
+ });
27
+ }
28
+ catch {
29
+ // Rspack may throw on invalid line & column when containing UTF-8.
30
+ // We catch it up here.
31
+ this.emitError(new Error(error.text));
32
+ }
33
+ }
34
+ else {
35
+ // Webpack or legacy Rspack
36
+ this.emitError(new Error(error.text));
37
+ }
38
+ }
39
+ this.callback(new Error('react-transform failed'));
40
+ return;
41
+ }
42
+ for (const warning of result.warnings) {
43
+ if (this.experiments?.emitDiagnostic) {
44
+ // Rspack with `emitDiagnostic` API
45
+ try {
46
+ this.experiments.emitDiagnostic({
47
+ message: warning.text,
48
+ sourceCode: content,
49
+ location: {
50
+ line: warning.location?.line ?? 1,
51
+ column: warning.location?.column ?? 0,
52
+ length: warning.location?.length ?? 0,
53
+ text: warning.text ?? '',
54
+ },
55
+ severity: 'warning',
56
+ });
57
+ }
58
+ catch {
59
+ // Rspack may throw on invalid line & column when containing UTF-8.
60
+ // We catch it up here.
61
+ this.emitWarning(new Error(warning.text));
62
+ }
63
+ }
64
+ else {
65
+ // Webpack or legacy Rspack
66
+ this.emitWarning(new Error(warning.text));
67
+ }
68
+ }
69
+ this.callback(null, result.code + (this.hot
70
+ // TODO: temporary fix LEPUS error `$RefreshReg$ is not defined`
71
+ // should make react-refresh transform in `react-transform`.
72
+ ? `\
73
+ // noop fns to prevent runtime errors during initialization
74
+ if (typeof globalThis !== "undefined") {
75
+ globalThis.$RefreshReg$ = function () {};
76
+ globalThis.$RefreshSig$ = function () {
77
+ return function(type) {
78
+ return type;
79
+ };
80
+ };
81
+ }
82
+ `
83
+ : ''), result.map);
84
+ }
85
+ export default mainThreadLoader;
86
+ //# sourceMappingURL=main-thread.js.map
@@ -0,0 +1,38 @@
1
+ import type { LoaderContext } from '@rspack/core';
2
+ import type { CompatVisitorConfig, DefineDceVisitorConfig, JsxTransformerConfig, ShakeVisitorConfig, TransformNodiffOptions } from '@lynx-js/react/transform';
3
+ /**
4
+ * The options of the ReactLynx plugin.
5
+ * @public
6
+ */
7
+ export interface ReactLoaderOptions {
8
+ /**
9
+ * {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.compat}
10
+ */
11
+ compat?: CompatVisitorConfig | undefined;
12
+ /**
13
+ * {@inheritdoc @lynx-js/template-webpack-plugin#LynxTemplatePluginOptions.enableRemoveCSSScope}
14
+ */
15
+ enableRemoveCSSScope?: boolean | undefined;
16
+ /**
17
+ * {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.jsx}
18
+ */
19
+ jsx?: JsxTransformerConfig | undefined;
20
+ /**
21
+ * Enable the Fast Refresh for ReactLynx.
22
+ */
23
+ refresh?: boolean | undefined;
24
+ /**
25
+ * How main-thread code will be shaken.
26
+ */
27
+ shake?: ShakeVisitorConfig | undefined;
28
+ /**
29
+ * Like `define` in various bundlers, but this one happens at transform time, and a DCE pass will be performed.
30
+ */
31
+ defineDCE?: DefineDceVisitorConfig | undefined;
32
+ /**
33
+ * Generate inline source content in source-map.
34
+ */
35
+ inlineSourcesContent?: boolean | undefined;
36
+ }
37
+ export declare function getMainThreadTransformOptions(this: LoaderContext<ReactLoaderOptions>): TransformNodiffOptions;
38
+ export declare function getBackgroundTransformOptions(this: LoaderContext<ReactLoaderOptions>): TransformNodiffOptions;
@@ -0,0 +1,222 @@
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 path from 'node:path';
5
+ import { LAYERS } from '../layer.js';
6
+ const PLUGIN_NAME = 'react:webpack';
7
+ const JSX_IMPORT_SOURCE = {
8
+ MAIN_THREAD: '@lynx-js/react/lepus',
9
+ BACKGROUND: '@lynx-js/react',
10
+ };
11
+ const PUBLIC_RUNTIME_PKG = '@lynx-js/react';
12
+ const RUNTIME_PKG = '@lynx-js/react/internal';
13
+ const OLD_RUNTIME_PKG = '@lynx-js/react-runtime';
14
+ const COMPONENT_PKG = '@lynx-js/react-components';
15
+ function getCommonOptions() {
16
+ const filename = path.relative(this.rootContext, this.resourcePath);
17
+ const { compat, enableRemoveCSSScope, inlineSourcesContent, isDynamicComponent, defineDCE = { define: {} }, } = this.getOptions();
18
+ const syntax = (/\.[mc]?tsx?$/.exec(this.resourcePath))
19
+ ? 'typescript'
20
+ : 'ecmascript';
21
+ // is '.ts' (one of '.js', '.jsx', '.ts', '.tsx')
22
+ const isTS = /\.[mc]?ts$/.exec(this.resourcePath);
23
+ const commonOptions = {
24
+ // We need to set `mode: 'development'` for HMR to work
25
+ mode: this.hot ? 'development' : 'production',
26
+ compat: typeof compat === 'object'
27
+ ? {
28
+ target: 'MIXED',
29
+ addComponentElement: compat?.addComponentElement ?? false,
30
+ additionalComponentAttributes: compat?.additionalComponentAttributes
31
+ ?? [],
32
+ componentsPkg: compat?.componentsPkg ?? [COMPONENT_PKG],
33
+ disableDeprecatedWarning: compat?.disableDeprecatedWarning ?? false,
34
+ newRuntimePkg: compat?.newRuntimePkg ?? PUBLIC_RUNTIME_PKG,
35
+ oldRuntimePkg: compat?.oldRuntimePkg ?? [OLD_RUNTIME_PKG],
36
+ simplifyCtorLikeReactLynx2: compat?.simplifyCtorLikeReactLynx2 ?? false,
37
+ // NOTE: never pass '' (empty string) as default value
38
+ ...(typeof compat?.removeComponentAttrRegex === 'string' && {
39
+ removeComponentAttrRegex: compat?.removeComponentAttrRegex,
40
+ }),
41
+ darkMode: false,
42
+ }
43
+ : false,
44
+ pluginName: PLUGIN_NAME,
45
+ // Ensure that swc get a full absolute path so that it will generate
46
+ // absolute path in the `source` param of `jsxDev(type, props, key, isStatic, source, self)`
47
+ filename: this.resourcePath,
48
+ cssScope: {
49
+ mode: getCSSScopeMode(enableRemoveCSSScope),
50
+ filename,
51
+ },
52
+ // Ensure that Webpack will get a full absolute path in the sourcemap
53
+ // so that it can properly map the module back to its internal cached
54
+ // modules.
55
+ // See: https://github.com/babel/babel-loader/blob/d85f4207947b618e040fb6a70afe9be9e1fd87d7/src/index.js#L135C1-L137C16
56
+ // See: https://github.com/swc-project/pkgs/blob/d096fdc1ac372ac045894bdda3180ef99bbcbe33/packages/swc-loader/src/index.js#L42
57
+ sourceFileName: this.resourcePath,
58
+ sourcemap: this.sourceMap,
59
+ sourceMapColumns: this.sourceMap && !this.hot,
60
+ inlineSourcesContent: inlineSourcesContent ?? !this.hot,
61
+ snapshot: {
62
+ // TODO: config
63
+ preserveJsx: false,
64
+ target: 'MIXED',
65
+ runtimePkg: RUNTIME_PKG,
66
+ filename,
67
+ isDynamicComponent: isDynamicComponent ?? false,
68
+ },
69
+ syntaxConfig: JSON.stringify({
70
+ syntax,
71
+ decorators: true,
72
+ // Only '.ts' conflicts with tsx, both '.js' and '.jsx' can be handled by tsx.
73
+ tsx: !isTS,
74
+ // `.js` is not conflicts with jsx, always pass true
75
+ jsx: true,
76
+ }),
77
+ // TODO: config
78
+ worklet: {
79
+ filename: filename,
80
+ runtimePkg: RUNTIME_PKG,
81
+ target: 'MIXED',
82
+ },
83
+ directiveDCE: false,
84
+ defineDCE,
85
+ refresh: false,
86
+ isModule: 'unknown',
87
+ };
88
+ return commonOptions;
89
+ }
90
+ export function getMainThreadTransformOptions() {
91
+ const commonOptions = getCommonOptions.call(this);
92
+ const { shake } = this.getOptions();
93
+ return {
94
+ ...commonOptions,
95
+ compat: typeof commonOptions.compat === 'object'
96
+ ? {
97
+ ...commonOptions.compat,
98
+ target: 'LEPUS',
99
+ }
100
+ : false,
101
+ snapshot: {
102
+ ...commonOptions.snapshot,
103
+ jsxImportSource: JSX_IMPORT_SOURCE.MAIN_THREAD,
104
+ target: 'LEPUS',
105
+ },
106
+ dynamicImport: {
107
+ layer: LAYERS.MAIN_THREAD,
108
+ runtimePkg: RUNTIME_PKG,
109
+ },
110
+ defineDCE: {
111
+ define: {
112
+ ...commonOptions.defineDCE?.define,
113
+ // DO NOT put lynx-speedy's defines here,
114
+ // we want to handle as few as possible defines here.
115
+ __LEPUS__: 'true',
116
+ __MAIN_THREAD__: 'true',
117
+ __JS__: 'false',
118
+ __BACKGROUND__: 'false',
119
+ __REACTLYNX2__: 'false',
120
+ __REACTLYNX3__: 'true',
121
+ },
122
+ },
123
+ shake: {
124
+ // if shake is false, we will not shake anything
125
+ // if shake is true, we will use default config from HERE,
126
+ // so never pass true to shake to rust
127
+ pkgName: [
128
+ 'react',
129
+ PUBLIC_RUNTIME_PKG,
130
+ `${PUBLIC_RUNTIME_PKG}/legacy-react-runtime`,
131
+ RUNTIME_PKG,
132
+ ...typeof commonOptions.compat === 'object'
133
+ ? commonOptions.compat.oldRuntimePkg
134
+ : [],
135
+ ...(shake?.pkgName ?? []),
136
+ ],
137
+ retainProp: [
138
+ 'constructor',
139
+ 'render',
140
+ 'getDerivedStateFromProps',
141
+ 'state',
142
+ 'defaultDataProcessor',
143
+ 'dataProcessors',
144
+ 'contextType',
145
+ 'defaultProps',
146
+ ...(shake?.retainProp ?? []),
147
+ ],
148
+ removeCallParams: [
149
+ 'useEffect',
150
+ 'useLayoutEffect',
151
+ '__runInJS',
152
+ 'useLynxGlobalEventListener',
153
+ ...(shake?.removeCallParams ?? []),
154
+ ],
155
+ },
156
+ worklet: {
157
+ ...commonOptions.worklet,
158
+ target: 'LEPUS',
159
+ },
160
+ directiveDCE: {
161
+ target: 'LEPUS',
162
+ },
163
+ };
164
+ }
165
+ export function getBackgroundTransformOptions() {
166
+ const commonOptions = getCommonOptions.call(this);
167
+ return {
168
+ ...commonOptions,
169
+ compat: typeof commonOptions.compat === 'object'
170
+ ? {
171
+ ...commonOptions.compat,
172
+ target: 'JS',
173
+ }
174
+ : false,
175
+ dynamicImport: {
176
+ layer: LAYERS.BACKGROUND,
177
+ runtimePkg: RUNTIME_PKG,
178
+ },
179
+ snapshot: {
180
+ ...commonOptions.snapshot,
181
+ jsxImportSource: JSX_IMPORT_SOURCE.BACKGROUND,
182
+ target: this.hot
183
+ // Using `MIX` when HMR is enabled.
184
+ // This allows serializing the updated runtime code to Lepus using `Function.prototype.toString`.
185
+ ? 'MIXED'
186
+ : 'JS',
187
+ },
188
+ defineDCE: {
189
+ define: {
190
+ ...commonOptions.defineDCE?.define,
191
+ // DO NOT put lynx-speedy's defines here,
192
+ // we want to handle as few as possible defines here.
193
+ __LEPUS__: 'false',
194
+ __MAIN_THREAD__: 'false',
195
+ __JS__: 'true',
196
+ __BACKGROUND__: 'true',
197
+ __REACTLYNX2__: 'false',
198
+ __REACTLYNX3__: 'true',
199
+ },
200
+ },
201
+ shake: false,
202
+ worklet: {
203
+ ...commonOptions.worklet,
204
+ target: 'JS',
205
+ },
206
+ directiveDCE: {
207
+ target: 'JS',
208
+ },
209
+ };
210
+ }
211
+ function getCSSScopeMode(enableRemoveCSSScope) {
212
+ if (enableRemoveCSSScope === true) {
213
+ return 'none';
214
+ }
215
+ else if (enableRemoveCSSScope === false) {
216
+ return 'all';
217
+ }
218
+ else {
219
+ return 'modules';
220
+ }
221
+ }
222
+ //# sourceMappingURL=options.js.map
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@lynx-js/react-webpack-plugin",
3
+ "version": "0.6.6",
4
+ "description": "A webpack plugin for ReactLynx",
5
+ "keywords": [
6
+ "webpack",
7
+ "Lynx",
8
+ "ReactLynx"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/lynx-wg/lynx-stack.git",
13
+ "directory": "packages/webpack/react-webpack-plugin"
14
+ },
15
+ "license": "Apache-2.0",
16
+ "author": {
17
+ "name": "Qingyu Wang",
18
+ "email": "colinwang.0616@gmail.com"
19
+ },
20
+ "type": "module",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./lib/index.d.ts",
24
+ "default": "./lib/index.js"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "types": "./lib/index.d.ts",
29
+ "files": [
30
+ "lib",
31
+ "!lib/**/*.js.map",
32
+ "CHANGELOG.md",
33
+ "README.md"
34
+ ],
35
+ "dependencies": {
36
+ "tiny-invariant": "^1.3.3",
37
+ "@lynx-js/webpack-runtime-globals": "0.0.4"
38
+ },
39
+ "devDependencies": {
40
+ "@microsoft/api-extractor": "7.51.0",
41
+ "@rspack/core": "1.2.6",
42
+ "css-loader": "^7.1.2",
43
+ "swc-loader": "^0.2.6",
44
+ "webpack": "^5.98.0",
45
+ "@lynx-js/css-extract-webpack-plugin": "0.5.0",
46
+ "@lynx-js/react": "0.105.0",
47
+ "@lynx-js/template-webpack-plugin": "0.6.3",
48
+ "@lynx-js/test-tools": "0.0.0",
49
+ "@lynx-js/vitest-setup": "0.0.0"
50
+ },
51
+ "peerDependencies": {
52
+ "@lynx-js/react": "^0.103.0 || ^0.104.0 || ^0.105.0",
53
+ "@lynx-js/template-webpack-plugin": "^0.4.0 || ^0.5.0 || ^0.6.0"
54
+ },
55
+ "peerDependenciesMeta": {
56
+ "@lynx-js/react": {
57
+ "optional": true
58
+ }
59
+ },
60
+ "engines": {
61
+ "node": ">=18"
62
+ },
63
+ "scripts": {
64
+ "api-extractor": "api-extractor run --verbose",
65
+ "test": "pnpm -w run test --project webpack/react"
66
+ }
67
+ }