@unpackjs/plugin-react 1.5.0 → 1.5.2
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 +5 -5
- package/dist/index.js +5 -5
- package/dist/mpa.cjs +12 -9
- package/dist/mpa.d.ts +2 -1
- package/dist/mpa.d.ts.map +1 -1
- package/dist/mpa.js +12 -9
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -41,12 +41,12 @@ const PLUGIN_NAME = "unpack:react";
|
|
|
41
41
|
const pluginReact = (options = {}) => {
|
|
42
42
|
return {
|
|
43
43
|
name: PLUGIN_NAME,
|
|
44
|
-
bundlerConfig: async (
|
|
45
|
-
let
|
|
44
|
+
bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig, bundler }) => {
|
|
45
|
+
let config = originalConfig;
|
|
46
46
|
if (options.clickToComponent) {
|
|
47
|
-
|
|
47
|
+
config = await (0, import_click_to_component.addClickToComponentSupport)({ config, bundler });
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
config = (0, import_mpa.addMpaSupport)({ config, unpackConfig, mergeConfig });
|
|
50
50
|
const jsExclude = [/node_modules[\\/](?!\.unpack)/];
|
|
51
51
|
const swcLoader = unpackConfig.bundler === "rspack" ? "builtin:swc-loader" : require.resolve("swc-loader");
|
|
52
52
|
const ReactRefreshPlugin = unpackConfig.bundler === "rspack" ? import_plugin_react_refresh.default : import_react_refresh_webpack_plugin.default;
|
|
@@ -72,7 +72,7 @@ const pluginReact = (options = {}) => {
|
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
|
-
return mergeConfig(
|
|
75
|
+
return mergeConfig(config, {
|
|
76
76
|
module: {
|
|
77
77
|
rules: [
|
|
78
78
|
{
|
package/dist/index.js
CHANGED
|
@@ -17,12 +17,12 @@ const PLUGIN_NAME = "unpack:react";
|
|
|
17
17
|
const pluginReact = (options = {}) => {
|
|
18
18
|
return {
|
|
19
19
|
name: PLUGIN_NAME,
|
|
20
|
-
bundlerConfig: async (
|
|
21
|
-
let
|
|
20
|
+
bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig, bundler }) => {
|
|
21
|
+
let config = originalConfig;
|
|
22
22
|
if (options.clickToComponent) {
|
|
23
|
-
|
|
23
|
+
config = await addClickToComponentSupport({ config, bundler });
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
config = addMpaSupport({ config, unpackConfig, mergeConfig });
|
|
26
26
|
const jsExclude = [/node_modules[\\/](?!\.unpack)/];
|
|
27
27
|
const swcLoader = unpackConfig.bundler === "rspack" ? "builtin:swc-loader" : require.resolve("swc-loader");
|
|
28
28
|
const ReactRefreshPlugin = unpackConfig.bundler === "rspack" ? RspackReactRefreshPlugin : WebpackReactRefreshPlugin;
|
|
@@ -48,7 +48,7 @@ const pluginReact = (options = {}) => {
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
|
-
return mergeConfig(
|
|
51
|
+
return mergeConfig(config, {
|
|
52
52
|
module: {
|
|
53
53
|
rules: [
|
|
54
54
|
{
|
package/dist/mpa.cjs
CHANGED
|
@@ -36,7 +36,8 @@ var import_shared = require("@unpackjs/shared");
|
|
|
36
36
|
var import_html_webpack_plugin = __toESM(require("html-webpack-plugin"));
|
|
37
37
|
const addMpaSupport = ({
|
|
38
38
|
config,
|
|
39
|
-
unpackConfig
|
|
39
|
+
unpackConfig,
|
|
40
|
+
mergeConfig
|
|
40
41
|
}) => {
|
|
41
42
|
if (!unpackConfig.mpa)
|
|
42
43
|
return config;
|
|
@@ -44,11 +45,11 @@ const addMpaSupport = ({
|
|
|
44
45
|
const userOptions = (0, import_shared.isPlainObject)(unpackConfig.mpa) ? unpackConfig.mpa : {};
|
|
45
46
|
const getPageConfig = (indexPath) => {
|
|
46
47
|
const filePath = import_node_path.default.join(indexPath, "../config.json");
|
|
47
|
-
let
|
|
48
|
+
let pageConfig = {};
|
|
48
49
|
if (import_node_fs.default.existsSync(filePath)) {
|
|
49
|
-
|
|
50
|
+
pageConfig = JSON.parse(import_node_fs.default.readFileSync(filePath, "utf-8"));
|
|
50
51
|
}
|
|
51
|
-
return
|
|
52
|
+
return pageConfig;
|
|
52
53
|
};
|
|
53
54
|
const getPathInJs = (absPath) => {
|
|
54
55
|
return JSON.stringify(absPath).slice(1, -1);
|
|
@@ -70,13 +71,13 @@ import '${getAbsPathForEntry(curr)}';`.trimStart();
|
|
|
70
71
|
const rootElement = `document.getElementById('${unpackConfig.html?.mountId}')`;
|
|
71
72
|
const reactDOMSource = "react-dom/client";
|
|
72
73
|
const renderer = `ReactDOM.createRoot(${rootElement}).render(${layoutJSX});`;
|
|
73
|
-
Object.entries(entry2).forEach(([entryName,
|
|
74
|
+
Object.entries(entry2).forEach(([entryName, entryConfig]) => {
|
|
74
75
|
const filePath = import_node_path.default.join(unpackConfig.root, tempDirectory, `${entryName}.jsx`);
|
|
75
76
|
const tpl = `
|
|
76
77
|
// DO NOT CHANGE IT MANUALLY!
|
|
77
78
|
import React from 'react';
|
|
78
79
|
import ReactDOM from '${reactDOMSource}';
|
|
79
|
-
import App from '${getPathInJs(
|
|
80
|
+
import App from '${getPathInJs(entryConfig.import[0])}';${layoutImport && `
|
|
80
81
|
${layoutImport}`}
|
|
81
82
|
${globalImport}
|
|
82
83
|
${renderer}
|
|
@@ -86,7 +87,7 @@ ${renderer}
|
|
|
86
87
|
import_node_fs.default.mkdirSync(dir, { recursive: true });
|
|
87
88
|
}
|
|
88
89
|
import_node_fs.default.writeFileSync(filePath, tpl, "utf-8");
|
|
89
|
-
|
|
90
|
+
entryConfig.import[0] = filePath;
|
|
90
91
|
});
|
|
91
92
|
return entry2;
|
|
92
93
|
};
|
|
@@ -144,8 +145,10 @@ ${renderer}
|
|
|
144
145
|
return { entry: entry2, html: html2 };
|
|
145
146
|
};
|
|
146
147
|
const { entry, html } = collectEntry();
|
|
147
|
-
config
|
|
148
|
-
|
|
148
|
+
config = mergeConfig(config, {
|
|
149
|
+
entry: createTempFile(entry),
|
|
150
|
+
plugins: html.map((h) => new import_html_webpack_plugin.default(h))
|
|
151
|
+
});
|
|
149
152
|
return config;
|
|
150
153
|
};
|
|
151
154
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/mpa.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type BundlerConfiguration, type UnpackConfig } from '@unpackjs/shared';
|
|
2
|
-
export declare const addMpaSupport: ({ config, unpackConfig, }: {
|
|
2
|
+
export declare const addMpaSupport: ({ config, unpackConfig, mergeConfig, }: {
|
|
3
3
|
config: BundlerConfiguration;
|
|
4
4
|
unpackConfig: UnpackConfig;
|
|
5
|
+
mergeConfig: (...configs: BundlerConfiguration[]) => BundlerConfiguration;
|
|
5
6
|
}) => BundlerConfiguration;
|
|
6
7
|
//# sourceMappingURL=mpa.d.ts.map
|
package/dist/mpa.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mpa.d.ts","sourceRoot":"","sources":["../src/mpa.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EAGzB,KAAK,YAAY,EAMlB,MAAM,kBAAkB,CAAA;AAazB,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"mpa.d.ts","sourceRoot":"","sources":["../src/mpa.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EAGzB,KAAK,YAAY,EAMlB,MAAM,kBAAkB,CAAA;AAazB,eAAO,MAAM,aAAa,2CAIvB;IACD,MAAM,EAAE,oBAAoB,CAAA;IAC5B,YAAY,EAAE,YAAY,CAAA;IAC1B,WAAW,EAAE,CAAC,GAAG,OAAO,EAAE,oBAAoB,EAAE,KAAK,oBAAoB,CAAA;CAC1E,KAAG,oBAoHH,CAAA"}
|
package/dist/mpa.js
CHANGED
|
@@ -21,7 +21,8 @@ import {
|
|
|
21
21
|
import HtmlWebpackPlugin from "html-webpack-plugin";
|
|
22
22
|
const addMpaSupport = ({
|
|
23
23
|
config,
|
|
24
|
-
unpackConfig
|
|
24
|
+
unpackConfig,
|
|
25
|
+
mergeConfig
|
|
25
26
|
}) => {
|
|
26
27
|
if (!unpackConfig.mpa)
|
|
27
28
|
return config;
|
|
@@ -29,11 +30,11 @@ const addMpaSupport = ({
|
|
|
29
30
|
const userOptions = isPlainObject(unpackConfig.mpa) ? unpackConfig.mpa : {};
|
|
30
31
|
const getPageConfig = (indexPath) => {
|
|
31
32
|
const filePath = path2.join(indexPath, "../config.json");
|
|
32
|
-
let
|
|
33
|
+
let pageConfig = {};
|
|
33
34
|
if (fs.existsSync(filePath)) {
|
|
34
|
-
|
|
35
|
+
pageConfig = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
35
36
|
}
|
|
36
|
-
return
|
|
37
|
+
return pageConfig;
|
|
37
38
|
};
|
|
38
39
|
const getPathInJs = (absPath) => {
|
|
39
40
|
return JSON.stringify(absPath).slice(1, -1);
|
|
@@ -55,13 +56,13 @@ import '${getAbsPathForEntry(curr)}';`.trimStart();
|
|
|
55
56
|
const rootElement = `document.getElementById('${unpackConfig.html?.mountId}')`;
|
|
56
57
|
const reactDOMSource = "react-dom/client";
|
|
57
58
|
const renderer = `ReactDOM.createRoot(${rootElement}).render(${layoutJSX});`;
|
|
58
|
-
Object.entries(entry2).forEach(([entryName,
|
|
59
|
+
Object.entries(entry2).forEach(([entryName, entryConfig]) => {
|
|
59
60
|
const filePath = path2.join(unpackConfig.root, tempDirectory, `${entryName}.jsx`);
|
|
60
61
|
const tpl = `
|
|
61
62
|
// DO NOT CHANGE IT MANUALLY!
|
|
62
63
|
import React from 'react';
|
|
63
64
|
import ReactDOM from '${reactDOMSource}';
|
|
64
|
-
import App from '${getPathInJs(
|
|
65
|
+
import App from '${getPathInJs(entryConfig.import[0])}';${layoutImport && `
|
|
65
66
|
${layoutImport}`}
|
|
66
67
|
${globalImport}
|
|
67
68
|
${renderer}
|
|
@@ -71,7 +72,7 @@ ${renderer}
|
|
|
71
72
|
fs.mkdirSync(dir, { recursive: true });
|
|
72
73
|
}
|
|
73
74
|
fs.writeFileSync(filePath, tpl, "utf-8");
|
|
74
|
-
|
|
75
|
+
entryConfig.import[0] = filePath;
|
|
75
76
|
});
|
|
76
77
|
return entry2;
|
|
77
78
|
};
|
|
@@ -129,8 +130,10 @@ ${renderer}
|
|
|
129
130
|
return { entry: entry2, html: html2 };
|
|
130
131
|
};
|
|
131
132
|
const { entry, html } = collectEntry();
|
|
132
|
-
config
|
|
133
|
-
|
|
133
|
+
config = mergeConfig(config, {
|
|
134
|
+
entry: createTempFile(entry),
|
|
135
|
+
plugins: html.map((h) => new HtmlWebpackPlugin(h))
|
|
136
|
+
});
|
|
134
137
|
return config;
|
|
135
138
|
};
|
|
136
139
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unpackjs/plugin-react",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@swc/helpers": "0.5.13",
|
|
32
32
|
"launch-editor": "2.9.1",
|
|
33
33
|
"html-webpack-plugin": "5.6.0",
|
|
34
|
-
"@unpackjs/shared": "^1.5.
|
|
34
|
+
"@unpackjs/shared": "^1.5.2"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"dev": "modern build --watch",
|