@unpackjs/plugin-react 1.7.2 → 1.7.3
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 +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/splitChunks.cjs +56 -0
- package/dist/splitChunks.d.ts +6 -0
- package/dist/splitChunks.d.ts.map +1 -0
- package/dist/splitChunks.js +44 -0
- package/package.json +2 -2
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);
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,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,YA6F9D,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
} from "@unpackjs/core";
|
|
23
23
|
import { applyClickToComponentConfig } from "./click-to-component/index.js";
|
|
24
24
|
import { applyMpaConfig } from "./mpa.js";
|
|
25
|
+
import { applySplitChunksConfig } from "./splitChunks.js";
|
|
25
26
|
const PLUGIN_NAME = "unpack:react";
|
|
26
27
|
const pluginReact = (options = {}) => {
|
|
27
28
|
const { clickToComponent, reactCompiler } = options;
|
|
@@ -35,6 +36,7 @@ const pluginReact = (options = {}) => {
|
|
|
35
36
|
if (isDev() && clickToComponent) {
|
|
36
37
|
config = await applyClickToComponentConfig({ config, unpackConfig });
|
|
37
38
|
}
|
|
39
|
+
config = applySplitChunksConfig({ config, unpackConfig });
|
|
38
40
|
if (reactCompiler && !getUserDepPath(unpackConfig.root, "react-compiler-runtime")) {
|
|
39
41
|
logger.error('Dependency "react-compiler-runtime" not found. Did you install it?');
|
|
40
42
|
process.exit(1);
|
|
@@ -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
|
+
}) => BundlerConfiguration;
|
|
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,yBA2BA,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.
|
|
3
|
+
"version": "1.7.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"launch-editor": "2.9.1",
|
|
35
35
|
"react-refresh": "0.14.2",
|
|
36
36
|
"swc-loader": "0.2.6",
|
|
37
|
-
"@unpackjs/core": "^1.7.
|
|
37
|
+
"@unpackjs/core": "^1.7.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"dev": "modern build --watch",
|