@lynx-js/react-rsbuild-plugin 0.13.0 → 0.14.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 CHANGED
@@ -1,5 +1,26 @@
1
1
  # @lynx-js/react-rsbuild-plugin
2
2
 
3
+ ## 0.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - feat: support `optimizeBundleSize` option to remove unused code for main-thread and background. ([#2336](https://github.com/lynx-family/lynx-stack/pull/2336))
8
+
9
+ - If `optimizeBundleSize` is `true` or `optimizeBundleSize.background` is `true`, `lynx.registerDataProcessors` calls will be marked as pure for the background thread output.
10
+ - If `optimizeBundleSize` is `true` or `optimizeBundleSize.mainThread` is `true`, `NativeModules.call` and `lynx.getJSModule` calls will be marked as pure for the main-thread output.
11
+
12
+ ### Patch Changes
13
+
14
+ - refactor: remove `modifyWebpackChain` since Rsbuild 2.0 dropped webpack support ([#2397](https://github.com/lynx-family/lynx-stack/pull/2397))
15
+
16
+ - Updated dependencies [[`9193711`](https://github.com/lynx-family/lynx-stack/commit/919371167f4136f2ee975075d8e73d2986b20a8f)]:
17
+ - @lynx-js/template-webpack-plugin@0.10.7
18
+ - @lynx-js/css-extract-webpack-plugin@0.7.0
19
+ - @lynx-js/react-webpack-plugin@0.8.0
20
+ - @lynx-js/react-alias-rsbuild-plugin@0.14.0
21
+ - @lynx-js/use-sync-external-store@1.5.0
22
+ - @lynx-js/react-refresh-webpack-plugin@0.3.5
23
+
3
24
  ## 0.13.0
4
25
 
5
26
  ### Minor Changes
package/dist/208.js CHANGED
@@ -6,7 +6,7 @@ import { LynxEncodePlugin, LynxTemplatePlugin, WebEncodePlugin } from "@lynx-js/
6
6
  import node_path from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { RuntimeWrapperWebpackPlugin } from "@lynx-js/runtime-wrapper-webpack-plugin";
9
- import { ReactRefreshRspackPlugin, ReactRefreshWebpackPlugin } from "@lynx-js/react-refresh-webpack-plugin";
9
+ import { ReactRefreshRspackPlugin } from "@lynx-js/react-refresh-webpack-plugin";
10
10
  __webpack_require__.add({
11
11
  "../../../node_modules/.pnpm/typia@10.1.0_typescript@5.9.3/node_modules/typia/lib/internal/_accessExpressionAsString.js" (__unused_rspack_module, exports) {
12
12
  exports._accessExpressionAsString = void 0;
@@ -443,11 +443,43 @@ function applyNodeEnv(api) {
443
443
  }
444
444
  }));
445
445
  }
446
+ function applyOptimizeBundleSize(api, options) {
447
+ api.modifyRsbuildConfig((config, { mergeRsbuildConfig })=>{
448
+ const optimizeBundleSize = options.optimizeBundleSize;
449
+ const optimizeBackground = 'boolean' == typeof optimizeBundleSize ? optimizeBundleSize : optimizeBundleSize?.background;
450
+ const optimizeMainThread = 'boolean' == typeof optimizeBundleSize ? optimizeBundleSize : optimizeBundleSize?.mainThread;
451
+ if (optimizeBackground || optimizeMainThread) {
452
+ const minifyConfig = {};
453
+ if (optimizeBackground) minifyConfig['backgroundOptions'] = {
454
+ minimizerOptions: {
455
+ compress: {
456
+ pure_funcs: [
457
+ 'lynx.registerDataProcessors'
458
+ ]
459
+ }
460
+ }
461
+ };
462
+ if (optimizeMainThread) minifyConfig['mainThreadOptions'] = {
463
+ minimizerOptions: {
464
+ compress: {
465
+ pure_funcs: [
466
+ 'NativeModules.call',
467
+ 'lynx.getJSModule'
468
+ ]
469
+ }
470
+ }
471
+ };
472
+ return mergeRsbuildConfig(config, {
473
+ output: {
474
+ minify: minifyConfig
475
+ }
476
+ });
477
+ }
478
+ return config;
479
+ });
480
+ }
446
481
  const PLUGIN_NAME_REACT_REFRESH = 'lynx:react:refresh';
447
482
  function applyRefresh(api) {
448
- api.modifyWebpackChain(async (chain, { CHAIN_ID, isProd })=>{
449
- if (!isProd) await applyRefreshRules(api, chain, CHAIN_ID, ReactRefreshWebpackPlugin);
450
- });
451
483
  api.modifyBundlerChain(async (chain, { isProd, CHAIN_ID })=>{
452
484
  if (!isProd) {
453
485
  const { resolve } = api.useExposed(Symbol.for('@lynx-js/react/internal:resolve'));
@@ -563,7 +595,7 @@ function applyUseSyncExternalStore(api) {
563
595
  const _assertGuard = __webpack_require__("../../../node_modules/.pnpm/typia@10.1.0_typescript@5.9.3/node_modules/typia/lib/internal/_assertGuard.js");
564
596
  const _accessExpressionAsString = __webpack_require__("../../../node_modules/.pnpm/typia@10.1.0_typescript@5.9.3/node_modules/typia/lib/internal/_accessExpressionAsString.js");
565
597
  const validateConfig = (()=>{
566
- const _io0 = (input, _exceptionable = true)=>(void 0 === input.compat || "object" == typeof input.compat && null !== input.compat && false === Array.isArray(input.compat) && _io1(input.compat, _exceptionable)) && (void 0 === input.customCSSInheritanceList || Array.isArray(input.customCSSInheritanceList) && input.customCSSInheritanceList.every((elem, _index1)=>"string" == typeof elem)) && (void 0 === input.debugInfoOutside || "boolean" == typeof input.debugInfoOutside) && (void 0 === input.defaultDisplayLinear || "boolean" == typeof input.defaultDisplayLinear) && (void 0 === input.enableAccessibilityElement || "boolean" == typeof input.enableAccessibilityElement) && (void 0 === input.enableCSSInheritance || "boolean" == typeof input.enableCSSInheritance) && (void 0 === input.enableCSSInvalidation || "boolean" == typeof input.enableCSSInvalidation) && (void 0 === input.enableCSSSelector || "boolean" == typeof input.enableCSSSelector) && (void 0 === input.enableNewGesture || "boolean" == typeof input.enableNewGesture) && (void 0 === input.enableRemoveCSSScope || "boolean" == typeof input.enableRemoveCSSScope) && (void 0 === input.firstScreenSyncTiming || "immediately" === input.firstScreenSyncTiming || "jsReady" === input.firstScreenSyncTiming) && (void 0 === input.enableSSR || "boolean" == typeof input.enableSSR) && (void 0 === input.removeDescendantSelectorScope || "boolean" == typeof input.removeDescendantSelectorScope) && (void 0 === input.shake || "object" == typeof input.shake && null !== input.shake && false === Array.isArray(input.shake) && _io4(input.shake, _exceptionable)) && (void 0 === input.defineDCE || "object" == typeof input.defineDCE && null !== input.defineDCE && false === Array.isArray(input.defineDCE) && _io5(input.defineDCE, _exceptionable)) && (void 0 === input.engineVersion || "string" == typeof input.engineVersion) && (void 0 === input.targetSdkVersion || "string" == typeof input.targetSdkVersion) && (void 0 === input.globalPropsMode || "reactive" === input.globalPropsMode || "event" === input.globalPropsMode) && null !== input.extractStr && (void 0 === input.extractStr || "boolean" == typeof input.extractStr || "object" == typeof input.extractStr && null !== input.extractStr && false === Array.isArray(input.extractStr) && _io7(input.extractStr, _exceptionable)) && (void 0 === input.experimental_isLazyBundle || "boolean" == typeof input.experimental_isLazyBundle) && (0 === Object.keys(input).length || Object.keys(input).every((key)=>{
598
+ const _io0 = (input, _exceptionable = true)=>(void 0 === input.compat || "object" == typeof input.compat && null !== input.compat && false === Array.isArray(input.compat) && _io1(input.compat, _exceptionable)) && (void 0 === input.customCSSInheritanceList || Array.isArray(input.customCSSInheritanceList) && input.customCSSInheritanceList.every((elem, _index1)=>"string" == typeof elem)) && (void 0 === input.debugInfoOutside || "boolean" == typeof input.debugInfoOutside) && (void 0 === input.defaultDisplayLinear || "boolean" == typeof input.defaultDisplayLinear) && (void 0 === input.enableAccessibilityElement || "boolean" == typeof input.enableAccessibilityElement) && (void 0 === input.enableCSSInheritance || "boolean" == typeof input.enableCSSInheritance) && (void 0 === input.enableCSSInvalidation || "boolean" == typeof input.enableCSSInvalidation) && (void 0 === input.enableCSSSelector || "boolean" == typeof input.enableCSSSelector) && (void 0 === input.enableNewGesture || "boolean" == typeof input.enableNewGesture) && (void 0 === input.enableRemoveCSSScope || "boolean" == typeof input.enableRemoveCSSScope) && (void 0 === input.firstScreenSyncTiming || "immediately" === input.firstScreenSyncTiming || "jsReady" === input.firstScreenSyncTiming) && (void 0 === input.enableSSR || "boolean" == typeof input.enableSSR) && (void 0 === input.removeDescendantSelectorScope || "boolean" == typeof input.removeDescendantSelectorScope) && (void 0 === input.shake || "object" == typeof input.shake && null !== input.shake && false === Array.isArray(input.shake) && _io4(input.shake, _exceptionable)) && (void 0 === input.defineDCE || "object" == typeof input.defineDCE && null !== input.defineDCE && false === Array.isArray(input.defineDCE) && _io5(input.defineDCE, _exceptionable)) && (void 0 === input.engineVersion || "string" == typeof input.engineVersion) && (void 0 === input.targetSdkVersion || "string" == typeof input.targetSdkVersion) && (void 0 === input.globalPropsMode || "reactive" === input.globalPropsMode || "event" === input.globalPropsMode) && null !== input.extractStr && (void 0 === input.extractStr || "boolean" == typeof input.extractStr || "object" == typeof input.extractStr && null !== input.extractStr && false === Array.isArray(input.extractStr) && _io7(input.extractStr, _exceptionable)) && (void 0 === input.experimental_isLazyBundle || "boolean" == typeof input.experimental_isLazyBundle) && null !== input.optimizeBundleSize && (void 0 === input.optimizeBundleSize || "boolean" == typeof input.optimizeBundleSize || "object" == typeof input.optimizeBundleSize && null !== input.optimizeBundleSize && false === Array.isArray(input.optimizeBundleSize) && _io8(input.optimizeBundleSize, _exceptionable)) && (0 === Object.keys(input).length || Object.keys(input).every((key)=>{
567
599
  if ([
568
600
  "compat",
569
601
  "customCSSInheritanceList",
@@ -584,7 +616,8 @@ const validateConfig = (()=>{
584
616
  "targetSdkVersion",
585
617
  "globalPropsMode",
586
618
  "extractStr",
587
- "experimental_isLazyBundle"
619
+ "experimental_isLazyBundle",
620
+ "optimizeBundleSize"
588
621
  ].some((prop)=>key === prop)) return true;
589
622
  const value = input[key];
590
623
  if (void 0 === value) return true;
@@ -654,6 +687,15 @@ const validateConfig = (()=>{
654
687
  if (void 0 === value) return true;
655
688
  return false;
656
689
  }));
690
+ const _io8 = (input, _exceptionable = true)=>(void 0 === input.mainThread || "boolean" == typeof input.mainThread) && (void 0 === input.background || "boolean" == typeof input.background) && (0 === Object.keys(input).length || Object.keys(input).every((key)=>{
691
+ if ([
692
+ "mainThread",
693
+ "background"
694
+ ].some((prop)=>key === prop)) return true;
695
+ const value = input[key];
696
+ if (void 0 === value) return true;
697
+ return false;
698
+ }));
657
699
  const _ao0 = (input, _path, _exceptionable = true)=>(void 0 === input.compat || ("object" == typeof input.compat && null !== input.compat && false === Array.isArray(input.compat) || _assertGuard._assertGuard(_exceptionable, {
658
700
  method: "typia.createAssertEquals",
659
701
  path: _path + ".compat",
@@ -789,6 +831,21 @@ const validateConfig = (()=>{
789
831
  path: _path + ".experimental_isLazyBundle",
790
832
  expected: "(boolean | undefined)",
791
833
  value: input.experimental_isLazyBundle
834
+ }, _errorFactory)) && (null !== input.optimizeBundleSize || _assertGuard._assertGuard(_exceptionable, {
835
+ method: "typia.createAssertEquals",
836
+ path: _path + ".optimizeBundleSize",
837
+ expected: "(__type | boolean | undefined)",
838
+ value: input.optimizeBundleSize
839
+ }, _errorFactory)) && (void 0 === input.optimizeBundleSize || "boolean" == typeof input.optimizeBundleSize || ("object" == typeof input.optimizeBundleSize && null !== input.optimizeBundleSize && false === Array.isArray(input.optimizeBundleSize) || _assertGuard._assertGuard(_exceptionable, {
840
+ method: "typia.createAssertEquals",
841
+ path: _path + ".optimizeBundleSize",
842
+ expected: "(__type | boolean | undefined)",
843
+ value: input.optimizeBundleSize
844
+ }, _errorFactory)) && _ao8(input.optimizeBundleSize, _path + ".optimizeBundleSize", _exceptionable) || _assertGuard._assertGuard(_exceptionable, {
845
+ method: "typia.createAssertEquals",
846
+ path: _path + ".optimizeBundleSize",
847
+ expected: "(__type | boolean | undefined)",
848
+ value: input.optimizeBundleSize
792
849
  }, _errorFactory)) && (0 === Object.keys(input).length || false === _exceptionable || Object.keys(input).every((key)=>{
793
850
  if ([
794
851
  "compat",
@@ -810,7 +867,8 @@ const validateConfig = (()=>{
810
867
  "targetSdkVersion",
811
868
  "globalPropsMode",
812
869
  "extractStr",
813
- "experimental_isLazyBundle"
870
+ "experimental_isLazyBundle",
871
+ "optimizeBundleSize"
814
872
  ].some((prop)=>key === prop)) return true;
815
873
  const value = input[key];
816
874
  if (void 0 === value) return true;
@@ -1090,6 +1148,30 @@ const validateConfig = (()=>{
1090
1148
  value: value
1091
1149
  }, _errorFactory);
1092
1150
  }));
1151
+ const _ao8 = (input, _path, _exceptionable = true)=>(void 0 === input.mainThread || "boolean" == typeof input.mainThread || _assertGuard._assertGuard(_exceptionable, {
1152
+ method: "typia.createAssertEquals",
1153
+ path: _path + ".mainThread",
1154
+ expected: "(boolean | undefined)",
1155
+ value: input.mainThread
1156
+ }, _errorFactory)) && (void 0 === input.background || "boolean" == typeof input.background || _assertGuard._assertGuard(_exceptionable, {
1157
+ method: "typia.createAssertEquals",
1158
+ path: _path + ".background",
1159
+ expected: "(boolean | undefined)",
1160
+ value: input.background
1161
+ }, _errorFactory)) && (0 === Object.keys(input).length || false === _exceptionable || Object.keys(input).every((key)=>{
1162
+ if ([
1163
+ "mainThread",
1164
+ "background"
1165
+ ].some((prop)=>key === prop)) return true;
1166
+ const value = input[key];
1167
+ if (void 0 === value) return true;
1168
+ return _assertGuard._assertGuard(_exceptionable, {
1169
+ method: "typia.createAssertEquals",
1170
+ path: _path + _accessExpressionAsString._accessExpressionAsString(key),
1171
+ expected: "undefined",
1172
+ value: value
1173
+ }, _errorFactory);
1174
+ }));
1093
1175
  const __is = (input, _exceptionable = true)=>void 0 === input || "object" == typeof input && null !== input && false === Array.isArray(input) && _io0(input, true);
1094
1176
  let _errorFactory;
1095
1177
  return (input, errorFactory = ({ path, expected, value })=>{
@@ -1147,7 +1229,8 @@ function pluginReactLynx(userOptions) {
1147
1229
  engineVersion: '',
1148
1230
  extractStr: false,
1149
1231
  globalPropsMode: 'reactive',
1150
- experimental_isLazyBundle: false
1232
+ experimental_isLazyBundle: false,
1233
+ optimizeBundleSize: false
1151
1234
  };
1152
1235
  const resolvedOptions = Object.assign(defaultOptions, userOptions, {
1153
1236
  targetSdkVersion: engineVersion,
@@ -1209,6 +1292,7 @@ function pluginReactLynx(userOptions) {
1209
1292
  }, config);
1210
1293
  return config;
1211
1294
  });
1295
+ if (resolvedOptions.optimizeBundleSize) applyOptimizeBundleSize(api, resolvedOptions);
1212
1296
  if (resolvedOptions.experimental_isLazyBundle) applyLazy(api);
1213
1297
  api.expose(Symbol.for('LAYERS'), LAYERS);
1214
1298
  api.expose(Symbol.for('LynxTemplatePlugin'), {
package/dist/index.d.ts CHANGED
@@ -640,6 +640,7 @@ export declare interface PluginReactLynxOptions {
640
640
  * `'event'`: `UpdateGlobalProps` will trigger global event and users need to trigger update in the event handler.
641
641
  *
642
642
  * @defaultValue `'reactive'`
643
+ * @public
643
644
  */
644
645
  globalPropsMode?: 'reactive' | 'event';
645
646
  /**
@@ -655,6 +656,19 @@ export declare interface PluginReactLynxOptions {
655
656
  * @alpha
656
657
  */
657
658
  experimental_isLazyBundle?: boolean;
659
+ /**
660
+ * Optimize bundle size by removing unused code by Minify.mainThreadOptions and Minify.backgroundOptions.
661
+ *
662
+ * When optimizeBundleSize or optimizeBundleSize.mainThread is true, main-thread code will be optimized.
663
+ * When optimizeBundleSize or optimizeBundleSize.background is true, background code will be optimized.
664
+ *
665
+ * @defaultValue `false`
666
+ * @public
667
+ */
668
+ optimizeBundleSize?: boolean | {
669
+ mainThread?: boolean;
670
+ background?: boolean;
671
+ };
658
672
  }
659
673
 
660
674
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/react-rsbuild-plugin",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "A rsbuild plugin for ReactLynx",
5
5
  "keywords": [
6
6
  "rsbuild",
@@ -33,18 +33,18 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@lynx-js/css-extract-webpack-plugin": "0.7.0",
36
- "@lynx-js/react-alias-rsbuild-plugin": "0.13.0",
36
+ "@lynx-js/react-alias-rsbuild-plugin": "0.14.0",
37
37
  "@lynx-js/react-refresh-webpack-plugin": "0.3.5",
38
38
  "@lynx-js/react-webpack-plugin": "0.8.0",
39
39
  "@lynx-js/runtime-wrapper-webpack-plugin": "0.1.3",
40
- "@lynx-js/template-webpack-plugin": "0.10.6",
40
+ "@lynx-js/template-webpack-plugin": "0.10.7",
41
41
  "@lynx-js/use-sync-external-store": "1.5.0",
42
42
  "background-only": "^0.0.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@microsoft/api-extractor": "7.57.6",
46
46
  "@rollup/plugin-typescript": "^12.3.0",
47
- "@rsbuild/core": "1.7.3",
47
+ "@rsbuild/core": "1.7.4",
48
48
  "@rsbuild/plugin-sass": "1.5.0",
49
49
  "@rsbuild/plugin-typed-css-modules": "1.2.2",
50
50
  "rsbuild-plugin-arethetypeswrong": "0.2.0",
@@ -55,9 +55,9 @@
55
55
  "typia": "10.1.0",
56
56
  "typia-rspack-plugin": "2.2.2",
57
57
  "@lynx-js/config-rsbuild-plugin": "0.0.1",
58
- "@lynx-js/react": "0.117.0",
58
+ "@lynx-js/react": "0.117.1",
59
59
  "@lynx-js/react-transform": "0.2.0",
60
- "@lynx-js/rspeedy": "0.13.6",
60
+ "@lynx-js/rspeedy": "0.14.0",
61
61
  "@lynx-js/vitest-setup": "0.0.0"
62
62
  },
63
63
  "peerDependencies": {