@unpackjs/plugin-react 2.2.0 → 3.0.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/dist/index.cjs +17 -21
- package/dist/index.js +36 -39
- package/dist/injectScript.js +1 -10
- package/dist-types/index.d.ts.map +1 -1
- package/dist-types/mpa.d.ts +1 -3
- package/dist-types/mpa.d.ts.map +1 -1
- package/package.json +5 -8
package/dist/index.cjs
CHANGED
|
@@ -25,8 +25,6 @@ __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_expo
|
|
|
25
25
|
});
|
|
26
26
|
let external_node_path_namespaceObject = require("node:path");
|
|
27
27
|
var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
|
|
28
|
-
let react_refresh_webpack_plugin_namespaceObject = require("@pmmmwh/react-refresh-webpack-plugin");
|
|
29
|
-
var react_refresh_webpack_plugin_default = __webpack_require__.n(react_refresh_webpack_plugin_namespaceObject);
|
|
30
28
|
let plugin_react_refresh_namespaceObject = require("@rspack/plugin-react-refresh");
|
|
31
29
|
var plugin_react_refresh_default = __webpack_require__.n(plugin_react_refresh_namespaceObject);
|
|
32
30
|
let core_namespaceObject = require("@unpackjs/core"), external_node_fs_namespaceObject = require("node:fs");
|
|
@@ -77,9 +75,9 @@ import '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().res
|
|
|
77
75
|
};
|
|
78
76
|
}
|
|
79
77
|
return config;
|
|
80
|
-
}, applyMpaConfig = ({ config, unpackConfig
|
|
78
|
+
}, applyMpaConfig = ({ config, unpackConfig })=>{
|
|
81
79
|
if (!unpackConfig.mpa) return config;
|
|
82
|
-
let
|
|
80
|
+
let tempDirectory = external_node_path_default().join(core_namespaceObject.TEMP_DIR, 'mpa'), userOptions = (0, core_namespaceObject.isPlainObject)(unpackConfig.mpa) ? unpackConfig.mpa : {}, { entry, html } = (()=>{
|
|
83
81
|
let start = performance.now(), entry = {}, html = [], pagesRoot = external_node_path_default().join(unpackConfig.root, 'src', 'pages');
|
|
84
82
|
return external_node_fs_default().readdirSync(pagesRoot).forEach((filename)=>{
|
|
85
83
|
if (filename.startsWith('.')) return;
|
|
@@ -104,8 +102,8 @@ import '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().res
|
|
|
104
102
|
indexFilePath
|
|
105
103
|
]
|
|
106
104
|
}, pageConfig.template && (pageConfig.template = external_node_path_default().join(indexFilePath, '../', pageConfig.template)), html.push({
|
|
107
|
-
template: (null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.template) ||
|
|
108
|
-
templateContent: (null == (_unpackConfig_html1 = unpackConfig.html) ? void 0 : _unpackConfig_html1.templateContent) || ((null == (_unpackConfig_html2 = unpackConfig.html) ? void 0 : _unpackConfig_html2.template) ?
|
|
105
|
+
template: (null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.template) || void 0,
|
|
106
|
+
templateContent: (null == (_unpackConfig_html1 = unpackConfig.html) ? void 0 : _unpackConfig_html1.templateContent) || ((null == (_unpackConfig_html2 = unpackConfig.html) ? void 0 : _unpackConfig_html2.template) ? void 0 : core_namespaceObject.TEMPLATE_CONTENT),
|
|
109
107
|
minify: !1,
|
|
110
108
|
filename: `${entryName}.html`,
|
|
111
109
|
chunks: [
|
|
@@ -128,7 +126,7 @@ import '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().res
|
|
|
128
126
|
html
|
|
129
127
|
};
|
|
130
128
|
})();
|
|
131
|
-
return config = mergeConfig(config, {
|
|
129
|
+
return config = (0, core_namespaceObject.mergeConfig)(config, {
|
|
132
130
|
entry: ((entry)=>{
|
|
133
131
|
var _userOptions_globalImport, _unpackConfig_html;
|
|
134
132
|
let root = unpackConfig.root;
|
|
@@ -147,7 +145,7 @@ ${renderer}
|
|
|
147
145
|
}), external_node_fs_default().writeFileSync(filePath, tpl, 'utf-8'), entryConfig.import[0] = filePath;
|
|
148
146
|
}), entry;
|
|
149
147
|
})(entry),
|
|
150
|
-
plugins: html.map((h)=>new
|
|
148
|
+
plugins: html.map((h)=>new core_namespaceObject.rspack.HtmlRspackPlugin(h))
|
|
151
149
|
});
|
|
152
150
|
}, applySplitChunksConfig = ({ config, unpackConfig })=>{
|
|
153
151
|
if ('split-by-experience' !== unpackConfig.performance.chunkSplit.strategy) return config;
|
|
@@ -172,22 +170,17 @@ ${renderer}
|
|
|
172
170
|
return {
|
|
173
171
|
name: PLUGIN_NAME,
|
|
174
172
|
bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig })=>{
|
|
175
|
-
let config = originalConfig
|
|
173
|
+
let config = originalConfig;
|
|
176
174
|
config = applyMpaConfig({
|
|
177
|
-
config,
|
|
178
|
-
unpackConfig,
|
|
179
|
-
mergeConfig,
|
|
180
|
-
HtmlPlugin: isRspack ? core_namespaceObject.rspack.HtmlRspackPlugin : core_namespaceObject.HtmlWebpackPlugin
|
|
181
|
-
}), (0, core_namespaceObject.isDev)() && clickToComponent && (config = await applyClickToComponentConfig({
|
|
182
175
|
config,
|
|
183
176
|
unpackConfig
|
|
184
|
-
})
|
|
177
|
+
}), (0, core_namespaceObject.isDev)() && clickToComponent && (config = await applyClickToComponentConfig({
|
|
185
178
|
config,
|
|
186
179
|
unpackConfig
|
|
187
|
-
});
|
|
180
|
+
}));
|
|
188
181
|
let jsExclude = [
|
|
189
182
|
/node_modules[\\/](?!\.unpack)/
|
|
190
|
-
],
|
|
183
|
+
], getSwcOptions = ({ tsx })=>({
|
|
191
184
|
jsc: {
|
|
192
185
|
parser: {
|
|
193
186
|
tsx,
|
|
@@ -207,7 +200,10 @@ ${renderer}
|
|
|
207
200
|
targets: core_namespaceObject.DEFAULT_BROWSERSLIST
|
|
208
201
|
}
|
|
209
202
|
});
|
|
210
|
-
return mergeConfig(config
|
|
203
|
+
return mergeConfig(config = applySplitChunksConfig({
|
|
204
|
+
config,
|
|
205
|
+
unpackConfig
|
|
206
|
+
}), {
|
|
211
207
|
module: {
|
|
212
208
|
rules: [
|
|
213
209
|
{
|
|
@@ -215,7 +211,7 @@ ${renderer}
|
|
|
215
211
|
exclude: jsExclude,
|
|
216
212
|
use: [
|
|
217
213
|
{
|
|
218
|
-
loader:
|
|
214
|
+
loader: 'builtin:swc-loader',
|
|
219
215
|
options: getSwcOptions({
|
|
220
216
|
tsx: !1
|
|
221
217
|
})
|
|
@@ -227,7 +223,7 @@ ${renderer}
|
|
|
227
223
|
exclude: jsExclude,
|
|
228
224
|
use: [
|
|
229
225
|
{
|
|
230
|
-
loader:
|
|
226
|
+
loader: 'builtin:swc-loader',
|
|
231
227
|
options: getSwcOptions({
|
|
232
228
|
tsx: !0
|
|
233
229
|
})
|
|
@@ -254,7 +250,7 @@ ${renderer}
|
|
|
254
250
|
]
|
|
255
251
|
},
|
|
256
252
|
plugins: [
|
|
257
|
-
(0, core_namespaceObject.isDevServer)() && new
|
|
253
|
+
(0, core_namespaceObject.isDevServer)() && new (plugin_react_refresh_default())({
|
|
258
254
|
overlay: !1
|
|
259
255
|
})
|
|
260
256
|
].filter(Boolean),
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,8 @@ let require = __rslib_shim_module__.createRequire(import.meta.url);
|
|
|
3
3
|
import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
|
|
4
4
|
import { dirname as __webpack_dirname__ } from "node:path";
|
|
5
5
|
import node_path from "node:path";
|
|
6
|
-
import react_refresh_webpack_plugin from "@pmmmwh/react-refresh-webpack-plugin";
|
|
7
6
|
import plugin_react_refresh from "@rspack/plugin-react-refresh";
|
|
8
|
-
import { DEFAULT_BROWSERSLIST,
|
|
7
|
+
import { DEFAULT_BROWSERSLIST, TEMPLATE_CONTENT, TEMP_DIR, colors, getPathInJs, getPort, isDev, isDevServer, isFunction, isPlainObject, logger, mergeConfig as core_mergeConfig, removeDir, restartCleaners, rspack } from "@unpackjs/core";
|
|
9
8
|
import node_fs from "node:fs";
|
|
10
9
|
import node_http from "node:http";
|
|
11
10
|
import launch_editor from "launch-editor";
|
|
@@ -57,10 +56,10 @@ import '${getPathInJs(node_path.resolve(Object.values(config.entry)[0]))}'
|
|
|
57
56
|
return {
|
|
58
57
|
name: PLUGIN_NAME,
|
|
59
58
|
bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig })=>{
|
|
60
|
-
let config = originalConfig
|
|
61
|
-
config = (({ config, unpackConfig
|
|
59
|
+
let config = originalConfig;
|
|
60
|
+
config = (({ config, unpackConfig })=>{
|
|
62
61
|
if (!unpackConfig.mpa) return config;
|
|
63
|
-
let
|
|
62
|
+
let tempDirectory = node_path.join(TEMP_DIR, 'mpa'), userOptions = isPlainObject(unpackConfig.mpa) ? unpackConfig.mpa : {}, { entry, html } = (()=>{
|
|
64
63
|
let start = performance.now(), entry = {}, html = [], pagesRoot = node_path.join(unpackConfig.root, 'src', 'pages');
|
|
65
64
|
return node_fs.readdirSync(pagesRoot).forEach((filename)=>{
|
|
66
65
|
if (filename.startsWith('.')) return;
|
|
@@ -85,8 +84,8 @@ import '${getPathInJs(node_path.resolve(Object.values(config.entry)[0]))}'
|
|
|
85
84
|
indexFilePath
|
|
86
85
|
]
|
|
87
86
|
}, pageConfig.template && (pageConfig.template = node_path.join(indexFilePath, '../', pageConfig.template)), html.push({
|
|
88
|
-
template: (null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.template) ||
|
|
89
|
-
templateContent: (null == (_unpackConfig_html1 = unpackConfig.html) ? void 0 : _unpackConfig_html1.templateContent) || ((null == (_unpackConfig_html2 = unpackConfig.html) ? void 0 : _unpackConfig_html2.template) ?
|
|
87
|
+
template: (null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.template) || void 0,
|
|
88
|
+
templateContent: (null == (_unpackConfig_html1 = unpackConfig.html) ? void 0 : _unpackConfig_html1.templateContent) || ((null == (_unpackConfig_html2 = unpackConfig.html) ? void 0 : _unpackConfig_html2.template) ? void 0 : TEMPLATE_CONTENT),
|
|
90
89
|
minify: !1,
|
|
91
90
|
filename: `${entryName}.html`,
|
|
92
91
|
chunks: [
|
|
@@ -109,7 +108,7 @@ import '${getPathInJs(node_path.resolve(Object.values(config.entry)[0]))}'
|
|
|
109
108
|
html
|
|
110
109
|
};
|
|
111
110
|
})();
|
|
112
|
-
return config =
|
|
111
|
+
return config = core_mergeConfig(config, {
|
|
113
112
|
entry: ((entry)=>{
|
|
114
113
|
var _userOptions_globalImport, _unpackConfig_html;
|
|
115
114
|
let root = unpackConfig.root;
|
|
@@ -128,41 +127,18 @@ ${renderer}
|
|
|
128
127
|
}), node_fs.writeFileSync(filePath, tpl, 'utf-8'), entryConfig.import[0] = filePath;
|
|
129
128
|
}), entry;
|
|
130
129
|
})(entry),
|
|
131
|
-
plugins: html.map((h)=>new
|
|
130
|
+
plugins: html.map((h)=>new rspack.HtmlRspackPlugin(h))
|
|
132
131
|
});
|
|
133
132
|
})({
|
|
134
|
-
config,
|
|
135
|
-
unpackConfig,
|
|
136
|
-
mergeConfig,
|
|
137
|
-
HtmlPlugin: isRspack ? rspack.HtmlRspackPlugin : HtmlWebpackPlugin
|
|
138
|
-
}), isDev() && clickToComponent && (config = await applyClickToComponentConfig({
|
|
139
133
|
config,
|
|
140
134
|
unpackConfig
|
|
141
|
-
})
|
|
142
|
-
if ('split-by-experience' !== unpackConfig.performance.chunkSplit.strategy) return config;
|
|
143
|
-
let currentConfig = config.optimization.splitChunks, extraGroups = {};
|
|
144
|
-
return extraGroups.react = {
|
|
145
|
-
name: 'lib-react',
|
|
146
|
-
test: isDevServer() ? /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/,
|
|
147
|
-
priority: 0
|
|
148
|
-
}, extraGroups.router = {
|
|
149
|
-
name: 'lib-router',
|
|
150
|
-
test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
|
|
151
|
-
priority: 0
|
|
152
|
-
}, config.optimization.splitChunks = {
|
|
153
|
-
...currentConfig,
|
|
154
|
-
cacheGroups: {
|
|
155
|
-
...extraGroups,
|
|
156
|
-
...currentConfig.cacheGroups
|
|
157
|
-
}
|
|
158
|
-
}, config;
|
|
159
|
-
})({
|
|
135
|
+
}), isDev() && clickToComponent && (config = await applyClickToComponentConfig({
|
|
160
136
|
config,
|
|
161
137
|
unpackConfig
|
|
162
|
-
});
|
|
138
|
+
}));
|
|
163
139
|
let jsExclude = [
|
|
164
140
|
/node_modules[\\/](?!\.unpack)/
|
|
165
|
-
],
|
|
141
|
+
], getSwcOptions = ({ tsx })=>({
|
|
166
142
|
jsc: {
|
|
167
143
|
parser: {
|
|
168
144
|
tsx,
|
|
@@ -182,7 +158,28 @@ ${renderer}
|
|
|
182
158
|
targets: DEFAULT_BROWSERSLIST
|
|
183
159
|
}
|
|
184
160
|
});
|
|
185
|
-
return mergeConfig(config, {
|
|
161
|
+
return mergeConfig(config = (({ config, unpackConfig })=>{
|
|
162
|
+
if ('split-by-experience' !== unpackConfig.performance.chunkSplit.strategy) return config;
|
|
163
|
+
let currentConfig = config.optimization.splitChunks, extraGroups = {};
|
|
164
|
+
return extraGroups.react = {
|
|
165
|
+
name: 'lib-react',
|
|
166
|
+
test: isDevServer() ? /node_modules[\\/](?:react|react-dom|scheduler|react-refresh|@rspack[\\/]plugin-react-refresh)[\\/]/ : /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/,
|
|
167
|
+
priority: 0
|
|
168
|
+
}, extraGroups.router = {
|
|
169
|
+
name: 'lib-router',
|
|
170
|
+
test: /node_modules[\\/](?:react-router|react-router-dom|history|@remix-run[\\/]router)[\\/]/,
|
|
171
|
+
priority: 0
|
|
172
|
+
}, config.optimization.splitChunks = {
|
|
173
|
+
...currentConfig,
|
|
174
|
+
cacheGroups: {
|
|
175
|
+
...extraGroups,
|
|
176
|
+
...currentConfig.cacheGroups
|
|
177
|
+
}
|
|
178
|
+
}, config;
|
|
179
|
+
})({
|
|
180
|
+
config,
|
|
181
|
+
unpackConfig
|
|
182
|
+
}), {
|
|
186
183
|
module: {
|
|
187
184
|
rules: [
|
|
188
185
|
{
|
|
@@ -190,7 +187,7 @@ ${renderer}
|
|
|
190
187
|
exclude: jsExclude,
|
|
191
188
|
use: [
|
|
192
189
|
{
|
|
193
|
-
loader:
|
|
190
|
+
loader: 'builtin:swc-loader',
|
|
194
191
|
options: getSwcOptions({
|
|
195
192
|
tsx: !1
|
|
196
193
|
})
|
|
@@ -202,7 +199,7 @@ ${renderer}
|
|
|
202
199
|
exclude: jsExclude,
|
|
203
200
|
use: [
|
|
204
201
|
{
|
|
205
|
-
loader:
|
|
202
|
+
loader: 'builtin:swc-loader',
|
|
206
203
|
options: getSwcOptions({
|
|
207
204
|
tsx: !0
|
|
208
205
|
})
|
|
@@ -229,7 +226,7 @@ ${renderer}
|
|
|
229
226
|
]
|
|
230
227
|
},
|
|
231
228
|
plugins: [
|
|
232
|
-
isDevServer() && new
|
|
229
|
+
isDevServer() && new plugin_react_refresh({
|
|
233
230
|
overlay: !1
|
|
234
231
|
})
|
|
235
232
|
].filter(Boolean),
|
package/dist/injectScript.js
CHANGED
|
@@ -53,16 +53,7 @@ function getClosestNodeFromFiber(fiber) {
|
|
|
53
53
|
}
|
|
54
54
|
function openEditor() {
|
|
55
55
|
if (!currentDebugSource) return;
|
|
56
|
-
let port = window.CLICK_TO_COMPONENT.port, { fileName, lineNumber, columnNumber } = currentDebugSource, url =
|
|
57
|
-
'http://localhost:',
|
|
58
|
-
port,
|
|
59
|
-
'/?file=',
|
|
60
|
-
fileName,
|
|
61
|
-
'&line=',
|
|
62
|
-
lineNumber,
|
|
63
|
-
'&column=',
|
|
64
|
-
columnNumber
|
|
65
|
-
].join(''), xhr = new XMLHttpRequest();
|
|
56
|
+
let port = window.CLICK_TO_COMPONENT.port, { fileName, lineNumber, columnNumber } = currentDebugSource, url = "http://localhost:" + port + "/?file=" + fileName + "&line=" + lineNumber + "&column=" + columnNumber, xhr = new XMLHttpRequest();
|
|
66
57
|
xhr.open('GET', url, !0), xhr.send(), xhr.addEventListener('error', ()=>{
|
|
67
58
|
document.createElement('img').src = url;
|
|
68
59
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4C,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAK5F,eAAO,MAAM,WAAW,iBAAiB,CAAA;AAEzC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AACD,eAAO,MAAM,WAAW,GAAI,UAAS,kBAAuB,KAAG,YAsF9D,CAAA"}
|
package/dist-types/mpa.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { type BundlerConfiguration, type UnpackConfig } from '@unpackjs/core';
|
|
2
|
-
export declare const applyMpaConfig: ({ config, unpackConfig,
|
|
2
|
+
export declare const applyMpaConfig: ({ config, unpackConfig, }: {
|
|
3
3
|
config: BundlerConfiguration;
|
|
4
4
|
unpackConfig: UnpackConfig;
|
|
5
|
-
mergeConfig: (...configs: BundlerConfiguration[]) => BundlerConfiguration;
|
|
6
|
-
HtmlPlugin: any;
|
|
7
5
|
}) => BundlerConfiguration;
|
|
8
6
|
//# sourceMappingURL=mpa.d.ts.map
|
package/dist-types/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,
|
|
1
|
+
{"version":3,"file":"mpa.d.ts","sourceRoot":"","sources":["../src/mpa.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EAYzB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAA;AAYvB,eAAO,MAAM,cAAc,GAAI,2BAG5B;IACD,MAAM,EAAE,oBAAoB,CAAA;IAC5B,YAAY,EAAE,YAAY,CAAA;CAC3B,KAAG,oBA6GH,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unpackjs/plugin-react",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "React plugin for Unpack",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -24,20 +24,17 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@pmmmwh/react-refresh-webpack-plugin": "0.6.1",
|
|
28
27
|
"@rspack/plugin-react-refresh": "1.4.3",
|
|
29
28
|
"@svgr/webpack": "8.1.0",
|
|
30
|
-
"@swc/core": "1.12.9",
|
|
31
29
|
"@swc/helpers": "0.5.17",
|
|
32
30
|
"launch-editor": "2.10.0",
|
|
33
|
-
"react-refresh": "0.17.0"
|
|
34
|
-
"swc-loader": "0.2.6"
|
|
31
|
+
"react-refresh": "0.17.0"
|
|
35
32
|
},
|
|
36
33
|
"devDependencies": {
|
|
37
|
-
"@unpackjs/core": "
|
|
34
|
+
"@unpackjs/core": "3.0.0"
|
|
38
35
|
},
|
|
39
36
|
"peerDependencies": {
|
|
40
|
-
"@unpackjs/core": "
|
|
37
|
+
"@unpackjs/core": "3.x"
|
|
41
38
|
},
|
|
42
39
|
"scripts": {
|
|
43
40
|
"dev": "rslib build --watch",
|