@lynx-js/react-rsbuild-plugin 0.19.1 → 0.20.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 +49 -0
- package/dist/index.js +116 -120
- package/package.json +22 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# @lynx-js/react-rsbuild-plugin
|
|
2
2
|
|
|
3
|
+
## 0.20.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- **BREAKING CHANGE**: Require `@lynx-js/rspeedy` `^0.17.0` in the plugins that read the build engine config through `Symbol.for('@lynx-js/rsbuild-plugin:config')`, since the engine that ships with `0.16` does not expose it. The plugins that do not touch the engine keep their existing range and add `^0.17.0` to it. ([#3682](https://github.com/lynx-family/lynx-stack/pull/3682))
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Do not apply the Lynx build engine again when `pluginLynx` is registered on an environment rather than globally, which silently replaced the options it was given. ([#3695](https://github.com/lynx-family/lynx-stack/pull/3695))
|
|
12
|
+
|
|
13
|
+
- Move runtime attribute-name configuration to the page-scoped `lynx` object and ([#3718](https://github.com/lynx-family/lynx-stack/pull/3718))
|
|
14
|
+
inject it from the host compilation through a standalone webpack plugin. Lazy
|
|
15
|
+
and external bundles reuse the host-injected configuration without applying
|
|
16
|
+
the plugin themselves. The runtime-config webpack plugin is published through
|
|
17
|
+
its own DSL-neutral package entry and accepts arbitrary runtime configuration
|
|
18
|
+
keys without depending on ReactLynx. The merged top-level configuration is
|
|
19
|
+
shallow-frozen to prevent accidental mutation after host initialization.
|
|
20
|
+
- Accept `DEBUG=lynx` (and `lynx:*`, `lynx:template`) for the Lynx debug output and intermediates. It is the recommended form now that the plugins also run under Rslib and Rsbuild; `DEBUG=rspeedy` keeps working. ([#3735](https://github.com/lynx-family/lynx-stack/pull/3735))
|
|
21
|
+
|
|
22
|
+
- Honor `splitChunks`, `performance.chunkSplit` and `output.sourceMap` when they are set on an environment. `pluginReactLynx` used to read them from the root of the config only when deciding whether to split chunks and whether to inline sources into source maps. ([#3768](https://github.com/lynx-family/lynx-stack/pull/3768))
|
|
23
|
+
|
|
24
|
+
- Skip the background runtime wrapper on any asset marked `lynx:main-thread` instead of matching filenames, and mark the main-thread assets of an external bundle by the layer of their modules, so a main-thread entry an external bundle names itself is no longer wrapped. ([#3751](https://github.com/lynx-family/lynx-stack/pull/3751))
|
|
25
|
+
|
|
26
|
+
- Declare the build host as an optional peer dependency. `@rsbuild/core` covers a plain Rsbuild build, and `@lynx-js/rspeedy` covers an Rspeedy one, so whichever host is installed is version-checked. ([#3678](https://github.com/lynx-family/lynx-stack/pull/3678))
|
|
27
|
+
|
|
28
|
+
- Add `performance` to the `pluginLynx` options, alongside `output`, and expose it on the config `pluginLynx` provides. Rspeedy maps its `performance.profile` onto it, so a plugin can read the option from the build engine instead of requiring Rspeedy to be the caller. `pluginReactLynx` reads it from there instead of requiring Rspeedy. ([#3691](https://github.com/lynx-family/lynx-stack/pull/3691))
|
|
29
|
+
|
|
30
|
+
- Honor `output.distPath.intermediate`. The Lynx build engine now resolves the intermediate directory, so the option is no longer ignored by the plugins that emit a Lynx bundle. ([#3676](https://github.com/lynx-family/lynx-stack/pull/3676))
|
|
31
|
+
|
|
32
|
+
- Accept `@lynx-js/react` 0.126, which ships Preact 11. ([#3450](https://github.com/lynx-family/lynx-stack/pull/3450))
|
|
33
|
+
|
|
34
|
+
- Apply the Lynx build engine to `rslib` builds: module resolution, SWC transforms, bundler target, output, minification (JS and CSS), source maps and debug metadata now match an application build. The plugins that load or serve a bundle stay off, since `rslib` assembles its own. ([#3696](https://github.com/lynx-family/lynx-stack/pull/3696))
|
|
35
|
+
|
|
36
|
+
- `pluginReactLynx` registers the encoders and the background runtime wrapper for every caller, and `WebEncodePlugin` routes the custom sections of a bundle without a root into the slots the web runtime reads. `@lynx-js/lynx-bundle-rslib-config` only sets the template plugin and the main-thread wrapper up now. ([#3744](https://github.com/lynx-family/lynx-stack/pull/3744))
|
|
37
|
+
|
|
38
|
+
- Expose `Symbol.for('LynxTemplatePlugin')` from `pluginLynx` instead of from each DSL plugin, so the plugins that tap the template hooks work with the build engine alone. ([#3675](https://github.com/lynx-family/lynx-stack/pull/3675))
|
|
39
|
+
|
|
40
|
+
- Skip the built-in `pluginLynx` when one is already applied, so a user who needs to configure the Lynx build engine can apply `pluginLynx` themselves and have their options win. `@lynx-js/rspeedy` becomes an optional peer dependency of `pluginReactLynx` and `pluginQRCode`. ([#3661](https://github.com/lynx-family/lynx-stack/pull/3661))
|
|
41
|
+
- Updated dependencies [[`643a52d`](https://github.com/lynx-family/lynx-stack/commit/643a52d9aefb327ca5a090cb052fd9b08cefbba6), [`76126fc`](https://github.com/lynx-family/lynx-stack/commit/76126fcad0f16e649c372d22c013e90ad88640df), [`b854dec`](https://github.com/lynx-family/lynx-stack/commit/b854dec62d48a09f60abc0632ba541bbdffda31f), [`c21cddd`](https://github.com/lynx-family/lynx-stack/commit/c21cddd0b75290330b6891f041db63ee5b28f492), [`f743e12`](https://github.com/lynx-family/lynx-stack/commit/f743e123e058d8f97720b1ce8c4a3d6601c8f7be), [`9bbfe5d`](https://github.com/lynx-family/lynx-stack/commit/9bbfe5d6e5367fbbaacc0129559e7b1d823038ad), [`5637926`](https://github.com/lynx-family/lynx-stack/commit/5637926c579bac5e9b78a02b982b1110cf4421d4), [`cdceffc`](https://github.com/lynx-family/lynx-stack/commit/cdceffc6f3fb9ac7b5ce1f48b7edb53c7788c057), [`6da3e18`](https://github.com/lynx-family/lynx-stack/commit/6da3e189f58637e14318782c176ed5970b59f75d), [`754ed35`](https://github.com/lynx-family/lynx-stack/commit/754ed35f8063c9333b75a7a7bbb264cb19c5cc51), [`5637926`](https://github.com/lynx-family/lynx-stack/commit/5637926c579bac5e9b78a02b982b1110cf4421d4), [`ab041b7`](https://github.com/lynx-family/lynx-stack/commit/ab041b72bc0d93e22f542b5963e221b6bd3f39e8), [`0a52438`](https://github.com/lynx-family/lynx-stack/commit/0a524389500421bb07e6a69366879e453d5d1d09), [`c6f971a`](https://github.com/lynx-family/lynx-stack/commit/c6f971a31fc0c54b98458c01f8c39a0828fe198c), [`0c47383`](https://github.com/lynx-family/lynx-stack/commit/0c4738342365ed4670ec659df5ede683e5aa2529), [`b3c6045`](https://github.com/lynx-family/lynx-stack/commit/b3c604544f84f1c600fb42468b05f7d73c120ad3), [`08a36e3`](https://github.com/lynx-family/lynx-stack/commit/08a36e39a5ba336946335d55a29efba1750e65ad), [`abab087`](https://github.com/lynx-family/lynx-stack/commit/abab087d0a4ce2e993c2417ce7bbf17e585ac972), [`32ba734`](https://github.com/lynx-family/lynx-stack/commit/32ba7347d1733eb4b2e19e95d7b7415ae78e23d2), [`7850e1e`](https://github.com/lynx-family/lynx-stack/commit/7850e1edb6f02ef2d332b756cd6e1a6ae6584368), [`3ab5ba3`](https://github.com/lynx-family/lynx-stack/commit/3ab5ba3fb738c368cfca6b6a5fc8c4ea323de124), [`eaefef6`](https://github.com/lynx-family/lynx-stack/commit/eaefef64d9874a8236d99b8abe17978d803a02da), [`e2ac811`](https://github.com/lynx-family/lynx-stack/commit/e2ac811c48535672bb14e4662f38dbebf0276167), [`0be26e9`](https://github.com/lynx-family/lynx-stack/commit/0be26e91d362041d1b0f568d15828d92f0ed2a6d), [`3d63331`](https://github.com/lynx-family/lynx-stack/commit/3d63331dc861bf3180f975ca54d4e7d9afd5eb70), [`32ba734`](https://github.com/lynx-family/lynx-stack/commit/32ba7347d1733eb4b2e19e95d7b7415ae78e23d2)]:
|
|
42
|
+
- @lynx-js/rsbuild-plugin@0.1.0
|
|
43
|
+
- @lynx-js/react-webpack-plugin@0.11.2
|
|
44
|
+
- @lynx-js/runtime-config-webpack-plugin@0.0.1
|
|
45
|
+
- @lynx-js/template-webpack-plugin@0.16.0
|
|
46
|
+
- @lynx-js/runtime-wrapper-webpack-plugin@0.2.4
|
|
47
|
+
- @lynx-js/react-alias-rsbuild-plugin@0.20.0
|
|
48
|
+
- @lynx-js/css-extract-webpack-plugin@0.11.0
|
|
49
|
+
- @lynx-js/use-sync-external-store@1.5.0
|
|
50
|
+
- @lynx-js/react-refresh-webpack-plugin@0.4.2
|
|
51
|
+
|
|
3
52
|
## 0.19.1
|
|
4
53
|
|
|
5
54
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { pluginReactAlias } from "@lynx-js/react-alias-rsbuild-plugin";
|
|
3
3
|
import { LAYERS, ReactWebpackPlugin } from "@lynx-js/react-webpack-plugin";
|
|
4
|
-
import {
|
|
5
|
-
import { PLUGIN_LYNX_NAME, pluginLynx } from "@lynx-js/rsbuild-plugin";
|
|
4
|
+
import { isPluginLynxRegistered, pluginLynx } from "@lynx-js/rsbuild-plugin";
|
|
6
5
|
import node_path from "node:path";
|
|
7
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { RuntimeConfigWebpackPlugin } from "@lynx-js/runtime-config-webpack-plugin";
|
|
8
8
|
import { RuntimeWrapperWebpackPlugin } from "@lynx-js/runtime-wrapper-webpack-plugin";
|
|
9
|
+
import { LynxEncodePlugin, LynxTemplatePlugin, WebEncodePlugin } from "@lynx-js/template-webpack-plugin";
|
|
9
10
|
import { ReactRefreshRspackPlugin } from "@lynx-js/react-refresh-webpack-plugin";
|
|
10
|
-
const S_PLUGIN_LYNX_APPLIED = Symbol.for('@lynx-js/rsbuild-plugin:applied');
|
|
11
11
|
function pluginAutoLynx() {
|
|
12
12
|
return {
|
|
13
13
|
name: 'lynx:react:auto-lynx',
|
|
14
14
|
async setup (api) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (api
|
|
18
|
-
Object.defineProperty(api.context, S_PLUGIN_LYNX_APPLIED, {
|
|
19
|
-
value: true
|
|
20
|
-
});
|
|
15
|
+
if ('rstest' === api.context.callerName) return;
|
|
16
|
+
const { environments } = api.getRsbuildConfig('original');
|
|
17
|
+
if (isPluginLynxRegistered(api, Object.keys(environments ?? {}))) return;
|
|
21
18
|
const original = api.getRsbuildConfig('original');
|
|
22
19
|
for (const plugin of pluginLynx()){
|
|
23
20
|
const { action } = api.context;
|
|
@@ -148,54 +145,94 @@ function meetsMinEngineVersion(actual, min) {
|
|
|
148
145
|
}
|
|
149
146
|
return true;
|
|
150
147
|
}
|
|
148
|
+
const isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj);
|
|
149
|
+
function getUserSplitChunks(config, environment) {
|
|
150
|
+
const scoped = config.environments?.[environment];
|
|
151
|
+
return {
|
|
152
|
+
splitChunks: scoped?.splitChunks ?? config.splitChunks,
|
|
153
|
+
chunkSplitStrategy: scoped?.performance?.chunkSplit?.strategy ?? config.performance?.chunkSplit?.strategy
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const applySplitChunksRule = (api)=>{
|
|
157
|
+
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig })=>{
|
|
158
|
+
const { splitChunks, chunkSplitStrategy } = getUserSplitChunks(api.getRsbuildConfig('original'), name);
|
|
159
|
+
if (void 0 === splitChunks && ('all-in-one' === chunkSplitStrategy || !chunkSplitStrategy)) return mergeEnvironmentConfig(config, {
|
|
160
|
+
splitChunks: false
|
|
161
|
+
});
|
|
162
|
+
return config;
|
|
163
|
+
});
|
|
164
|
+
api.modifyBundlerChain((chain, { environment })=>{
|
|
165
|
+
const { config } = environment;
|
|
166
|
+
const { splitChunks, chunkSplitStrategy } = getUserSplitChunks(api.getRsbuildConfig('original'), environment.name);
|
|
167
|
+
const isSplitByExperience = void 0 === splitChunks ? 'split-by-experience' === chunkSplitStrategy : isPlainObject(config.splitChunks) && 'default' === config.splitChunks.preset;
|
|
168
|
+
if (!isSplitByExperience) return;
|
|
169
|
+
const currentConfig = chain.optimization.splitChunks.values();
|
|
170
|
+
if (!isPlainObject(currentConfig)) return;
|
|
171
|
+
const extraGroups = {};
|
|
172
|
+
extraGroups['preact'] = {
|
|
173
|
+
name: 'lib-preact',
|
|
174
|
+
test: /node_modules[\\/](.*?[\\/])?(?:(?:internal-)?preact|(?:internal-)?preact[\\/]compat|(?:internal-)?preact[\\/]hooks|(?:internal-)?preact[\\/]jsx-runtime)[\\/]/,
|
|
175
|
+
priority: 0
|
|
176
|
+
};
|
|
177
|
+
chain.optimization.splitChunks({
|
|
178
|
+
...currentConfig,
|
|
179
|
+
cacheGroups: {
|
|
180
|
+
...currentConfig.cacheGroups,
|
|
181
|
+
...extraGroups
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
api.modifyRspackConfig((rspackConfig)=>{
|
|
186
|
+
if (!rspackConfig.optimization) return rspackConfig;
|
|
187
|
+
if (!rspackConfig.optimization.splitChunks) return rspackConfig;
|
|
188
|
+
rspackConfig.optimization.splitChunks.chunks = function(chunk) {
|
|
189
|
+
return !chunk.name?.includes('__main-thread');
|
|
190
|
+
};
|
|
191
|
+
return rspackConfig;
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
const S_LYNX_CONFIG = Symbol.for('@lynx-js/rsbuild-plugin:config');
|
|
151
195
|
const PLUGIN_NAME_REACT = 'lynx:react';
|
|
196
|
+
const PLUGIN_NAME_RUNTIME_CONFIG = 'lynx:runtime-config';
|
|
152
197
|
const PLUGIN_NAME_TEMPLATE = 'lynx:template';
|
|
153
198
|
const PLUGIN_NAME_RUNTIME_WRAPPER = 'lynx:runtime-wrapper';
|
|
154
199
|
const PLUGIN_NAME_WEB = 'lynx:web';
|
|
155
|
-
const DEFAULT_DIST_PATH_INTERMEDIATE = '.rspeedy';
|
|
156
200
|
const DEFAULT_FILENAME_HASH = '.[contenthash:8]';
|
|
157
201
|
const EMPTY_HASH = '';
|
|
158
202
|
function applyEntry(api, options) {
|
|
159
203
|
const { compat, customCSSInheritanceList, debugInfoOutside, defaultDisplayLinear, enableAccessibilityElement, enableCSSInheritance, enableCSSInvalidation, enableCSSSelector, enableNewGesture, enableRemoveCSSScope, firstScreenSyncTiming, globalPropsMode, enableSSR, removeDescendantSelectorScope, targetSdkVersion, extractStr: originalExtractStr, experimental_isLazyBundle, experimental_transformBuiltinAttributeNames } = options;
|
|
160
204
|
const lazyBundleFetcher = resolveLazyBundleFetcher(targetSdkVersion);
|
|
205
|
+
const runtimeConfig = {};
|
|
206
|
+
if (experimental_transformBuiltinAttributeNames) runtimeConfig['transformBuiltinAttributeNames'] = experimental_transformBuiltinAttributeNames;
|
|
161
207
|
api.modifyBundlerChain(async (chain, { environment, isDev, isProd })=>{
|
|
162
208
|
const mainThreadChunks = [];
|
|
163
209
|
const entryPairs = [];
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
const chunkSplitStrategy = userConfig.performance?.chunkSplit?.strategy;
|
|
167
|
-
const enableChunkSplitting = void 0 === userConfig.splitChunks ? chunkSplitStrategy ? 'all-in-one' !== chunkSplitStrategy : false !== rsbuildConfig.splitChunks : false !== rsbuildConfig.splitChunks;
|
|
210
|
+
const { splitChunks, chunkSplitStrategy } = getUserSplitChunks(api.getRsbuildConfig('original'), environment.name);
|
|
211
|
+
const enableChunkSplitting = void 0 === splitChunks ? chunkSplitStrategy ? 'all-in-one' !== chunkSplitStrategy : false !== environment.config.splitChunks : false !== environment.config.splitChunks;
|
|
168
212
|
const rspeedyConfig = 'rspeedy' === api.context.callerName ? api.useExposed(Symbol.for('rspeedy.api'))?.config : void 0;
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
|
|
213
|
+
const lynxConfig = api.useExposed(S_LYNX_CONFIG);
|
|
214
|
+
const isLynx = 'lynx' === environment.name || environment.name.startsWith('lynx-');
|
|
215
|
+
const isWeb = 'web' === environment.name || environment.name.startsWith('web-');
|
|
216
|
+
const isApplication = 'rslib' !== api.context.callerName && 'rstest' !== api.context.callerName;
|
|
217
|
+
if (isApplication) {
|
|
218
|
+
if (!lynxConfig) throw new Error('No Lynx config exposed. `pluginLynx` has to be applied for the Lynx build engine to be configured.');
|
|
172
219
|
const entries = chain.entryPoints.entries() ?? {};
|
|
173
|
-
const isLynx = 'lynx' === environment.name || environment.name.startsWith('lynx-');
|
|
174
|
-
const isWeb = 'web' === environment.name || environment.name.startsWith('web-');
|
|
175
220
|
const { hmr, liveReload } = environment.config.dev ?? {};
|
|
176
221
|
const enabledHMR = isDev && false !== hmr;
|
|
177
222
|
const enabledLiveReload = isDev && false !== liveReload;
|
|
178
223
|
chain.entryPoints.clear();
|
|
179
224
|
Object.entries(entries).forEach(([entryName, entryPoint])=>{
|
|
180
225
|
const { imports } = getChunks(entryName, entryPoint.values());
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
platform: environment.name
|
|
189
|
-
});
|
|
190
|
-
lazyBundleFilename = bundleFilename({
|
|
191
|
-
lazyBundle: true,
|
|
192
|
-
entryName: void 0,
|
|
193
|
-
platform: environment.name
|
|
194
|
-
}).replaceAll('[platform]', environment.name);
|
|
195
|
-
} else templateFilename = bundleFilename ?? '[name].[platform].bundle';
|
|
226
|
+
const templateFilename = lynxConfig.resolveBundleFilename({
|
|
227
|
+
entryName,
|
|
228
|
+
platform: environment.name
|
|
229
|
+
});
|
|
230
|
+
const lazyBundleFilename = lynxConfig.resolveLazyBundleFilename({
|
|
231
|
+
platform: environment.name
|
|
232
|
+
});
|
|
196
233
|
const mainThreadEntry = `${entryName}__main-thread`;
|
|
197
|
-
const mainThreadName = node_path.posix.join(isLynx ?
|
|
198
|
-
const backgroundName = node_path.posix.join(isLynx ?
|
|
234
|
+
const mainThreadName = node_path.posix.join(isLynx ? lynxConfig.resolveIntermediateDir() : '', `${entryName}/main-thread.js`);
|
|
235
|
+
const backgroundName = node_path.posix.join(isLynx ? lynxConfig.resolveIntermediateDir() : '', getBackgroundFilename(entryName, environment.config, isProd, experimental_isLazyBundle));
|
|
199
236
|
const backgroundEntry = entryName;
|
|
200
237
|
mainThreadChunks.push(mainThreadName);
|
|
201
238
|
entryPairs.push({
|
|
@@ -236,11 +273,13 @@ function applyEntry(api, options) {
|
|
|
236
273
|
mainThreadEntry,
|
|
237
274
|
backgroundEntry
|
|
238
275
|
],
|
|
239
|
-
filename: templateFilename
|
|
276
|
+
filename: templateFilename,
|
|
240
277
|
...lazyBundleFilename ? {
|
|
241
278
|
lazyBundleFilename
|
|
242
279
|
} : {},
|
|
243
|
-
intermediate:
|
|
280
|
+
intermediate: lynxConfig.resolveIntermediateDir({
|
|
281
|
+
entryName
|
|
282
|
+
}),
|
|
244
283
|
customCSSInheritanceList,
|
|
245
284
|
debugInfoOutside,
|
|
246
285
|
defaultDisplayLinear,
|
|
@@ -259,35 +298,34 @@ function applyEntry(api, options) {
|
|
|
259
298
|
}
|
|
260
299
|
]).end();
|
|
261
300
|
});
|
|
262
|
-
if (isLynx) {
|
|
263
|
-
let inlineScripts;
|
|
264
|
-
inlineScripts = experimental_isLazyBundle ? true : environment.config.output?.inlineScripts ?? !enableChunkSplitting;
|
|
265
|
-
chain.plugin(PLUGIN_NAME_RUNTIME_WRAPPER).use(RuntimeWrapperWebpackPlugin, [
|
|
266
|
-
{
|
|
267
|
-
injectVars (vars) {
|
|
268
|
-
const UNUSED_VARS = new Set([
|
|
269
|
-
'Card',
|
|
270
|
-
'Component',
|
|
271
|
-
'ReactLynx',
|
|
272
|
-
'Behavior'
|
|
273
|
-
]);
|
|
274
|
-
return vars.map((name)=>{
|
|
275
|
-
if (UNUSED_VARS.has(name)) return `__${name}`;
|
|
276
|
-
return name;
|
|
277
|
-
});
|
|
278
|
-
},
|
|
279
|
-
targetSdkVersion,
|
|
280
|
-
test: /^(?!.*main-thread(?:\.[A-Fa-f0-9]*)?\.js$).*\.js$/,
|
|
281
|
-
experimental_isLazyBundle
|
|
282
|
-
}
|
|
283
|
-
]).end().plugin(`${LynxEncodePlugin.name}`).use(LynxEncodePlugin, [
|
|
284
|
-
{
|
|
285
|
-
inlineScripts
|
|
286
|
-
}
|
|
287
|
-
]).end();
|
|
288
|
-
}
|
|
289
|
-
if (isWeb) chain.plugin(PLUGIN_NAME_WEB).use(WebEncodePlugin, []).end();
|
|
290
301
|
}
|
|
302
|
+
if (isLynx) {
|
|
303
|
+
let inlineScripts;
|
|
304
|
+
inlineScripts = experimental_isLazyBundle ? true : environment.config.output?.inlineScripts ?? !enableChunkSplitting;
|
|
305
|
+
chain.plugin(PLUGIN_NAME_RUNTIME_WRAPPER).use(RuntimeWrapperWebpackPlugin, [
|
|
306
|
+
{
|
|
307
|
+
injectVars (vars) {
|
|
308
|
+
const UNUSED_VARS = new Set([
|
|
309
|
+
'Card',
|
|
310
|
+
'Component',
|
|
311
|
+
'ReactLynx',
|
|
312
|
+
'Behavior'
|
|
313
|
+
]);
|
|
314
|
+
return vars.map((name)=>{
|
|
315
|
+
if (UNUSED_VARS.has(name)) return `__${name}`;
|
|
316
|
+
return name;
|
|
317
|
+
});
|
|
318
|
+
},
|
|
319
|
+
targetSdkVersion,
|
|
320
|
+
experimental_isLazyBundle
|
|
321
|
+
}
|
|
322
|
+
]).end().plugin(`${LynxEncodePlugin.name}`).use(LynxEncodePlugin, [
|
|
323
|
+
{
|
|
324
|
+
inlineScripts
|
|
325
|
+
}
|
|
326
|
+
]).end();
|
|
327
|
+
}
|
|
328
|
+
if (isWeb) chain.plugin(PLUGIN_NAME_WEB).use(WebEncodePlugin, []).end();
|
|
291
329
|
let extractStr = originalExtractStr;
|
|
292
330
|
if (enableChunkSplitting && originalExtractStr) {
|
|
293
331
|
(api.logger ?? console).warn('`extractStr` is changed to `false` because it is only supported when chunk splitting is disabled, please set `splitChunks` to `false` to use `extractStr.`');
|
|
@@ -305,16 +343,19 @@ function applyEntry(api, options) {
|
|
|
305
343
|
extractStr,
|
|
306
344
|
experimental_isLazyBundle,
|
|
307
345
|
experimental_useElementTemplate: options.experimental_useElementTemplate,
|
|
308
|
-
experimental_transformBuiltinAttributeNames,
|
|
309
346
|
profile: getDefaultProfile(),
|
|
310
347
|
workletRuntimePath: await resolve(`@lynx-js/react/${isDev ? 'worklet-dev-runtime' : 'worklet-runtime'}`),
|
|
311
348
|
lazyBundleFetcher
|
|
312
349
|
}
|
|
313
350
|
]);
|
|
351
|
+
const isHostEnvironment = isApplication && !experimental_isLazyBundle;
|
|
352
|
+
if (isHostEnvironment && Object.keys(runtimeConfig).length > 0) chain.plugin(PLUGIN_NAME_RUNTIME_CONFIG).after(PLUGIN_NAME_REACT).use(RuntimeConfigWebpackPlugin, [
|
|
353
|
+
runtimeConfig
|
|
354
|
+
]);
|
|
314
355
|
function getDefaultProfile() {
|
|
315
356
|
const environmentProfile = rspeedyConfig?.environments?.[environment.name]?.performance?.profile;
|
|
316
357
|
if (void 0 !== environmentProfile) return environmentProfile;
|
|
317
|
-
const userProfile =
|
|
358
|
+
const userProfile = lynxConfig?.performance.profile;
|
|
318
359
|
if (void 0 !== userProfile) return userProfile;
|
|
319
360
|
if (isDebug()) return true;
|
|
320
361
|
}
|
|
@@ -324,6 +365,7 @@ const isDebug = ()=>{
|
|
|
324
365
|
if (!process.env['DEBUG']) return false;
|
|
325
366
|
const values = process.env['DEBUG'].toLocaleLowerCase().split(',');
|
|
326
367
|
return [
|
|
368
|
+
'lynx',
|
|
327
369
|
'rspeedy',
|
|
328
370
|
'*'
|
|
329
371
|
].some((key)=>values.includes(key));
|
|
@@ -396,8 +438,7 @@ const MAIN_THREAD_ENV_INCLUDE = [
|
|
|
396
438
|
const MAIN_THREAD_ENV_TARGETS = {
|
|
397
439
|
chrome: '120'
|
|
398
440
|
};
|
|
399
|
-
function getLoaderOptions(
|
|
400
|
-
const { output } = api.getRsbuildConfig();
|
|
441
|
+
function getLoaderOptions(output, options, isMainThread = false) {
|
|
401
442
|
const inlineSourcesContent = output?.sourceMap === true || !(output?.sourceMap === false || output?.sourceMap?.js === false || output?.sourceMap?.js?.includes('nosources'));
|
|
402
443
|
const { compat, enableRemoveCSSScope, shake, defineDCE, engineVersion, enableUiSourceMap, experimental_transformBuiltinAttributeNames, experimental_isLazyBundle, experimental_useElementTemplate } = options;
|
|
403
444
|
return {
|
|
@@ -417,13 +458,13 @@ function getLoaderOptions(api, options, isMainThread = false) {
|
|
|
417
458
|
}
|
|
418
459
|
const TESTING_RULE_NAME = 'react:testing';
|
|
419
460
|
function applyTestingLoaders(api, options) {
|
|
420
|
-
api.modifyBundlerChain((chain, { CHAIN_ID })=>{
|
|
461
|
+
api.modifyBundlerChain((chain, { CHAIN_ID, environment })=>{
|
|
421
462
|
const rule = chain.module.rule(CHAIN_ID.RULE.JS).oneOf(CHAIN_ID.ONE_OF.JS_MAIN);
|
|
422
|
-
rule.use(TESTING_RULE_NAME).loader(ReactWebpackPlugin.loaders.TESTING).options(getLoaderOptions(
|
|
463
|
+
rule.use(TESTING_RULE_NAME).loader(ReactWebpackPlugin.loaders.TESTING).options(getLoaderOptions(environment.config.output, options)).end();
|
|
423
464
|
});
|
|
424
465
|
}
|
|
425
466
|
function applyLoaders(api, options) {
|
|
426
|
-
api.modifyBundlerChain((chain, { CHAIN_ID })=>{
|
|
467
|
+
api.modifyBundlerChain((chain, { CHAIN_ID, environment })=>{
|
|
427
468
|
const rule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
428
469
|
const jsMainRule = rule.oneOf(CHAIN_ID.ONE_OF.JS_MAIN);
|
|
429
470
|
const type = jsMainRule.get('type');
|
|
@@ -432,7 +473,7 @@ function applyLoaders(api, options) {
|
|
|
432
473
|
const backgroundRule = jsMainRule.oneOf(LAYERS.BACKGROUND);
|
|
433
474
|
backgroundRule.issuerLayer(LAYERS.BACKGROUND).when(void 0 !== type, (rule)=>{
|
|
434
475
|
rule.type(type);
|
|
435
|
-
}).uses.merge(uses).end().use(LAYERS.BACKGROUND).loader(ReactWebpackPlugin.loaders.BACKGROUND).options(getLoaderOptions(
|
|
476
|
+
}).uses.merge(uses).end().use(LAYERS.BACKGROUND).loader(ReactWebpackPlugin.loaders.BACKGROUND).options(getLoaderOptions(environment.config.output, options)).end();
|
|
436
477
|
const mainThreadRule = jsMainRule.oneOf(LAYERS.MAIN_THREAD);
|
|
437
478
|
mainThreadRule.issuerLayer(LAYERS.MAIN_THREAD).when(void 0 !== type, (rule)=>{
|
|
438
479
|
rule.type(type);
|
|
@@ -456,7 +497,7 @@ function applyLoaders(api, options) {
|
|
|
456
497
|
]
|
|
457
498
|
}
|
|
458
499
|
});
|
|
459
|
-
}).use(LAYERS.MAIN_THREAD).loader(ReactWebpackPlugin.loaders.MAIN_THREAD).options(getLoaderOptions(
|
|
500
|
+
}).use(LAYERS.MAIN_THREAD).loader(ReactWebpackPlugin.loaders.MAIN_THREAD).options(getLoaderOptions(environment.config.output, options, true)).end();
|
|
460
501
|
});
|
|
461
502
|
}
|
|
462
503
|
function applyNodeEnv(api) {
|
|
@@ -523,46 +564,6 @@ async function applyRefreshRules(api, chain, CHAIN_ID, ReactRefreshPlugin) {
|
|
|
523
564
|
chain.resolve.alias.set('@lynx-js/react/refresh$', refresh);
|
|
524
565
|
chain.plugin(PLUGIN_NAME_REACT_REFRESH).before(CHAIN_ID.PLUGIN.HMR).use(ReactRefreshPlugin).end().module.rule('react:refresh').issuerLayer(LAYERS.BACKGROUND).before(CHAIN_ID.RULE.JS).test(/\.[jt]sx$/).exclude.add(/node_modules/).add(node_path.dirname(reactRuntime)).add(node_path.dirname(refresh)).add(node_path.dirname(workletRuntime)).add(ReactRefreshPlugin.loader).end().use('ReactRefresh').loader(ReactRefreshPlugin.loader).options({}).end().end().end().end();
|
|
525
566
|
}
|
|
526
|
-
const isPlainObject = (obj)=>null !== obj && 'object' == typeof obj && '[object Object]' === Object.prototype.toString.call(obj);
|
|
527
|
-
const applySplitChunksRule = (api)=>{
|
|
528
|
-
api.modifyRsbuildConfig((config, { mergeRsbuildConfig })=>{
|
|
529
|
-
const userConfig = api.getRsbuildConfig('original');
|
|
530
|
-
const chunkSplitStrategy = userConfig.performance?.chunkSplit?.strategy;
|
|
531
|
-
if (void 0 === userConfig.splitChunks && ('all-in-one' === chunkSplitStrategy || !chunkSplitStrategy)) return mergeRsbuildConfig(config, {
|
|
532
|
-
splitChunks: false
|
|
533
|
-
});
|
|
534
|
-
return config;
|
|
535
|
-
});
|
|
536
|
-
api.modifyBundlerChain((chain, { environment })=>{
|
|
537
|
-
const { config } = environment;
|
|
538
|
-
const userConfig = api.getRsbuildConfig('original');
|
|
539
|
-
const isSplitByExperience = void 0 === userConfig.splitChunks ? userConfig.performance?.chunkSplit?.strategy === 'split-by-experience' : isPlainObject(config.splitChunks) && 'default' === config.splitChunks.preset;
|
|
540
|
-
if (!isSplitByExperience) return;
|
|
541
|
-
const currentConfig = chain.optimization.splitChunks.values();
|
|
542
|
-
if (!isPlainObject(currentConfig)) return;
|
|
543
|
-
const extraGroups = {};
|
|
544
|
-
extraGroups['preact'] = {
|
|
545
|
-
name: 'lib-preact',
|
|
546
|
-
test: /node_modules[\\/](.*?[\\/])?(?:(?:internal-)?preact|(?:internal-)?preact[\\/]compat|(?:internal-)?preact[\\/]hooks|(?:internal-)?preact[\\/]jsx-runtime)[\\/]/,
|
|
547
|
-
priority: 0
|
|
548
|
-
};
|
|
549
|
-
chain.optimization.splitChunks({
|
|
550
|
-
...currentConfig,
|
|
551
|
-
cacheGroups: {
|
|
552
|
-
...currentConfig.cacheGroups,
|
|
553
|
-
...extraGroups
|
|
554
|
-
}
|
|
555
|
-
});
|
|
556
|
-
});
|
|
557
|
-
api.modifyRspackConfig((rspackConfig)=>{
|
|
558
|
-
if (!rspackConfig.optimization) return rspackConfig;
|
|
559
|
-
if (!rspackConfig.optimization.splitChunks) return rspackConfig;
|
|
560
|
-
rspackConfig.optimization.splitChunks.chunks = function(chunk) {
|
|
561
|
-
return !chunk.name?.includes('__main-thread');
|
|
562
|
-
};
|
|
563
|
-
return rspackConfig;
|
|
564
|
-
});
|
|
565
|
-
};
|
|
566
567
|
function applySWC(api) {
|
|
567
568
|
api.modifyRsbuildConfig((config, { mergeRsbuildConfig })=>mergeRsbuildConfig({
|
|
568
569
|
tools: {
|
|
@@ -1513,11 +1514,6 @@ function pluginReactLynx(userOptions) {
|
|
|
1513
1514
|
if (resolvedOptions.optimizeBundleSize) applyOptimizeBundleSize(api, resolvedOptions);
|
|
1514
1515
|
if (resolvedOptions.experimental_isLazyBundle) applyLazy(api);
|
|
1515
1516
|
api.expose(Symbol.for('LAYERS'), LAYERS);
|
|
1516
|
-
api.expose(Symbol.for('LynxTemplatePlugin'), {
|
|
1517
|
-
LynxTemplatePlugin: {
|
|
1518
|
-
getLynxTemplatePluginHooks: LynxTemplatePlugin.getLynxTemplatePluginHooks.bind(LynxTemplatePlugin)
|
|
1519
|
-
}
|
|
1520
|
-
});
|
|
1521
1517
|
const require = createRequire(import.meta.url);
|
|
1522
1518
|
const { version } = require('../package.json');
|
|
1523
1519
|
const webpackPluginPath = require.resolve('@lynx-js/react-webpack-plugin');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/react-rsbuild-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "A rsbuild plugin for ReactLynx",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rsbuild",
|
|
@@ -33,22 +33,23 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"tiny-invariant": "^1.3.3",
|
|
36
|
-
"@lynx-js/css-extract-webpack-plugin": "0.
|
|
37
|
-
"@lynx-js/react-
|
|
36
|
+
"@lynx-js/css-extract-webpack-plugin": "0.11.0",
|
|
37
|
+
"@lynx-js/react-webpack-plugin": "0.11.2",
|
|
38
38
|
"@lynx-js/react-refresh-webpack-plugin": "0.4.2",
|
|
39
|
-
"@lynx-js/
|
|
40
|
-
"@lynx-js/
|
|
41
|
-
"@lynx-js/
|
|
42
|
-
"@lynx-js/
|
|
39
|
+
"@lynx-js/rsbuild-plugin": "0.1.0",
|
|
40
|
+
"@lynx-js/runtime-config-webpack-plugin": "0.0.1",
|
|
41
|
+
"@lynx-js/react-alias-rsbuild-plugin": "0.20.0",
|
|
42
|
+
"@lynx-js/runtime-wrapper-webpack-plugin": "0.2.4",
|
|
43
|
+
"@lynx-js/template-webpack-plugin": "0.16.0",
|
|
43
44
|
"@lynx-js/use-sync-external-store": "1.5.0",
|
|
44
45
|
"background-only": "^0.0.1"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@microsoft/api-extractor": "7.58.12",
|
|
48
|
-
"@rsbuild/core": "2.
|
|
49
|
+
"@rsbuild/core": "2.2.3",
|
|
49
50
|
"@rsbuild/plugin-sass": "2.0.1",
|
|
50
51
|
"@rsbuild/plugin-typed-css-modules": "1.2.4",
|
|
51
|
-
"@rstest/core": "0.11.
|
|
52
|
+
"@rstest/core": "0.11.12",
|
|
52
53
|
"rsbuild-plugin-arethetypeswrong": "0.3.1",
|
|
53
54
|
"rsbuild-plugin-publint": "1.0.0",
|
|
54
55
|
"source-map": "^0.8.0",
|
|
@@ -56,19 +57,27 @@
|
|
|
56
57
|
"type-fest": "^5.8.0",
|
|
57
58
|
"typia": "12.1.1",
|
|
58
59
|
"typia-rspack-plugin": "3.0.1",
|
|
60
|
+
"@lynx-js/config-rsbuild-plugin": "0.2.3",
|
|
59
61
|
"@lynx-js/debug-metadata": "0.1.0",
|
|
60
|
-
"@lynx-js/
|
|
61
|
-
"@lynx-js/react": "0.125.0",
|
|
62
|
+
"@lynx-js/react": "0.126.0",
|
|
62
63
|
"@lynx-js/react-transform": "0.2.0",
|
|
63
|
-
"@lynx-js/rspeedy": "0.
|
|
64
|
+
"@lynx-js/rspeedy": "0.17.0",
|
|
64
65
|
"@lynx-js/test-tools": "0.0.0"
|
|
65
66
|
},
|
|
66
67
|
"peerDependencies": {
|
|
67
|
-
"@lynx-js/react": "^0.124.0 || ^0.125.0"
|
|
68
|
+
"@lynx-js/react": "^0.124.0 || ^0.125.0 || ^0.126.0",
|
|
69
|
+
"@lynx-js/rspeedy": "^0.17.0",
|
|
70
|
+
"@rsbuild/core": "^2.0.0"
|
|
68
71
|
},
|
|
69
72
|
"peerDependenciesMeta": {
|
|
70
73
|
"@lynx-js/react": {
|
|
71
74
|
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"@lynx-js/rspeedy": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"@rsbuild/core": {
|
|
80
|
+
"optional": true
|
|
72
81
|
}
|
|
73
82
|
},
|
|
74
83
|
"engines": {
|