@unpackjs/plugin-react 2.1.0 → 2.2.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 +182 -81
- package/dist/index.js +155 -41
- package/dist/injectScript.js +82 -0
- package/{dist → dist-types}/index.d.ts +0 -1
- package/dist-types/index.d.ts.map +1 -0
- package/{dist → dist-types}/mpa.d.ts.map +1 -1
- package/package.json +8 -11
- package/dist/click-to-component/index.cjs +0 -110
- package/dist/click-to-component/index.js +0 -68
- package/dist/click-to-component/injectScript.js +0 -116
- package/dist/index.d.ts.map +0 -1
- package/dist/mpa.cjs +0 -152
- package/dist/mpa.js +0 -109
- package/dist/react-compiler-loader/index.cjs +0 -95
- package/dist/react-compiler-loader/index.d.ts +0 -5
- package/dist/react-compiler-loader/index.d.ts.map +0 -1
- package/dist/react-compiler-loader/index.js +0 -51
- package/dist/splitChunks.cjs +0 -59
- package/dist/splitChunks.js +0 -27
- /package/{dist → dist-types}/click-to-component/index.d.ts +0 -0
- /package/{dist → dist-types}/click-to-component/index.d.ts.map +0 -0
- /package/{dist → dist-types}/mpa.d.ts +0 -0
- /package/{dist → dist-types}/splitChunks.d.ts +0 -0
- /package/{dist → dist-types}/splitChunks.d.ts.map +0 -0
|
@@ -2,7 +2,6 @@ import { type UnpackPlugin } from '@unpackjs/core';
|
|
|
2
2
|
export declare const PLUGIN_NAME = "unpack:react";
|
|
3
3
|
export type PluginReactOptions = {
|
|
4
4
|
clickToComponent?: boolean;
|
|
5
|
-
reactCompiler?: boolean;
|
|
6
5
|
};
|
|
7
6
|
export declare const pluginReact: (options?: PluginReactOptions) => UnpackPlugin;
|
|
8
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAML,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAA;AAKvB,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mpa.d.ts","sourceRoot":"","sources":["../src/mpa.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EAUzB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAA;AAYvB,eAAO,MAAM,cAAc,GAAI,oDAK5B;IACD,MAAM,EAAE,oBAAoB,CAAA;IAC5B,YAAY,EAAE,YAAY,CAAA;IAC1B,WAAW,EAAE,CAAC,GAAG,OAAO,EAAE,oBAAoB,EAAE,KAAK,oBAAoB,CAAA;IACzE,UAAU,EAAE,GAAG,CAAA;CAChB,KAAG,
|
|
1
|
+
{"version":3,"file":"mpa.d.ts","sourceRoot":"","sources":["../src/mpa.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EAUzB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAA;AAYvB,eAAO,MAAM,cAAc,GAAI,oDAK5B;IACD,MAAM,EAAE,oBAAoB,CAAA;IAC5B,YAAY,EAAE,YAAY,CAAA;IAC1B,WAAW,EAAE,CAAC,GAAG,OAAO,EAAE,oBAAoB,EAAE,KAAK,oBAAoB,CAAA;IACzE,UAAU,EAAE,GAAG,CAAA;CAChB,KAAG,oBA8GH,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,43 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unpackjs/plugin-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
8
|
+
"types": "./dist-types/index.d.ts",
|
|
9
9
|
"import": "./dist/index.js",
|
|
10
10
|
"require": "./dist/index.cjs"
|
|
11
|
-
}
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
12
13
|
},
|
|
13
14
|
"main": "./dist/index.cjs",
|
|
14
|
-
"types": "./dist/index.d.ts",
|
|
15
|
+
"types": "./dist-types/index.d.ts",
|
|
15
16
|
"keywords": [],
|
|
16
17
|
"authors": [],
|
|
17
18
|
"license": "MIT",
|
|
18
19
|
"files": [
|
|
19
20
|
"dist",
|
|
20
|
-
"
|
|
21
|
+
"dist-types"
|
|
21
22
|
],
|
|
22
23
|
"publishConfig": {
|
|
23
24
|
"access": "public"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"@babel/core": "7.27.4",
|
|
27
|
-
"@babel/plugin-proposal-decorators": "7.27.1",
|
|
28
|
-
"@babel/plugin-transform-class-properties": "7.27.1",
|
|
29
27
|
"@pmmmwh/react-refresh-webpack-plugin": "0.6.1",
|
|
30
28
|
"@rspack/plugin-react-refresh": "1.4.3",
|
|
31
29
|
"@svgr/webpack": "8.1.0",
|
|
32
|
-
"@swc/core": "1.12.
|
|
30
|
+
"@swc/core": "1.12.9",
|
|
33
31
|
"@swc/helpers": "0.5.17",
|
|
34
|
-
"babel-plugin-react-compiler": "latest",
|
|
35
32
|
"launch-editor": "2.10.0",
|
|
36
33
|
"react-refresh": "0.17.0",
|
|
37
34
|
"swc-loader": "0.2.6"
|
|
38
35
|
},
|
|
39
36
|
"devDependencies": {
|
|
40
|
-
"@unpackjs/core": "2.3
|
|
37
|
+
"@unpackjs/core": "2.4.3"
|
|
41
38
|
},
|
|
42
39
|
"peerDependencies": {
|
|
43
40
|
"@unpackjs/core": "2.x"
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
|
-
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: definition[key]
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
})();
|
|
20
|
-
(()=>{
|
|
21
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
-
})();
|
|
23
|
-
(()=>{
|
|
24
|
-
__webpack_require__.r = (exports1)=>{
|
|
25
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
-
value: 'Module'
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
-
value: true
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
})();
|
|
33
|
-
var __webpack_exports__ = {};
|
|
34
|
-
__webpack_require__.r(__webpack_exports__);
|
|
35
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
applyClickToComponentConfig: ()=>applyClickToComponentConfig
|
|
37
|
-
});
|
|
38
|
-
const external_node_fs_namespaceObject = require("node:fs");
|
|
39
|
-
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
40
|
-
const external_node_http_namespaceObject = require("node:http");
|
|
41
|
-
var external_node_http_default = /*#__PURE__*/ __webpack_require__.n(external_node_http_namespaceObject);
|
|
42
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
43
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
44
|
-
const core_namespaceObject = require("@unpackjs/core");
|
|
45
|
-
const external_launch_editor_namespaceObject = require("launch-editor");
|
|
46
|
-
var external_launch_editor_default = /*#__PURE__*/ __webpack_require__.n(external_launch_editor_namespaceObject);
|
|
47
|
-
const createServer = ()=>new Promise((resolve)=>{
|
|
48
|
-
const server = external_node_http_default().createServer((req, res)=>{
|
|
49
|
-
const params = new URLSearchParams(req.url.slice(1));
|
|
50
|
-
const file = decodeURIComponent(params.get('file'));
|
|
51
|
-
const line = Number(params.get('line'));
|
|
52
|
-
const column = Number(params.get('column'));
|
|
53
|
-
res.writeHead(200, {
|
|
54
|
-
'Access-Control-Allow-Origin': '*',
|
|
55
|
-
'Access-Control-Allow-Methods': '*',
|
|
56
|
-
'Access-Control-Allow-Headers': '*',
|
|
57
|
-
'Access-Control-Allow-Private-Network': 'true'
|
|
58
|
-
});
|
|
59
|
-
res.end('ok');
|
|
60
|
-
external_launch_editor_default()(`${file}:${line}:${column}`);
|
|
61
|
-
});
|
|
62
|
-
(0, core_namespaceObject.getPort)().then((port)=>{
|
|
63
|
-
server.listen(port, ()=>{
|
|
64
|
-
resolve({
|
|
65
|
-
port
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
core_namespaceObject.restartCleaners.push(()=>new Promise((resolve)=>server.close(()=>resolve())));
|
|
70
|
-
});
|
|
71
|
-
const applyClickToComponentConfig = async ({ config, unpackConfig })=>{
|
|
72
|
-
const { port } = await createServer();
|
|
73
|
-
const injectScript = external_node_fs_default().readFileSync(external_node_path_default().resolve(__dirname, './injectScript.js'), 'utf-8');
|
|
74
|
-
const scriptTpl = `
|
|
75
|
-
if (!document.querySelector('#__click-to-component__')) {
|
|
76
|
-
const script = document.createElement('script')
|
|
77
|
-
window['CLICK_TO_COMPONENT'] = { port: ${port} }
|
|
78
|
-
script.setAttribute('type', 'text/javascript')
|
|
79
|
-
script.textContent = \`${injectScript}\`
|
|
80
|
-
document.body.appendChild(script)
|
|
81
|
-
}`;
|
|
82
|
-
if (unpackConfig.mpa) Object.values(config.entry).forEach((entryConfig)=>{
|
|
83
|
-
const filePath = entryConfig.import[0];
|
|
84
|
-
const content = external_node_fs_default().readFileSync(filePath, 'utf-8');
|
|
85
|
-
external_node_fs_default().writeFileSync(filePath, `${scriptTpl}\n${content}`, 'utf-8');
|
|
86
|
-
});
|
|
87
|
-
else {
|
|
88
|
-
const realEntryPath = external_node_path_default().resolve(config.context, core_namespaceObject.TEMP_DIR, 'entries', `index.${port}.jsx`);
|
|
89
|
-
const tpl = `
|
|
90
|
-
${scriptTpl}
|
|
91
|
-
import '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().resolve(Object.values(config.entry)[0]))}'
|
|
92
|
-
`;
|
|
93
|
-
const dir = external_node_path_default().dirname(realEntryPath);
|
|
94
|
-
if (!external_node_fs_default().existsSync(dir)) external_node_fs_default().mkdirSync(dir, {
|
|
95
|
-
recursive: true
|
|
96
|
-
});
|
|
97
|
-
external_node_fs_default().writeFileSync(realEntryPath, tpl, 'utf-8');
|
|
98
|
-
config.entry = {
|
|
99
|
-
main: realEntryPath
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
return config;
|
|
103
|
-
};
|
|
104
|
-
exports.applyClickToComponentConfig = __webpack_exports__.applyClickToComponentConfig;
|
|
105
|
-
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
106
|
-
"applyClickToComponentConfig"
|
|
107
|
-
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
108
|
-
Object.defineProperty(exports, '__esModule', {
|
|
109
|
-
value: true
|
|
110
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import 'module';
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
|
|
4
|
-
import { dirname as __webpack_dirname__ } from "node:path";
|
|
5
|
-
import node_fs from "node:fs";
|
|
6
|
-
import node_http from "node:http";
|
|
7
|
-
import node_path from "node:path";
|
|
8
|
-
import { TEMP_DIR, getPathInJs, getPort, restartCleaners } from "@unpackjs/core";
|
|
9
|
-
import launch_editor from "launch-editor";
|
|
10
|
-
var click_to_component_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
|
|
11
|
-
const createServer = ()=>new Promise((resolve)=>{
|
|
12
|
-
const server = node_http.createServer((req, res)=>{
|
|
13
|
-
const params = new URLSearchParams(req.url.slice(1));
|
|
14
|
-
const file = decodeURIComponent(params.get('file'));
|
|
15
|
-
const line = Number(params.get('line'));
|
|
16
|
-
const column = Number(params.get('column'));
|
|
17
|
-
res.writeHead(200, {
|
|
18
|
-
'Access-Control-Allow-Origin': '*',
|
|
19
|
-
'Access-Control-Allow-Methods': '*',
|
|
20
|
-
'Access-Control-Allow-Headers': '*',
|
|
21
|
-
'Access-Control-Allow-Private-Network': 'true'
|
|
22
|
-
});
|
|
23
|
-
res.end('ok');
|
|
24
|
-
launch_editor(`${file}:${line}:${column}`);
|
|
25
|
-
});
|
|
26
|
-
getPort().then((port)=>{
|
|
27
|
-
server.listen(port, ()=>{
|
|
28
|
-
resolve({
|
|
29
|
-
port
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
restartCleaners.push(()=>new Promise((resolve)=>server.close(()=>resolve())));
|
|
34
|
-
});
|
|
35
|
-
const applyClickToComponentConfig = async ({ config, unpackConfig })=>{
|
|
36
|
-
const { port } = await createServer();
|
|
37
|
-
const injectScript = node_fs.readFileSync(node_path.resolve(click_to_component_dirname, './injectScript.js'), 'utf-8');
|
|
38
|
-
const scriptTpl = `
|
|
39
|
-
if (!document.querySelector('#__click-to-component__')) {
|
|
40
|
-
const script = document.createElement('script')
|
|
41
|
-
window['CLICK_TO_COMPONENT'] = { port: ${port} }
|
|
42
|
-
script.setAttribute('type', 'text/javascript')
|
|
43
|
-
script.textContent = \`${injectScript}\`
|
|
44
|
-
document.body.appendChild(script)
|
|
45
|
-
}`;
|
|
46
|
-
if (unpackConfig.mpa) Object.values(config.entry).forEach((entryConfig)=>{
|
|
47
|
-
const filePath = entryConfig.import[0];
|
|
48
|
-
const content = node_fs.readFileSync(filePath, 'utf-8');
|
|
49
|
-
node_fs.writeFileSync(filePath, `${scriptTpl}\n${content}`, 'utf-8');
|
|
50
|
-
});
|
|
51
|
-
else {
|
|
52
|
-
const realEntryPath = node_path.resolve(config.context, TEMP_DIR, 'entries', `index.${port}.jsx`);
|
|
53
|
-
const tpl = `
|
|
54
|
-
${scriptTpl}
|
|
55
|
-
import '${getPathInJs(node_path.resolve(Object.values(config.entry)[0]))}'
|
|
56
|
-
`;
|
|
57
|
-
const dir = node_path.dirname(realEntryPath);
|
|
58
|
-
if (!node_fs.existsSync(dir)) node_fs.mkdirSync(dir, {
|
|
59
|
-
recursive: true
|
|
60
|
-
});
|
|
61
|
-
node_fs.writeFileSync(realEntryPath, tpl, 'utf-8');
|
|
62
|
-
config.entry = {
|
|
63
|
-
main: realEntryPath
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
return config;
|
|
67
|
-
};
|
|
68
|
-
export { applyClickToComponentConfig };
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
const COVER_ID = '__click-to-component__';
|
|
2
|
-
let cover = null;
|
|
3
|
-
let currentDebugSource = null;
|
|
4
|
-
let enabled = false;
|
|
5
|
-
function debounce(fn, delay = 200) {
|
|
6
|
-
let timer = null;
|
|
7
|
-
return (...args)=>{
|
|
8
|
-
clearTimeout(timer);
|
|
9
|
-
timer = setTimeout(()=>{
|
|
10
|
-
fn(...args);
|
|
11
|
-
}, delay);
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
function applyStyles(target, styles) {
|
|
15
|
-
Object.entries(styles).forEach(([key, value])=>{
|
|
16
|
-
target.style[key] = value;
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
function createCover() {
|
|
20
|
-
cover = document.createElement('div');
|
|
21
|
-
cover.id = COVER_ID;
|
|
22
|
-
applyStyles(cover, {
|
|
23
|
-
position: 'fixed',
|
|
24
|
-
zIndex: '999999',
|
|
25
|
-
background: 'rgba(120, 170, 210, 0.6)',
|
|
26
|
-
display: 'none',
|
|
27
|
-
pointerEvents: 'none'
|
|
28
|
-
});
|
|
29
|
-
document.body.appendChild(cover);
|
|
30
|
-
}
|
|
31
|
-
function updateCover(target) {
|
|
32
|
-
if ('function' != typeof target.getBoundingClientRect) {
|
|
33
|
-
currentDebugSource = null;
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const { top, left, width, height } = target.getBoundingClientRect();
|
|
37
|
-
applyStyles(cover, {
|
|
38
|
-
top: top + 'px',
|
|
39
|
-
left: left + 'px',
|
|
40
|
-
width: width + 'px',
|
|
41
|
-
height: height + 'px',
|
|
42
|
-
display: 'block'
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function hideCover() {
|
|
46
|
-
cover.style.display = 'none';
|
|
47
|
-
}
|
|
48
|
-
function getFiberWithDebugSourceByTarget(target) {
|
|
49
|
-
const fiberKey = Object.keys(target).find((key)=>key.includes('__reactFiber'));
|
|
50
|
-
const maxDepth = 10;
|
|
51
|
-
const doNext = (fiber, depth = 0)=>{
|
|
52
|
-
if (!fiber) return;
|
|
53
|
-
if (depth > maxDepth) return;
|
|
54
|
-
if (fiber._debugSource) return fiber;
|
|
55
|
-
if (fiber._debugOwner) return doNext(fiber._debugOwner, depth + 1);
|
|
56
|
-
console.warn('[WARN] click-to-component cannot work with the minified version of React.');
|
|
57
|
-
};
|
|
58
|
-
return doNext(target[fiberKey]);
|
|
59
|
-
}
|
|
60
|
-
function getClosestNodeFromFiber(fiber) {
|
|
61
|
-
if (fiber.stateNode) return fiber.stateNode;
|
|
62
|
-
return getClosestNodeFromFiber(fiber.return);
|
|
63
|
-
}
|
|
64
|
-
function openEditor() {
|
|
65
|
-
if (!currentDebugSource) return;
|
|
66
|
-
const port = window.CLICK_TO_COMPONENT.port;
|
|
67
|
-
const { fileName, lineNumber, columnNumber } = currentDebugSource;
|
|
68
|
-
const url = [
|
|
69
|
-
'http://localhost:',
|
|
70
|
-
port,
|
|
71
|
-
'/?file=',
|
|
72
|
-
fileName,
|
|
73
|
-
'&line=',
|
|
74
|
-
lineNumber,
|
|
75
|
-
'&column=',
|
|
76
|
-
columnNumber
|
|
77
|
-
].join('');
|
|
78
|
-
const sendXHR = ()=>{
|
|
79
|
-
const xhr = new XMLHttpRequest();
|
|
80
|
-
xhr.open('GET', url, true);
|
|
81
|
-
xhr.send();
|
|
82
|
-
xhr.addEventListener('error', ()=>{
|
|
83
|
-
const img = document.createElement('img');
|
|
84
|
-
img.src = url;
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
sendXHR();
|
|
88
|
-
}
|
|
89
|
-
document.addEventListener('mouseover', debounce((e)=>{
|
|
90
|
-
if (!enabled) return;
|
|
91
|
-
const target = e.target;
|
|
92
|
-
const fiber = getFiberWithDebugSourceByTarget(target);
|
|
93
|
-
if (!fiber) return;
|
|
94
|
-
const closestNode = getClosestNodeFromFiber(fiber);
|
|
95
|
-
if (!closestNode) return;
|
|
96
|
-
currentDebugSource = fiber._debugSource;
|
|
97
|
-
updateCover(closestNode);
|
|
98
|
-
}, 30));
|
|
99
|
-
document.addEventListener('click', (e)=>{
|
|
100
|
-
if (!enabled) return;
|
|
101
|
-
e.stopPropagation();
|
|
102
|
-
e.preventDefault();
|
|
103
|
-
openEditor();
|
|
104
|
-
hideCover();
|
|
105
|
-
enabled = false;
|
|
106
|
-
}, true);
|
|
107
|
-
document.addEventListener('keydown', (e)=>{
|
|
108
|
-
if ('Alt' === e.key) enabled = true;
|
|
109
|
-
});
|
|
110
|
-
document.addEventListener('keyup', (e)=>{
|
|
111
|
-
if ('Alt' === e.key) {
|
|
112
|
-
enabled = false;
|
|
113
|
-
hideCover();
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
createCover();
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EASL,KAAK,YAAY,EAClB,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,GAAI,UAAS,kBAAuB,KAAG,YAoG9D,CAAA"}
|
package/dist/mpa.cjs
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
|
-
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: definition[key]
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
})();
|
|
20
|
-
(()=>{
|
|
21
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
-
})();
|
|
23
|
-
(()=>{
|
|
24
|
-
__webpack_require__.r = (exports1)=>{
|
|
25
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
-
value: 'Module'
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
-
value: true
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
})();
|
|
33
|
-
var __webpack_exports__ = {};
|
|
34
|
-
__webpack_require__.r(__webpack_exports__);
|
|
35
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
applyMpaConfig: ()=>applyMpaConfig
|
|
37
|
-
});
|
|
38
|
-
const external_node_fs_namespaceObject = require("node:fs");
|
|
39
|
-
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
40
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
41
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
42
|
-
const core_namespaceObject = require("@unpackjs/core");
|
|
43
|
-
const applyMpaConfig = ({ config, unpackConfig, mergeConfig, HtmlPlugin })=>{
|
|
44
|
-
if (!unpackConfig.mpa) return config;
|
|
45
|
-
const isRspack = 'rspack' === unpackConfig.bundler;
|
|
46
|
-
const tempDirectory = external_node_path_default().join(core_namespaceObject.TEMP_DIR, 'mpa');
|
|
47
|
-
const userOptions = (0, core_namespaceObject.isPlainObject)(unpackConfig.mpa) ? unpackConfig.mpa : {};
|
|
48
|
-
const getPageConfig = (indexPath)=>{
|
|
49
|
-
const filePath = external_node_path_default().join(indexPath, '../config.json');
|
|
50
|
-
let pageConfig = {};
|
|
51
|
-
if (external_node_fs_default().existsSync(filePath)) pageConfig = JSON.parse(external_node_fs_default().readFileSync(filePath, 'utf-8'));
|
|
52
|
-
return pageConfig;
|
|
53
|
-
};
|
|
54
|
-
const createTempFile = (entry)=>{
|
|
55
|
-
var _userOptions_globalImport, _unpackConfig_html;
|
|
56
|
-
(0, core_namespaceObject.removeDir)(external_node_path_default().join(unpackConfig.root, tempDirectory));
|
|
57
|
-
const globalImport = (null == (_userOptions_globalImport = userOptions.globalImport) ? void 0 : _userOptions_globalImport.reduce((acc, curr)=>`${acc}\nimport '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().resolve(unpackConfig.root, curr))}'`, '')) || '';
|
|
58
|
-
const { layout } = userOptions;
|
|
59
|
-
const layoutImport = layout ? `import Layout from '${(0, core_namespaceObject.getPathInJs)(external_node_path_default().resolve(unpackConfig.root, layout))}'` : '';
|
|
60
|
-
const layoutJSX = layout ? '<Layout><App /></Layout>' : '<App />';
|
|
61
|
-
const rootElement = `document.getElementById('${null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.mountId}')`;
|
|
62
|
-
const reactDOMSource = 'react-dom/client';
|
|
63
|
-
const renderer = `ReactDOM.createRoot(${rootElement}).render(${layoutJSX})`;
|
|
64
|
-
Object.entries(entry).forEach(([entryName, entryConfig])=>{
|
|
65
|
-
const filePath = external_node_path_default().join(unpackConfig.root, tempDirectory, `${entryName}.jsx`);
|
|
66
|
-
const tpl = `
|
|
67
|
-
import React from 'react'
|
|
68
|
-
import ReactDOM from '${reactDOMSource}'
|
|
69
|
-
import App from '${(0, core_namespaceObject.getPathInJs)(entryConfig.import[0])}'${layoutImport && `\n${layoutImport}`}
|
|
70
|
-
${globalImport}
|
|
71
|
-
${renderer}
|
|
72
|
-
`;
|
|
73
|
-
const dir = external_node_path_default().dirname(filePath);
|
|
74
|
-
if (!external_node_fs_default().existsSync(dir)) external_node_fs_default().mkdirSync(dir, {
|
|
75
|
-
recursive: true
|
|
76
|
-
});
|
|
77
|
-
external_node_fs_default().writeFileSync(filePath, tpl, 'utf-8');
|
|
78
|
-
entryConfig.import[0] = filePath;
|
|
79
|
-
});
|
|
80
|
-
return entry;
|
|
81
|
-
};
|
|
82
|
-
const collectEntry = ()=>{
|
|
83
|
-
const start = performance.now();
|
|
84
|
-
const entry = {};
|
|
85
|
-
const html = [];
|
|
86
|
-
const getIndexFilePath = (dir)=>{
|
|
87
|
-
const extensions = [
|
|
88
|
-
'.tsx',
|
|
89
|
-
'.jsx'
|
|
90
|
-
];
|
|
91
|
-
for (const extension of extensions){
|
|
92
|
-
const indexFilePath = external_node_path_default().join(dir, `index${extension}`);
|
|
93
|
-
if (external_node_fs_default().existsSync(indexFilePath)) return indexFilePath;
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
};
|
|
97
|
-
const pagesRoot = external_node_path_default().join(unpackConfig.root, 'src', 'pages');
|
|
98
|
-
external_node_fs_default().readdirSync(pagesRoot).forEach((filename)=>{
|
|
99
|
-
if (filename.startsWith('.')) return;
|
|
100
|
-
const indexFilePath = getIndexFilePath(external_node_path_default().join(pagesRoot, filename));
|
|
101
|
-
if (indexFilePath) {
|
|
102
|
-
var _unpackConfig_html, _unpackConfig_html1, _unpackConfig_html2, _unpackConfig_html3, _unpackConfig_html4, _unpackConfig_html5, _unpackConfig_html6, _unpackConfig_html7, _unpackConfig_html8;
|
|
103
|
-
const pageConfig = getPageConfig(indexFilePath);
|
|
104
|
-
let entryName = true === userOptions.lowerCase ? filename.toLowerCase() : filename;
|
|
105
|
-
if (pageConfig.filename) entryName = pageConfig.filename.slice(0, -5);
|
|
106
|
-
entry[entryName] = {
|
|
107
|
-
import: [
|
|
108
|
-
indexFilePath
|
|
109
|
-
]
|
|
110
|
-
};
|
|
111
|
-
if (pageConfig.template) pageConfig.template = external_node_path_default().join(indexFilePath, '../', pageConfig.template);
|
|
112
|
-
html.push({
|
|
113
|
-
template: (null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.template) || (isRspack ? void 0 : ''),
|
|
114
|
-
templateContent: (null == (_unpackConfig_html1 = unpackConfig.html) ? void 0 : _unpackConfig_html1.templateContent) || ((null == (_unpackConfig_html2 = unpackConfig.html) ? void 0 : _unpackConfig_html2.template) ? isRspack ? void 0 : false : core_namespaceObject.TEMPLATE_CONTENT),
|
|
115
|
-
minify: false,
|
|
116
|
-
filename: `${entryName}.html`,
|
|
117
|
-
chunks: [
|
|
118
|
-
entryName
|
|
119
|
-
],
|
|
120
|
-
...pageConfig,
|
|
121
|
-
templateParameters: {
|
|
122
|
-
mountId: null == (_unpackConfig_html3 = unpackConfig.html) ? void 0 : _unpackConfig_html3.mountId,
|
|
123
|
-
title: (0, core_namespaceObject.isFunction)(null == (_unpackConfig_html4 = unpackConfig.html) ? void 0 : _unpackConfig_html4.title) ? null == (_unpackConfig_html5 = unpackConfig.html) ? void 0 : _unpackConfig_html5.title({
|
|
124
|
-
entryName
|
|
125
|
-
}) : (null == (_unpackConfig_html6 = unpackConfig.html) ? void 0 : _unpackConfig_html6.title) || '',
|
|
126
|
-
headTag: (null == (_unpackConfig_html7 = unpackConfig.html) ? void 0 : _unpackConfig_html7.headTag) || '',
|
|
127
|
-
...null == (_unpackConfig_html8 = unpackConfig.html) ? void 0 : _unpackConfig_html8.templateParameters,
|
|
128
|
-
...pageConfig.templateParameters
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
(0, core_namespaceObject.isDevServer)() || core_namespaceObject.logger.info(`collect entries in ${(performance.now() - start).toFixed(2)}ms ${core_namespaceObject.colors.dim('[MPA]')}`);
|
|
134
|
-
return {
|
|
135
|
-
entry,
|
|
136
|
-
html
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
const { entry, html } = collectEntry();
|
|
140
|
-
config = mergeConfig(config, {
|
|
141
|
-
entry: createTempFile(entry),
|
|
142
|
-
plugins: html.map((h)=>new HtmlPlugin(h))
|
|
143
|
-
});
|
|
144
|
-
return config;
|
|
145
|
-
};
|
|
146
|
-
exports.applyMpaConfig = __webpack_exports__.applyMpaConfig;
|
|
147
|
-
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
148
|
-
"applyMpaConfig"
|
|
149
|
-
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
150
|
-
Object.defineProperty(exports, '__esModule', {
|
|
151
|
-
value: true
|
|
152
|
-
});
|
package/dist/mpa.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import 'module';
|
|
2
|
-
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
import node_fs from "node:fs";
|
|
4
|
-
import node_path from "node:path";
|
|
5
|
-
import { TEMPLATE_CONTENT, TEMP_DIR, colors, getPathInJs, isDevServer, isFunction, isPlainObject, logger, removeDir } from "@unpackjs/core";
|
|
6
|
-
const applyMpaConfig = ({ config, unpackConfig, mergeConfig, HtmlPlugin })=>{
|
|
7
|
-
if (!unpackConfig.mpa) return config;
|
|
8
|
-
const isRspack = 'rspack' === unpackConfig.bundler;
|
|
9
|
-
const tempDirectory = node_path.join(TEMP_DIR, 'mpa');
|
|
10
|
-
const userOptions = isPlainObject(unpackConfig.mpa) ? unpackConfig.mpa : {};
|
|
11
|
-
const getPageConfig = (indexPath)=>{
|
|
12
|
-
const filePath = node_path.join(indexPath, '../config.json');
|
|
13
|
-
let pageConfig = {};
|
|
14
|
-
if (node_fs.existsSync(filePath)) pageConfig = JSON.parse(node_fs.readFileSync(filePath, 'utf-8'));
|
|
15
|
-
return pageConfig;
|
|
16
|
-
};
|
|
17
|
-
const createTempFile = (entry)=>{
|
|
18
|
-
var _userOptions_globalImport, _unpackConfig_html;
|
|
19
|
-
removeDir(node_path.join(unpackConfig.root, tempDirectory));
|
|
20
|
-
const globalImport = (null == (_userOptions_globalImport = userOptions.globalImport) ? void 0 : _userOptions_globalImport.reduce((acc, curr)=>`${acc}\nimport '${getPathInJs(node_path.resolve(unpackConfig.root, curr))}'`, '')) || '';
|
|
21
|
-
const { layout } = userOptions;
|
|
22
|
-
const layoutImport = layout ? `import Layout from '${getPathInJs(node_path.resolve(unpackConfig.root, layout))}'` : '';
|
|
23
|
-
const layoutJSX = layout ? '<Layout><App /></Layout>' : '<App />';
|
|
24
|
-
const rootElement = `document.getElementById('${null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.mountId}')`;
|
|
25
|
-
const reactDOMSource = 'react-dom/client';
|
|
26
|
-
const renderer = `ReactDOM.createRoot(${rootElement}).render(${layoutJSX})`;
|
|
27
|
-
Object.entries(entry).forEach(([entryName, entryConfig])=>{
|
|
28
|
-
const filePath = node_path.join(unpackConfig.root, tempDirectory, `${entryName}.jsx`);
|
|
29
|
-
const tpl = `
|
|
30
|
-
import React from 'react'
|
|
31
|
-
import ReactDOM from '${reactDOMSource}'
|
|
32
|
-
import App from '${getPathInJs(entryConfig.import[0])}'${layoutImport && `\n${layoutImport}`}
|
|
33
|
-
${globalImport}
|
|
34
|
-
${renderer}
|
|
35
|
-
`;
|
|
36
|
-
const dir = node_path.dirname(filePath);
|
|
37
|
-
if (!node_fs.existsSync(dir)) node_fs.mkdirSync(dir, {
|
|
38
|
-
recursive: true
|
|
39
|
-
});
|
|
40
|
-
node_fs.writeFileSync(filePath, tpl, 'utf-8');
|
|
41
|
-
entryConfig.import[0] = filePath;
|
|
42
|
-
});
|
|
43
|
-
return entry;
|
|
44
|
-
};
|
|
45
|
-
const collectEntry = ()=>{
|
|
46
|
-
const start = performance.now();
|
|
47
|
-
const entry = {};
|
|
48
|
-
const html = [];
|
|
49
|
-
const getIndexFilePath = (dir)=>{
|
|
50
|
-
const extensions = [
|
|
51
|
-
'.tsx',
|
|
52
|
-
'.jsx'
|
|
53
|
-
];
|
|
54
|
-
for (const extension of extensions){
|
|
55
|
-
const indexFilePath = node_path.join(dir, `index${extension}`);
|
|
56
|
-
if (node_fs.existsSync(indexFilePath)) return indexFilePath;
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
};
|
|
60
|
-
const pagesRoot = node_path.join(unpackConfig.root, 'src', 'pages');
|
|
61
|
-
node_fs.readdirSync(pagesRoot).forEach((filename)=>{
|
|
62
|
-
if (filename.startsWith('.')) return;
|
|
63
|
-
const indexFilePath = getIndexFilePath(node_path.join(pagesRoot, filename));
|
|
64
|
-
if (indexFilePath) {
|
|
65
|
-
var _unpackConfig_html, _unpackConfig_html1, _unpackConfig_html2, _unpackConfig_html3, _unpackConfig_html4, _unpackConfig_html5, _unpackConfig_html6, _unpackConfig_html7, _unpackConfig_html8;
|
|
66
|
-
const pageConfig = getPageConfig(indexFilePath);
|
|
67
|
-
let entryName = true === userOptions.lowerCase ? filename.toLowerCase() : filename;
|
|
68
|
-
if (pageConfig.filename) entryName = pageConfig.filename.slice(0, -5);
|
|
69
|
-
entry[entryName] = {
|
|
70
|
-
import: [
|
|
71
|
-
indexFilePath
|
|
72
|
-
]
|
|
73
|
-
};
|
|
74
|
-
if (pageConfig.template) pageConfig.template = node_path.join(indexFilePath, '../', pageConfig.template);
|
|
75
|
-
html.push({
|
|
76
|
-
template: (null == (_unpackConfig_html = unpackConfig.html) ? void 0 : _unpackConfig_html.template) || (isRspack ? void 0 : ''),
|
|
77
|
-
templateContent: (null == (_unpackConfig_html1 = unpackConfig.html) ? void 0 : _unpackConfig_html1.templateContent) || ((null == (_unpackConfig_html2 = unpackConfig.html) ? void 0 : _unpackConfig_html2.template) ? isRspack ? void 0 : false : TEMPLATE_CONTENT),
|
|
78
|
-
minify: false,
|
|
79
|
-
filename: `${entryName}.html`,
|
|
80
|
-
chunks: [
|
|
81
|
-
entryName
|
|
82
|
-
],
|
|
83
|
-
...pageConfig,
|
|
84
|
-
templateParameters: {
|
|
85
|
-
mountId: null == (_unpackConfig_html3 = unpackConfig.html) ? void 0 : _unpackConfig_html3.mountId,
|
|
86
|
-
title: isFunction(null == (_unpackConfig_html4 = unpackConfig.html) ? void 0 : _unpackConfig_html4.title) ? null == (_unpackConfig_html5 = unpackConfig.html) ? void 0 : _unpackConfig_html5.title({
|
|
87
|
-
entryName
|
|
88
|
-
}) : (null == (_unpackConfig_html6 = unpackConfig.html) ? void 0 : _unpackConfig_html6.title) || '',
|
|
89
|
-
headTag: (null == (_unpackConfig_html7 = unpackConfig.html) ? void 0 : _unpackConfig_html7.headTag) || '',
|
|
90
|
-
...null == (_unpackConfig_html8 = unpackConfig.html) ? void 0 : _unpackConfig_html8.templateParameters,
|
|
91
|
-
...pageConfig.templateParameters
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
isDevServer() || logger.info(`collect entries in ${(performance.now() - start).toFixed(2)}ms ${colors.dim('[MPA]')}`);
|
|
97
|
-
return {
|
|
98
|
-
entry,
|
|
99
|
-
html
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
const { entry, html } = collectEntry();
|
|
103
|
-
config = mergeConfig(config, {
|
|
104
|
-
entry: createTempFile(entry),
|
|
105
|
-
plugins: html.map((h)=>new HtmlPlugin(h))
|
|
106
|
-
});
|
|
107
|
-
return config;
|
|
108
|
-
};
|
|
109
|
-
export { applyMpaConfig };
|