@unpackjs/plugin-react 2.2.0 → 3.0.1
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 +18 -24
- package/dist/index.js +18 -23
- 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/dist-types/splitChunks.d.ts +2 -3
- package/dist-types/splitChunks.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,8 @@ import '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().res
|
|
|
77
75
|
};
|
|
78
76
|
}
|
|
79
77
|
return config;
|
|
80
|
-
}, applyMpaConfig = ({ config, unpackConfig
|
|
81
|
-
|
|
82
|
-
let isRspack = 'rspack' === unpackConfig.bundler, tempDirectory = external_node_path_default().join(core_namespaceObject.TEMP_DIR, 'mpa'), userOptions = (0, core_namespaceObject.isPlainObject)(unpackConfig.mpa) ? unpackConfig.mpa : {}, { entry, html } = (()=>{
|
|
78
|
+
}, applyMpaConfig = ({ config, unpackConfig })=>{
|
|
79
|
+
let tempDirectory = external_node_path_default().join(core_namespaceObject.TEMP_DIR, 'mpa'), userOptions = (0, core_namespaceObject.isPlainObject)(unpackConfig.mpa) ? unpackConfig.mpa : {}, { entry, html } = (()=>{
|
|
83
80
|
let start = performance.now(), entry = {}, html = [], pagesRoot = external_node_path_default().join(unpackConfig.root, 'src', 'pages');
|
|
84
81
|
return external_node_fs_default().readdirSync(pagesRoot).forEach((filename)=>{
|
|
85
82
|
if (filename.startsWith('.')) return;
|
|
@@ -104,8 +101,8 @@ import '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().res
|
|
|
104
101
|
indexFilePath
|
|
105
102
|
]
|
|
106
103
|
}, 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) ?
|
|
104
|
+
template: (null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.template) || void 0,
|
|
105
|
+
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
106
|
minify: !1,
|
|
110
107
|
filename: `${entryName}.html`,
|
|
111
108
|
chunks: [
|
|
@@ -128,7 +125,7 @@ import '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().res
|
|
|
128
125
|
html
|
|
129
126
|
};
|
|
130
127
|
})();
|
|
131
|
-
return config = mergeConfig(config, {
|
|
128
|
+
return config = (0, core_namespaceObject.mergeConfig)(config, {
|
|
132
129
|
entry: ((entry)=>{
|
|
133
130
|
var _userOptions_globalImport, _unpackConfig_html;
|
|
134
131
|
let root = unpackConfig.root;
|
|
@@ -147,10 +144,9 @@ ${renderer}
|
|
|
147
144
|
}), external_node_fs_default().writeFileSync(filePath, tpl, 'utf-8'), entryConfig.import[0] = filePath;
|
|
148
145
|
}), entry;
|
|
149
146
|
})(entry),
|
|
150
|
-
plugins: html.map((h)=>new
|
|
147
|
+
plugins: html.map((h)=>new core_namespaceObject.rspack.HtmlRspackPlugin(h))
|
|
151
148
|
});
|
|
152
|
-
}, applySplitChunksConfig = ({ config
|
|
153
|
-
if ('split-by-experience' !== unpackConfig.performance.chunkSplit.strategy) return config;
|
|
149
|
+
}, applySplitChunksConfig = ({ config })=>{
|
|
154
150
|
let currentConfig = config.optimization.splitChunks, extraGroups = {};
|
|
155
151
|
return extraGroups.react = {
|
|
156
152
|
name: 'lib-react',
|
|
@@ -172,22 +168,20 @@ ${renderer}
|
|
|
172
168
|
return {
|
|
173
169
|
name: PLUGIN_NAME,
|
|
174
170
|
bundlerConfig: async (originalConfig, { unpackConfig, mergeConfig })=>{
|
|
175
|
-
|
|
176
|
-
config =
|
|
177
|
-
|
|
178
|
-
unpackConfig,
|
|
179
|
-
mergeConfig,
|
|
180
|
-
HtmlPlugin: isRspack ? core_namespaceObject.rspack.HtmlRspackPlugin : core_namespaceObject.HtmlWebpackPlugin
|
|
181
|
-
}), (0, core_namespaceObject.isDev)() && clickToComponent && (config = await applyClickToComponentConfig({
|
|
171
|
+
var _unpackConfig_performance_chunkSplit, _unpackConfig_performance;
|
|
172
|
+
let config = originalConfig;
|
|
173
|
+
unpackConfig.mpa && (config = applyMpaConfig({
|
|
182
174
|
config,
|
|
183
175
|
unpackConfig
|
|
184
|
-
})), config =
|
|
176
|
+
})), (0, core_namespaceObject.isDev)() && clickToComponent && (config = await applyClickToComponentConfig({
|
|
185
177
|
config,
|
|
186
178
|
unpackConfig
|
|
187
|
-
})
|
|
179
|
+
})), (null == (_unpackConfig_performance = unpackConfig.performance) || null == (_unpackConfig_performance_chunkSplit = _unpackConfig_performance.chunkSplit) ? void 0 : _unpackConfig_performance_chunkSplit.strategy) === 'split-by-experience' && (config = applySplitChunksConfig({
|
|
180
|
+
config
|
|
181
|
+
}));
|
|
188
182
|
let jsExclude = [
|
|
189
183
|
/node_modules[\\/](?!\.unpack)/
|
|
190
|
-
],
|
|
184
|
+
], getSwcOptions = ({ tsx })=>({
|
|
191
185
|
jsc: {
|
|
192
186
|
parser: {
|
|
193
187
|
tsx,
|
|
@@ -215,7 +209,7 @@ ${renderer}
|
|
|
215
209
|
exclude: jsExclude,
|
|
216
210
|
use: [
|
|
217
211
|
{
|
|
218
|
-
loader:
|
|
212
|
+
loader: 'builtin:swc-loader',
|
|
219
213
|
options: getSwcOptions({
|
|
220
214
|
tsx: !1
|
|
221
215
|
})
|
|
@@ -227,7 +221,7 @@ ${renderer}
|
|
|
227
221
|
exclude: jsExclude,
|
|
228
222
|
use: [
|
|
229
223
|
{
|
|
230
|
-
loader:
|
|
224
|
+
loader: 'builtin:swc-loader',
|
|
231
225
|
options: getSwcOptions({
|
|
232
226
|
tsx: !0
|
|
233
227
|
})
|
|
@@ -254,7 +248,7 @@ ${renderer}
|
|
|
254
248
|
]
|
|
255
249
|
},
|
|
256
250
|
plugins: [
|
|
257
|
-
(0, core_namespaceObject.isDevServer)() && new
|
|
251
|
+
(0, core_namespaceObject.isDevServer)() && new (plugin_react_refresh_default())({
|
|
258
252
|
overlay: !1
|
|
259
253
|
})
|
|
260
254
|
].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
|
-
|
|
61
|
-
config =
|
|
62
|
-
|
|
63
|
-
let
|
|
59
|
+
var _unpackConfig_performance_chunkSplit, _unpackConfig_performance;
|
|
60
|
+
let config = originalConfig;
|
|
61
|
+
unpackConfig.mpa && (config = (({ config, unpackConfig })=>{
|
|
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,18 +127,15 @@ ${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
133
|
config,
|
|
135
|
-
unpackConfig
|
|
136
|
-
|
|
137
|
-
HtmlPlugin: isRspack ? rspack.HtmlRspackPlugin : HtmlWebpackPlugin
|
|
138
|
-
}), isDev() && clickToComponent && (config = await applyClickToComponentConfig({
|
|
134
|
+
unpackConfig
|
|
135
|
+
})), isDev() && clickToComponent && (config = await applyClickToComponentConfig({
|
|
139
136
|
config,
|
|
140
137
|
unpackConfig
|
|
141
|
-
})), config = (({ config
|
|
142
|
-
if ('split-by-experience' !== unpackConfig.performance.chunkSplit.strategy) return config;
|
|
138
|
+
})), (null == (_unpackConfig_performance = unpackConfig.performance) || null == (_unpackConfig_performance_chunkSplit = _unpackConfig_performance.chunkSplit) ? void 0 : _unpackConfig_performance_chunkSplit.strategy) === 'split-by-experience' && (config = (({ config })=>{
|
|
143
139
|
let currentConfig = config.optimization.splitChunks, extraGroups = {};
|
|
144
140
|
return extraGroups.react = {
|
|
145
141
|
name: 'lib-react',
|
|
@@ -157,12 +153,11 @@ ${renderer}
|
|
|
157
153
|
}
|
|
158
154
|
}, config;
|
|
159
155
|
})({
|
|
160
|
-
config
|
|
161
|
-
|
|
162
|
-
});
|
|
156
|
+
config
|
|
157
|
+
}));
|
|
163
158
|
let jsExclude = [
|
|
164
159
|
/node_modules[\\/](?!\.unpack)/
|
|
165
|
-
],
|
|
160
|
+
], getSwcOptions = ({ tsx })=>({
|
|
166
161
|
jsc: {
|
|
167
162
|
parser: {
|
|
168
163
|
tsx,
|
|
@@ -190,7 +185,7 @@ ${renderer}
|
|
|
190
185
|
exclude: jsExclude,
|
|
191
186
|
use: [
|
|
192
187
|
{
|
|
193
|
-
loader:
|
|
188
|
+
loader: 'builtin:swc-loader',
|
|
194
189
|
options: getSwcOptions({
|
|
195
190
|
tsx: !1
|
|
196
191
|
})
|
|
@@ -202,7 +197,7 @@ ${renderer}
|
|
|
202
197
|
exclude: jsExclude,
|
|
203
198
|
use: [
|
|
204
199
|
{
|
|
205
|
-
loader:
|
|
200
|
+
loader: 'builtin:swc-loader',
|
|
206
201
|
options: getSwcOptions({
|
|
207
202
|
tsx: !0
|
|
208
203
|
})
|
|
@@ -229,7 +224,7 @@ ${renderer}
|
|
|
229
224
|
]
|
|
230
225
|
},
|
|
231
226
|
plugins: [
|
|
232
|
-
isDevServer() && new
|
|
227
|
+
isDevServer() && new plugin_react_refresh({
|
|
233
228
|
overlay: !1
|
|
234
229
|
})
|
|
235
230
|
].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,YA0F9D,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,oBA4GH,CAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { type BundlerConfiguration
|
|
2
|
-
export declare const applySplitChunksConfig: ({ config
|
|
1
|
+
import { type BundlerConfiguration } from '@unpackjs/core';
|
|
2
|
+
export declare const applySplitChunksConfig: ({ config }: {
|
|
3
3
|
config: BundlerConfiguration;
|
|
4
|
-
unpackConfig: UnpackConfig;
|
|
5
4
|
}) => import("@rspack/core").RspackOptions;
|
|
6
5
|
//# sourceMappingURL=splitChunks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splitChunks.d.ts","sourceRoot":"","sources":["../src/splitChunks.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"splitChunks.d.ts","sourceRoot":"","sources":["../src/splitChunks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAiC,MAAM,gBAAgB,CAAA;AAEzF,eAAO,MAAM,sBAAsB,GAAI,YAAY;IAAE,MAAM,EAAE,oBAAoB,CAAA;CAAE,yCAwBlF,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.1",
|
|
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.1.1"
|
|
38
35
|
},
|
|
39
36
|
"peerDependencies": {
|
|
40
|
-
"@unpackjs/core": "
|
|
37
|
+
"@unpackjs/core": "3.x"
|
|
41
38
|
},
|
|
42
39
|
"scripts": {
|
|
43
40
|
"dev": "rslib build --watch",
|