@unpackjs/plugin-react 1.7.2 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -37,6 +37,7 @@ var import_plugin_react_refresh = __toESM(require("@rspack/plugin-react-refresh"
37
37
  var import_core = require("@unpackjs/core");
38
38
  var import_click_to_component = require("./click-to-component/index.cjs");
39
39
  var import_mpa = require("./mpa.cjs");
40
+ var import_splitChunks = require("./splitChunks.cjs");
40
41
  const PLUGIN_NAME = "unpack:react";
41
42
  const pluginReact = (options = {}) => {
42
43
  const { clickToComponent, reactCompiler } = options;
@@ -50,6 +51,7 @@ const pluginReact = (options = {}) => {
50
51
  if ((0, import_core.isDev)() && clickToComponent) {
51
52
  config = await (0, import_click_to_component.applyClickToComponentConfig)({ config, unpackConfig });
52
53
  }
54
+ config = (0, import_splitChunks.applySplitChunksConfig)({ config, unpackConfig });
53
55
  if (reactCompiler && !(0, import_core.getUserDepPath)(unpackConfig.root, "react-compiler-runtime")) {
54
56
  import_core.logger.error('Dependency "react-compiler-runtime" not found. Did you install it?');
55
57
  process.exit(1);
@@ -100,10 +102,6 @@ const pluginReact = (options = {}) => {
100
102
  loader: swcLoader,
101
103
  options: getSwcOptions({ tsx: true })
102
104
  },
103
- reactCompiler && unpackConfig.build?.parallel && {
104
- loader: import_node_path.default.resolve(__dirname, "../../core/dist/thread-loader/index.cjs"),
105
- options: import_core.THREAD_OPTIONS
106
- },
107
105
  reactCompiler && {
108
106
  loader: import_node_path.default.resolve(__dirname, "./react-compiler-loader/index.cjs"),
109
107
  options: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,YAAY,EAMlB,MAAM,gBAAgB,CAAA;AAIvB,eAAO,MAAM,WAAW,iBAAiB,CAAA;AAEzC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AACD,eAAO,MAAM,WAAW,aAAa,kBAAkB,KAAQ,YA4F9D,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,YAAY,EAMlB,MAAM,gBAAgB,CAAA;AAKvB,eAAO,MAAM,WAAW,iBAAiB,CAAA;AAEzC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AACD,eAAO,MAAM,WAAW,aAAa,kBAAkB,KAAQ,YAwF9D,CAAA"}
package/dist/index.js CHANGED
@@ -13,7 +13,6 @@ import RspackReactRefreshPlugin from "@rspack/plugin-react-refresh";
13
13
  import {
14
14
  DEFAULT_BROWSERSLIST,
15
15
  HtmlWebpackPlugin,
16
- THREAD_OPTIONS,
17
16
  getUserDepPath,
18
17
  getUserDepVersion,
19
18
  isDev,
@@ -22,6 +21,7 @@ import {
22
21
  } from "@unpackjs/core";
23
22
  import { applyClickToComponentConfig } from "./click-to-component/index.js";
24
23
  import { applyMpaConfig } from "./mpa.js";
24
+ import { applySplitChunksConfig } from "./splitChunks.js";
25
25
  const PLUGIN_NAME = "unpack:react";
26
26
  const pluginReact = (options = {}) => {
27
27
  const { clickToComponent, reactCompiler } = options;
@@ -35,6 +35,7 @@ const pluginReact = (options = {}) => {
35
35
  if (isDev() && clickToComponent) {
36
36
  config = await applyClickToComponentConfig({ config, unpackConfig });
37
37
  }
38
+ config = applySplitChunksConfig({ config, unpackConfig });
38
39
  if (reactCompiler && !getUserDepPath(unpackConfig.root, "react-compiler-runtime")) {
39
40
  logger.error('Dependency "react-compiler-runtime" not found. Did you install it?');
40
41
  process.exit(1);
@@ -85,10 +86,6 @@ const pluginReact = (options = {}) => {
85
86
  loader: swcLoader,
86
87
  options: getSwcOptions({ tsx: true })
87
88
  },
88
- reactCompiler && unpackConfig.build?.parallel && {
89
- loader: path2.resolve(__dirname, "../../core/dist/thread-loader/index.cjs"),
90
- options: THREAD_OPTIONS
91
- },
92
89
  reactCompiler && {
93
90
  loader: path2.resolve(__dirname, "./react-compiler-loader/index.cjs"),
94
91
  options: {
@@ -0,0 +1,56 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var splitChunks_exports = {};
19
+ __export(splitChunks_exports, {
20
+ applySplitChunksConfig: () => applySplitChunksConfig
21
+ });
22
+ module.exports = __toCommonJS(splitChunks_exports);
23
+ var import_core = require("@unpackjs/core");
24
+ const applySplitChunksConfig = ({
25
+ config,
26
+ unpackConfig
27
+ }) => {
28
+ if (unpackConfig.performance.chunkSplit.strategy !== "split-by-experience") {
29
+ return config;
30
+ }
31
+ const currentConfig = config.optimization.splitChunks;
32
+ const extraGroups = {};
33
+ extraGroups.react = {
34
+ name: "lib-react",
35
+ test: !(0, import_core.isDevServer)() ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
36
+ priority: 0
37
+ };
38
+ extraGroups.router = {
39
+ name: "lib-router",
40
+ test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
41
+ priority: 0
42
+ };
43
+ config.optimization.splitChunks = {
44
+ ...currentConfig,
45
+ cacheGroups: {
46
+ ...extraGroups,
47
+ // @ts-expect-error
48
+ ...currentConfig.cacheGroups
49
+ }
50
+ };
51
+ return config;
52
+ };
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ applySplitChunksConfig
56
+ });
@@ -0,0 +1,6 @@
1
+ import { type BundlerConfiguration, type UnpackConfig } from '@unpackjs/core';
2
+ export declare const applySplitChunksConfig: ({ config, unpackConfig, }: {
3
+ config: BundlerConfiguration;
4
+ unpackConfig: UnpackConfig;
5
+ }) => import("@rspack/core").RspackOptions;
6
+ //# sourceMappingURL=splitChunks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splitChunks.d.ts","sourceRoot":"","sources":["../src/splitChunks.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,oBAAoB,EAEzB,KAAK,YAAY,EAElB,MAAM,gBAAgB,CAAA;AAEvB,eAAO,MAAM,sBAAsB,8BAGhC;IACD,MAAM,EAAE,oBAAoB,CAAA;IAC5B,YAAY,EAAE,YAAY,CAAA;CAC3B,yCA2BA,CAAA"}
@@ -0,0 +1,44 @@
1
+ import { createRequire } from 'node:module';
2
+ var require = createRequire(import.meta['url']);
3
+
4
+ import path from "path";
5
+ import { fileURLToPath } from "url";
6
+ var getFilename = () => fileURLToPath(import.meta.url);
7
+ var getDirname = () => path.dirname(getFilename());
8
+ var __dirname = /* @__PURE__ */ getDirname();
9
+ var __filename = /* @__PURE__ */ getFilename();
10
+ import {
11
+ isDevServer
12
+ } from "@unpackjs/core";
13
+ const applySplitChunksConfig = ({
14
+ config,
15
+ unpackConfig
16
+ }) => {
17
+ if (unpackConfig.performance.chunkSplit.strategy !== "split-by-experience") {
18
+ return config;
19
+ }
20
+ const currentConfig = config.optimization.splitChunks;
21
+ const extraGroups = {};
22
+ extraGroups.react = {
23
+ name: "lib-react",
24
+ test: !isDevServer() ? /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/,
25
+ priority: 0
26
+ };
27
+ extraGroups.router = {
28
+ name: "lib-router",
29
+ test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
30
+ priority: 0
31
+ };
32
+ config.optimization.splitChunks = {
33
+ ...currentConfig,
34
+ cacheGroups: {
35
+ ...extraGroups,
36
+ // @ts-expect-error
37
+ ...currentConfig.cacheGroups
38
+ }
39
+ };
40
+ return config;
41
+ };
42
+ export {
43
+ applySplitChunksConfig
44
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unpackjs/plugin-react",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -27,14 +27,14 @@
27
27
  "@babel/plugin-proposal-decorators": "7.25.9",
28
28
  "@babel/plugin-transform-class-properties": "7.25.9",
29
29
  "@pmmmwh/react-refresh-webpack-plugin": "0.5.15",
30
- "@rspack/plugin-react-refresh": "1.0.0",
31
- "@swc/core": "1.9.3",
30
+ "@rspack/plugin-react-refresh": "1.0.1",
31
+ "@swc/core": "1.10.1",
32
32
  "@swc/helpers": "0.5.15",
33
33
  "babel-plugin-react-compiler": "latest",
34
34
  "launch-editor": "2.9.1",
35
- "react-refresh": "0.14.2",
35
+ "react-refresh": "0.16.0",
36
36
  "swc-loader": "0.2.6",
37
- "@unpackjs/core": "^1.7.2"
37
+ "@unpackjs/core": "^1.7.4"
38
38
  },
39
39
  "scripts": {
40
40
  "dev": "modern build --watch",