@unpackjs/plugin-react 3.2.1 → 3.2.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 +9 -12
- package/dist/index.js +10 -14
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -87,15 +87,14 @@ import '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().res
|
|
|
87
87
|
return null;
|
|
88
88
|
})(external_node_path_default().join(pagesRoot, filename));
|
|
89
89
|
if (indexFilePath) {
|
|
90
|
-
var _unpackConfig_html, _unpackConfig_html1, _unpackConfig_html2, _unpackConfig_html3, _unpackConfig_html4, _unpackConfig_html5, _unpackConfig_html6, _unpackConfig_html7, _unpackConfig_html8;
|
|
91
90
|
let filePath, pageConfig, pageConfig1 = (filePath = external_node_path_default().join(indexFilePath, '../config.json'), pageConfig = {}, external_node_fs_default().existsSync(filePath) && (pageConfig = JSON.parse(external_node_fs_default().readFileSync(filePath, 'utf-8'))), pageConfig), entryName = !0 === userOptions.lowerCase ? filename.toLowerCase() : filename;
|
|
92
91
|
pageConfig1.filename && (entryName = pageConfig1.filename.slice(0, -5)), entry[entryName] = {
|
|
93
92
|
import: [
|
|
94
93
|
indexFilePath
|
|
95
94
|
]
|
|
96
95
|
}, pageConfig1.template && (pageConfig1.template = external_node_path_default().join(indexFilePath, '../', pageConfig1.template)), html.push({
|
|
97
|
-
template:
|
|
98
|
-
templateContent:
|
|
96
|
+
template: unpackConfig.html?.template || void 0,
|
|
97
|
+
templateContent: unpackConfig.html?.templateContent || (unpackConfig.html?.template ? void 0 : core_namespaceObject.TEMPLATE_CONTENT),
|
|
99
98
|
minify: !1,
|
|
100
99
|
filename: `${entryName}.html`,
|
|
101
100
|
chunks: [
|
|
@@ -103,12 +102,12 @@ import '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().res
|
|
|
103
102
|
],
|
|
104
103
|
...pageConfig1,
|
|
105
104
|
templateParameters: {
|
|
106
|
-
mountId:
|
|
107
|
-
title: (0, core_namespaceObject.isFunction)(
|
|
105
|
+
mountId: unpackConfig.html?.mountId,
|
|
106
|
+
title: (0, core_namespaceObject.isFunction)(unpackConfig.html?.title) ? unpackConfig.html?.title({
|
|
108
107
|
entryName
|
|
109
|
-
}) :
|
|
110
|
-
headTag:
|
|
111
|
-
...
|
|
108
|
+
}) : unpackConfig.html?.title || '',
|
|
109
|
+
headTag: unpackConfig.html?.headTag || '',
|
|
110
|
+
...unpackConfig.html?.templateParameters,
|
|
112
111
|
...pageConfig1.templateParameters
|
|
113
112
|
}
|
|
114
113
|
});
|
|
@@ -119,10 +118,9 @@ import '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().res
|
|
|
119
118
|
});
|
|
120
119
|
return (0, core_namespaceObject.mergeConfig)(config, {
|
|
121
120
|
entry: ((entry)=>{
|
|
122
|
-
var _userOptions_globalImport, _unpackConfig_html;
|
|
123
121
|
let root = unpackConfig.root;
|
|
124
122
|
(0, core_namespaceObject.removeDir)(external_node_path_default().join(root, tempDirectory));
|
|
125
|
-
let globalImport =
|
|
123
|
+
let globalImport = userOptions.globalImport?.reduce((acc, curr)=>`${acc}\nimport '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().resolve(root, curr))}'`, '') || '', { layout } = userOptions, layoutImport = layout ? `import Layout from '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().resolve(root, layout))}'` : '', layoutJSX = layout ? '<Layout><App /></Layout>' : '<App />', rootElement = `document.getElementById('${unpackConfig.html?.mountId}')`, renderer = `ReactDOM.createRoot(${rootElement}).render(${layoutJSX})`;
|
|
126
124
|
return Object.entries(entry).forEach(([entryName, entryConfig])=>{
|
|
127
125
|
let filePath = external_node_path_default().join(root, tempDirectory, `${entryName}.jsx`), tpl = `
|
|
128
126
|
import React from 'react'
|
|
@@ -160,7 +158,6 @@ ${renderer}
|
|
|
160
158
|
return {
|
|
161
159
|
name: PLUGIN_NAME,
|
|
162
160
|
bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig })=>{
|
|
163
|
-
var _unpackConfig_performance_chunkSplit, _unpackConfig_performance;
|
|
164
161
|
let config = originalConfig;
|
|
165
162
|
unpackConfig.mpa && (config = applyMpaConfig({
|
|
166
163
|
config,
|
|
@@ -168,7 +165,7 @@ ${renderer}
|
|
|
168
165
|
})), (0, core_namespaceObject.isDev)() && clickToComponent && (config = await applyClickToComponentConfig({
|
|
169
166
|
config,
|
|
170
167
|
unpackConfig
|
|
171
|
-
})),
|
|
168
|
+
})), unpackConfig.performance?.chunkSplit?.strategy === 'split-by-experience' && (config = applySplitChunksConfig({
|
|
172
169
|
config
|
|
173
170
|
}));
|
|
174
171
|
let jsExclude = [
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import __rslib_shim_module__ from 'module';
|
|
2
2
|
let require = __rslib_shim_module__.createRequire(import.meta.url);
|
|
3
3
|
import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
|
|
4
|
-
import { dirname as __webpack_dirname__ } from "node:path";
|
|
5
|
-
import node_path from "node:path";
|
|
6
4
|
import plugin_react_refresh from "@rspack/plugin-react-refresh";
|
|
7
5
|
import { TEMPLATE_CONTENT, TEMP_DIR, addRestartCleaner, colors, esVersionToBrowserslist, getPathInJs, getPort, isDev, isDevServer, isFunction, isPlainObject, launchEditor, logger, mergeConfig as core_mergeConfig, removeDir, rspack } from "@unpackjs/core";
|
|
8
6
|
import node_fs from "node:fs";
|
|
@@ -55,7 +53,6 @@ import '${getPathInJs(node_path.resolve(Object.values(config.entry)[0]))}'
|
|
|
55
53
|
return {
|
|
56
54
|
name: PLUGIN_NAME,
|
|
57
55
|
bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig })=>{
|
|
58
|
-
var _unpackConfig_performance_chunkSplit, _unpackConfig_performance;
|
|
59
56
|
let config = originalConfig;
|
|
60
57
|
unpackConfig.mpa && (config = (({ config, unpackConfig })=>{
|
|
61
58
|
let start, entry, html, pagesRoot, tempDirectory = node_path.join(TEMP_DIR, 'mpa'), userOptions = isPlainObject(unpackConfig.mpa) ? unpackConfig.mpa : {}, { entry: entry1, html: html1 } = (start = performance.now(), entry = {}, html = [], pagesRoot = node_path.join(unpackConfig.root, 'src', 'pages'), node_fs.readdirSync(pagesRoot).forEach((filename)=>{
|
|
@@ -71,15 +68,14 @@ import '${getPathInJs(node_path.resolve(Object.values(config.entry)[0]))}'
|
|
|
71
68
|
return null;
|
|
72
69
|
})(node_path.join(pagesRoot, filename));
|
|
73
70
|
if (indexFilePath) {
|
|
74
|
-
var _unpackConfig_html, _unpackConfig_html1, _unpackConfig_html2, _unpackConfig_html3, _unpackConfig_html4, _unpackConfig_html5, _unpackConfig_html6, _unpackConfig_html7, _unpackConfig_html8;
|
|
75
71
|
let filePath, pageConfig, pageConfig1 = (filePath = node_path.join(indexFilePath, '../config.json'), pageConfig = {}, node_fs.existsSync(filePath) && (pageConfig = JSON.parse(node_fs.readFileSync(filePath, 'utf-8'))), pageConfig), entryName = !0 === userOptions.lowerCase ? filename.toLowerCase() : filename;
|
|
76
72
|
pageConfig1.filename && (entryName = pageConfig1.filename.slice(0, -5)), entry[entryName] = {
|
|
77
73
|
import: [
|
|
78
74
|
indexFilePath
|
|
79
75
|
]
|
|
80
76
|
}, pageConfig1.template && (pageConfig1.template = node_path.join(indexFilePath, '../', pageConfig1.template)), html.push({
|
|
81
|
-
template:
|
|
82
|
-
templateContent:
|
|
77
|
+
template: unpackConfig.html?.template || void 0,
|
|
78
|
+
templateContent: unpackConfig.html?.templateContent || (unpackConfig.html?.template ? void 0 : TEMPLATE_CONTENT),
|
|
83
79
|
minify: !1,
|
|
84
80
|
filename: `${entryName}.html`,
|
|
85
81
|
chunks: [
|
|
@@ -87,12 +83,12 @@ import '${getPathInJs(node_path.resolve(Object.values(config.entry)[0]))}'
|
|
|
87
83
|
],
|
|
88
84
|
...pageConfig1,
|
|
89
85
|
templateParameters: {
|
|
90
|
-
mountId:
|
|
91
|
-
title: isFunction(
|
|
86
|
+
mountId: unpackConfig.html?.mountId,
|
|
87
|
+
title: isFunction(unpackConfig.html?.title) ? unpackConfig.html?.title({
|
|
92
88
|
entryName
|
|
93
|
-
}) :
|
|
94
|
-
headTag:
|
|
95
|
-
...
|
|
89
|
+
}) : unpackConfig.html?.title || '',
|
|
90
|
+
headTag: unpackConfig.html?.headTag || '',
|
|
91
|
+
...unpackConfig.html?.templateParameters,
|
|
96
92
|
...pageConfig1.templateParameters
|
|
97
93
|
}
|
|
98
94
|
});
|
|
@@ -103,10 +99,9 @@ import '${getPathInJs(node_path.resolve(Object.values(config.entry)[0]))}'
|
|
|
103
99
|
});
|
|
104
100
|
return core_mergeConfig(config, {
|
|
105
101
|
entry: ((entry)=>{
|
|
106
|
-
var _userOptions_globalImport, _unpackConfig_html;
|
|
107
102
|
let root = unpackConfig.root;
|
|
108
103
|
removeDir(node_path.join(root, tempDirectory));
|
|
109
|
-
let globalImport =
|
|
104
|
+
let globalImport = userOptions.globalImport?.reduce((acc, curr)=>`${acc}\nimport '${getPathInJs(node_path.resolve(root, curr))}'`, '') || '', { layout } = userOptions, layoutImport = layout ? `import Layout from '${getPathInJs(node_path.resolve(root, layout))}'` : '', layoutJSX = layout ? '<Layout><App /></Layout>' : '<App />', rootElement = `document.getElementById('${unpackConfig.html?.mountId}')`, renderer = `ReactDOM.createRoot(${rootElement}).render(${layoutJSX})`;
|
|
110
105
|
return Object.entries(entry).forEach(([entryName, entryConfig])=>{
|
|
111
106
|
let filePath = node_path.join(root, tempDirectory, `${entryName}.jsx`), tpl = `
|
|
112
107
|
import React from 'react'
|
|
@@ -128,7 +123,7 @@ ${renderer}
|
|
|
128
123
|
})), isDev() && clickToComponent && (config = await applyClickToComponentConfig({
|
|
129
124
|
config,
|
|
130
125
|
unpackConfig
|
|
131
|
-
})),
|
|
126
|
+
})), unpackConfig.performance?.chunkSplit?.strategy === 'split-by-experience' && (config = (({ config })=>{
|
|
132
127
|
let currentConfig = config.optimization.splitChunks, extraGroups = {};
|
|
133
128
|
return extraGroups.react = {
|
|
134
129
|
name: 'lib-react',
|
|
@@ -230,4 +225,5 @@ ${renderer}
|
|
|
230
225
|
}
|
|
231
226
|
};
|
|
232
227
|
};
|
|
228
|
+
import node_path, { dirname as __webpack_dirname__ } from "node:path";
|
|
233
229
|
export { PLUGIN_NAME, pluginReact };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unpackjs/plugin-react",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.3",
|
|
4
4
|
"description": "React plugin for Unpack",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@rspack/plugin-react-refresh": "1.5.
|
|
27
|
+
"@rspack/plugin-react-refresh": "1.5.2",
|
|
28
28
|
"@svgr/webpack": "8.1.0",
|
|
29
29
|
"@swc/helpers": "0.5.17",
|
|
30
|
-
"react-refresh": "0.
|
|
30
|
+
"react-refresh": "0.18.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@unpackjs/core": "3.3.
|
|
33
|
+
"@unpackjs/core": "3.3.5"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@unpackjs/core": "3.x"
|