@bleedingdev/modern-js-plugin-ssg 3.2.0-ultramodern.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/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/cjs/index.js +136 -0
- package/dist/cjs/libs/make.js +79 -0
- package/dist/cjs/libs/output.js +55 -0
- package/dist/cjs/libs/replace.js +75 -0
- package/dist/cjs/libs/util.js +224 -0
- package/dist/cjs/server/consts.js +36 -0
- package/dist/cjs/server/index.js +141 -0
- package/dist/cjs/server/prerender.js +75 -0
- package/dist/cjs/types.js +18 -0
- package/dist/esm/index.mjs +90 -0
- package/dist/esm/libs/make.mjs +31 -0
- package/dist/esm/libs/output.mjs +11 -0
- package/dist/esm/libs/replace.mjs +28 -0
- package/dist/esm/libs/util.mjs +147 -0
- package/dist/esm/server/consts.mjs +2 -0
- package/dist/esm/server/index.mjs +97 -0
- package/dist/esm/server/prerender.mjs +30 -0
- package/dist/esm/types.mjs +0 -0
- package/dist/esm-node/index.mjs +91 -0
- package/dist/esm-node/libs/make.mjs +32 -0
- package/dist/esm-node/libs/output.mjs +12 -0
- package/dist/esm-node/libs/replace.mjs +29 -0
- package/dist/esm-node/libs/util.mjs +149 -0
- package/dist/esm-node/server/consts.mjs +3 -0
- package/dist/esm-node/server/index.mjs +98 -0
- package/dist/esm-node/server/prerender.mjs +31 -0
- package/dist/esm-node/types.mjs +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/libs/make.d.ts +5 -0
- package/dist/types/libs/output.d.ts +2 -0
- package/dist/types/libs/replace.d.ts +4 -0
- package/dist/types/libs/util.d.ts +27 -0
- package/dist/types/server/consts.d.ts +1 -0
- package/dist/types/server/index.d.ts +4 -0
- package/dist/types/server/prerender.d.ts +10 -0
- package/dist/types/types.d.ts +23 -0
- package/package.json +84 -0
- package/rslib.config.mts +4 -0
- package/rstest.config.mts +7 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Modern.js
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Modern.js</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
A Progressive React Framework for modern web development.
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
## Getting Started
|
|
12
|
+
|
|
13
|
+
Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
|
|
14
|
+
|
|
15
|
+
## Documentation
|
|
16
|
+
|
|
17
|
+
- [English Documentation](https://modernjs.dev/en/)
|
|
18
|
+
- [中文文档](https://modernjs.dev)
|
|
19
|
+
|
|
20
|
+
## Contributing
|
|
21
|
+
|
|
22
|
+
Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
|
|
@@ -0,0 +1,136 @@
|
|
|
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 ("u" > 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
|
+
default: ()=>src,
|
|
37
|
+
ssgPlugin: ()=>ssgPlugin
|
|
38
|
+
});
|
|
39
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
40
|
+
const external_path_namespaceObject = require("path");
|
|
41
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
42
|
+
const make_js_namespaceObject = require("./libs/make.js");
|
|
43
|
+
const output_js_namespaceObject = require("./libs/output.js");
|
|
44
|
+
const replace_js_namespaceObject = require("./libs/replace.js");
|
|
45
|
+
const util_js_namespaceObject = require("./libs/util.js");
|
|
46
|
+
const index_js_namespaceObject = require("./server/index.js");
|
|
47
|
+
const ssgPlugin = ()=>({
|
|
48
|
+
name: '@modern-js/plugin-ssg',
|
|
49
|
+
pre: [
|
|
50
|
+
'@modern-js/plugin-bff'
|
|
51
|
+
],
|
|
52
|
+
setup: (api)=>{
|
|
53
|
+
const agreedRouteMap = {};
|
|
54
|
+
api.modifyFileSystemRoutes(async ({ entrypoint, routes })=>{
|
|
55
|
+
const { entryName } = entrypoint;
|
|
56
|
+
const flattedRoutes = (0, util_js_namespaceObject.flattenRoutes)((0, utils_namespaceObject.filterRoutesForServer)(routes));
|
|
57
|
+
agreedRouteMap[entryName] = flattedRoutes;
|
|
58
|
+
return {
|
|
59
|
+
entrypoint,
|
|
60
|
+
routes
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
api.onAfterBuild(async ()=>{
|
|
64
|
+
const resolvedConfig = api.getNormalizedConfig();
|
|
65
|
+
const appContext = api.getAppContext();
|
|
66
|
+
const { appDirectory, entrypoints } = appContext;
|
|
67
|
+
const { output, server } = resolvedConfig;
|
|
68
|
+
const { ssg, ssgByEntries, distPath: { root: outputPath } = {} } = output;
|
|
69
|
+
const ssgOptions = (Array.isArray(ssg) ? ssg.pop() : ssg) ?? true;
|
|
70
|
+
const buildDir = external_path_default().join(appDirectory, outputPath);
|
|
71
|
+
const routes = (0, util_js_namespaceObject.readJSONSpec)(buildDir);
|
|
72
|
+
const pageRoutes = routes.filter((route)=>route.isSPA);
|
|
73
|
+
const apiRoutes = routes.filter((route)=>!route.isSPA);
|
|
74
|
+
if (0 === pageRoutes.length) return;
|
|
75
|
+
const intermediateOptions = (0, util_js_namespaceObject.standardOptions)(ssgOptions, entrypoints, pageRoutes, server, ssgByEntries);
|
|
76
|
+
if (!intermediateOptions) return;
|
|
77
|
+
const ssgRoutes = [];
|
|
78
|
+
pageRoutes.forEach((pageRoute)=>{
|
|
79
|
+
const { entryName, entryPath } = pageRoute;
|
|
80
|
+
const agreedRoutes = agreedRouteMap[entryName];
|
|
81
|
+
let entryOptions = intermediateOptions[entryName] || intermediateOptions[pageRoute.urlPath];
|
|
82
|
+
if (agreedRoutes) {
|
|
83
|
+
if (!entryOptions) return;
|
|
84
|
+
if (true === entryOptions) entryOptions = {
|
|
85
|
+
routes: [],
|
|
86
|
+
headers: {}
|
|
87
|
+
};
|
|
88
|
+
const { routes: userRoutes = [], headers } = entryOptions || {};
|
|
89
|
+
if (userRoutes.length > 0) userRoutes.forEach((route)=>{
|
|
90
|
+
ssgRoutes.push((0, make_js_namespaceObject.makeRoute)(pageRoute, route, headers));
|
|
91
|
+
});
|
|
92
|
+
else agreedRoutes.forEach((route)=>{
|
|
93
|
+
if (!(0, util_js_namespaceObject.isDynamicUrl)(route.path)) ssgRoutes.push((0, make_js_namespaceObject.makeRoute)(pageRoute, route.path, headers));
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
if (!entryOptions) return;
|
|
97
|
+
if (true === entryOptions) ssgRoutes.push({
|
|
98
|
+
...pageRoute,
|
|
99
|
+
output: entryPath
|
|
100
|
+
});
|
|
101
|
+
else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
102
|
+
const { routes: enrtyRoutes, headers } = entryOptions;
|
|
103
|
+
enrtyRoutes.forEach((route)=>{
|
|
104
|
+
ssgRoutes.push((0, make_js_namespaceObject.makeRoute)(pageRoute, route, headers));
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
if (0 === ssgRoutes.length) return;
|
|
110
|
+
ssgRoutes.forEach((ssgRoute)=>{
|
|
111
|
+
if (ssgRoute.isSSR) {
|
|
112
|
+
const isOriginRoute = pageRoutes.some((pageRoute)=>pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName);
|
|
113
|
+
if (isOriginRoute) throw new Error(`ssg can not using with ssr,url - ${ssgRoute.urlPath}, entry - ${ssgRoute.entryName} `);
|
|
114
|
+
utils_namespaceObject.logger.warn(`new ssg route ${ssgRoute.urlPath} is using ssr now,maybe from parent route ${ssgRoute.entryName},close ssr`);
|
|
115
|
+
}
|
|
116
|
+
ssgRoute.isSSR = false;
|
|
117
|
+
ssgRoute.output = (0, util_js_namespaceObject.formatOutput)(ssgRoute.output);
|
|
118
|
+
});
|
|
119
|
+
const htmlAry = await (0, index_js_namespaceObject.createServer)(appContext, ssgRoutes, pageRoutes, apiRoutes, resolvedConfig);
|
|
120
|
+
(0, output_js_namespaceObject.writeHtmlFile)(htmlAry, ssgRoutes, buildDir);
|
|
121
|
+
(0, replace_js_namespaceObject.replaceRoute)(ssgRoutes, pageRoutes);
|
|
122
|
+
(0, util_js_namespaceObject.writeJSONSpec)(buildDir, pageRoutes.concat(apiRoutes));
|
|
123
|
+
utils_namespaceObject.logger.info('ssg Compiled successfully');
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
const src = ssgPlugin;
|
|
128
|
+
exports["default"] = __webpack_exports__["default"];
|
|
129
|
+
exports.ssgPlugin = __webpack_exports__.ssgPlugin;
|
|
130
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
131
|
+
"default",
|
|
132
|
+
"ssgPlugin"
|
|
133
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
134
|
+
Object.defineProperty(exports, '__esModule', {
|
|
135
|
+
value: true
|
|
136
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
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 ("u" > 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
|
+
makeRender: ()=>makeRender,
|
|
37
|
+
makeRoute: ()=>makeRoute
|
|
38
|
+
});
|
|
39
|
+
const external_normalize_path_namespaceObject = require("normalize-path");
|
|
40
|
+
var external_normalize_path_default = /*#__PURE__*/ __webpack_require__.n(external_normalize_path_namespaceObject);
|
|
41
|
+
const external_path_namespaceObject = require("path");
|
|
42
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
43
|
+
function makeRender(ssgRoutes, render, port) {
|
|
44
|
+
return ssgRoutes.map((ssgRoute)=>render({
|
|
45
|
+
url: ssgRoute.urlPath,
|
|
46
|
+
headers: {
|
|
47
|
+
host: `localhost:${port}`,
|
|
48
|
+
...ssgRoute.headers
|
|
49
|
+
},
|
|
50
|
+
connection: {}
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
function makeRoute(baseRoute, route, headers = {}) {
|
|
54
|
+
const { urlPath, entryPath } = baseRoute;
|
|
55
|
+
if ('string' == typeof route) return {
|
|
56
|
+
...baseRoute,
|
|
57
|
+
urlPath: external_normalize_path_default()(`${urlPath}${route}`) || '/',
|
|
58
|
+
headers,
|
|
59
|
+
output: external_path_default().join(entryPath, `..${'/' === route ? '' : route}`)
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
...baseRoute,
|
|
63
|
+
urlPath: external_normalize_path_default()(`${urlPath}${route.url}`) || '/',
|
|
64
|
+
headers: {
|
|
65
|
+
...headers,
|
|
66
|
+
...route.headers
|
|
67
|
+
},
|
|
68
|
+
output: route.output ? external_path_default().normalize(route.output) : external_path_default().join(entryPath, `..${'/' === route.url ? '' : route.url}`)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
exports.makeRender = __webpack_exports__.makeRender;
|
|
72
|
+
exports.makeRoute = __webpack_exports__.makeRoute;
|
|
73
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
74
|
+
"makeRender",
|
|
75
|
+
"makeRoute"
|
|
76
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
77
|
+
Object.defineProperty(exports, '__esModule', {
|
|
78
|
+
value: true
|
|
79
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
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 ("u" > 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
|
+
writeHtmlFile: ()=>writeHtmlFile
|
|
37
|
+
});
|
|
38
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
39
|
+
const external_path_namespaceObject = require("path");
|
|
40
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
41
|
+
function writeHtmlFile(htmlAry, ssgRoutes, baseDir) {
|
|
42
|
+
htmlAry.forEach((html, index)=>{
|
|
43
|
+
const ssgRoute = ssgRoutes[index];
|
|
44
|
+
const filepath = external_path_default().join(baseDir, ssgRoute.output);
|
|
45
|
+
if (!utils_namespaceObject.fs.existsSync(external_path_default().dirname(filepath))) utils_namespaceObject.fs.ensureDirSync(external_path_default().dirname(filepath));
|
|
46
|
+
utils_namespaceObject.fs.writeFileSync(filepath, html);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.writeHtmlFile = __webpack_exports__.writeHtmlFile;
|
|
50
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
51
|
+
"writeHtmlFile"
|
|
52
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
53
|
+
Object.defineProperty(exports, '__esModule', {
|
|
54
|
+
value: true
|
|
55
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
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 ("u" > 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
|
+
exist: ()=>exist,
|
|
37
|
+
replaceRoute: ()=>replaceRoute
|
|
38
|
+
});
|
|
39
|
+
const external_normalize_path_namespaceObject = require("normalize-path");
|
|
40
|
+
var external_normalize_path_default = /*#__PURE__*/ __webpack_require__.n(external_normalize_path_namespaceObject);
|
|
41
|
+
function exist(route, pageRoutes) {
|
|
42
|
+
return pageRoutes.slice().findIndex((pageRoute)=>{
|
|
43
|
+
const urlEqual = external_normalize_path_default()(pageRoute.urlPath) === external_normalize_path_default()(route.urlPath);
|
|
44
|
+
const entryEqual = pageRoute.entryName === route.entryName;
|
|
45
|
+
if (urlEqual && entryEqual) return true;
|
|
46
|
+
return false;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function replaceRoute(ssgRoutes, pageRoutes) {
|
|
50
|
+
const cleanSsgRoutes = ssgRoutes.map((ssgRoute)=>{
|
|
51
|
+
const { output, headers, ...cleanSsgRoute } = ssgRoute;
|
|
52
|
+
return Object.assign(cleanSsgRoute, output ? {
|
|
53
|
+
entryPath: output
|
|
54
|
+
} : {});
|
|
55
|
+
});
|
|
56
|
+
const freshRoutes = [];
|
|
57
|
+
cleanSsgRoutes.forEach((ssgRoute)=>{
|
|
58
|
+
const index = exist(ssgRoute, pageRoutes);
|
|
59
|
+
if (index < 0) freshRoutes.push({
|
|
60
|
+
...ssgRoute
|
|
61
|
+
});
|
|
62
|
+
else pageRoutes[index].entryPath = ssgRoute.entryPath;
|
|
63
|
+
});
|
|
64
|
+
pageRoutes.push(...freshRoutes);
|
|
65
|
+
return pageRoutes;
|
|
66
|
+
}
|
|
67
|
+
exports.exist = __webpack_exports__.exist;
|
|
68
|
+
exports.replaceRoute = __webpack_exports__.replaceRoute;
|
|
69
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
70
|
+
"exist",
|
|
71
|
+
"replaceRoute"
|
|
72
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
73
|
+
Object.defineProperty(exports, '__esModule', {
|
|
74
|
+
value: true
|
|
75
|
+
});
|
|
@@ -0,0 +1,224 @@
|
|
|
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 ("u" > 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
|
+
chunkArray: ()=>chunkArray,
|
|
37
|
+
flattenRoutes: ()=>flattenRoutes,
|
|
38
|
+
formatOutput: ()=>formatOutput,
|
|
39
|
+
formatPath: ()=>formatPath,
|
|
40
|
+
getOutput: ()=>getOutput,
|
|
41
|
+
getUrlPrefix: ()=>getUrlPrefix,
|
|
42
|
+
isDynamicUrl: ()=>isDynamicUrl,
|
|
43
|
+
openRouteSSR: ()=>openRouteSSR,
|
|
44
|
+
readJSONSpec: ()=>readJSONSpec,
|
|
45
|
+
replaceWithAlias: ()=>replaceWithAlias,
|
|
46
|
+
standardOptions: ()=>standardOptions,
|
|
47
|
+
writeJSONSpec: ()=>writeJSONSpec
|
|
48
|
+
});
|
|
49
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
50
|
+
const external_path_namespaceObject = require("path");
|
|
51
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
52
|
+
function formatOutput(filename) {
|
|
53
|
+
const outputPath = external_path_default().extname(filename) ? filename : `${filename}/index.html`;
|
|
54
|
+
return outputPath;
|
|
55
|
+
}
|
|
56
|
+
function formatPath(str) {
|
|
57
|
+
let addr = str;
|
|
58
|
+
if (!addr || 'string' != typeof addr) return addr;
|
|
59
|
+
if (addr.startsWith('.')) addr = addr.slice(1);
|
|
60
|
+
if (!addr.startsWith('/')) addr = `/${addr}`;
|
|
61
|
+
if (addr.endsWith('/') && '/' !== addr) addr = addr.slice(0, addr.length - 1);
|
|
62
|
+
return addr;
|
|
63
|
+
}
|
|
64
|
+
function isDynamicUrl(url) {
|
|
65
|
+
return url.includes(':') || url.endsWith('*');
|
|
66
|
+
}
|
|
67
|
+
function getUrlPrefix(route, baseUrl) {
|
|
68
|
+
let base = '';
|
|
69
|
+
if (Array.isArray(baseUrl)) {
|
|
70
|
+
const filters = baseUrl.filter((url)=>route.urlPath.includes(url));
|
|
71
|
+
if (filters.length > 1) {
|
|
72
|
+
const matched = filters.sort((a, b)=>a.length - b.length)[0];
|
|
73
|
+
if (!matched) throw new Error('');
|
|
74
|
+
base = matched;
|
|
75
|
+
}
|
|
76
|
+
} else base = baseUrl;
|
|
77
|
+
base = '/' === base ? '' : base;
|
|
78
|
+
const entryName = 'main' === route.entryName ? '' : route.entryName;
|
|
79
|
+
const prefix = `${base}/${entryName}`;
|
|
80
|
+
return prefix.endsWith('/') ? prefix.slice(0, -1) : prefix;
|
|
81
|
+
}
|
|
82
|
+
function getOutput(route, base, agreed) {
|
|
83
|
+
const { output } = route;
|
|
84
|
+
if (output) return output;
|
|
85
|
+
if (agreed) {
|
|
86
|
+
const urlWithoutBase = route.urlPath.replace(base, '');
|
|
87
|
+
return urlWithoutBase.startsWith('/') ? urlWithoutBase.slice(1) : urlWithoutBase;
|
|
88
|
+
}
|
|
89
|
+
throw new Error(`routing must provide output when calling createPage(), check ${route.urlPath}`);
|
|
90
|
+
}
|
|
91
|
+
const readJSONSpec = (dir)=>{
|
|
92
|
+
const routeJSONPath = external_path_default().join(dir, utils_namespaceObject.ROUTE_SPEC_FILE);
|
|
93
|
+
const routeJSON = require(routeJSONPath);
|
|
94
|
+
const { routes } = routeJSON;
|
|
95
|
+
return routes;
|
|
96
|
+
};
|
|
97
|
+
const writeJSONSpec = (dir, routes)=>{
|
|
98
|
+
const routeJSONPath = external_path_default().join(dir, utils_namespaceObject.ROUTE_SPEC_FILE);
|
|
99
|
+
utils_namespaceObject.fs.writeJSONSync(routeJSONPath, {
|
|
100
|
+
routes
|
|
101
|
+
}, {
|
|
102
|
+
spaces: 2
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
const replaceWithAlias = (base, filePath, alias)=>external_path_default().posix.join(alias, external_path_default().posix.relative(base, filePath));
|
|
106
|
+
const standardOptions = (ssgOptions, entrypoints, routes, server, ssgByEntries)=>{
|
|
107
|
+
if (ssgByEntries && Object.keys(ssgByEntries).length > 0) {
|
|
108
|
+
const result = {};
|
|
109
|
+
Object.keys(ssgByEntries).forEach((key)=>{
|
|
110
|
+
const val = ssgByEntries[key];
|
|
111
|
+
if ('function' != typeof val) result[key] = val;
|
|
112
|
+
});
|
|
113
|
+
for (const entry of entrypoints){
|
|
114
|
+
const { entryName } = entry;
|
|
115
|
+
const configured = ssgByEntries[entryName];
|
|
116
|
+
if ('function' == typeof configured) {
|
|
117
|
+
const routesForEntry = routes.filter((r)=>r.entryName === entryName);
|
|
118
|
+
if (Array.isArray(server?.baseUrl)) for (const url of server.baseUrl)routesForEntry.filter((r)=>'string' == typeof r.urlPath && r.urlPath.startsWith(url)).forEach((r)=>{
|
|
119
|
+
result[r.urlPath] = configured(entryName, {
|
|
120
|
+
baseUrl: url
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
else result[entryName] = configured(entryName, {
|
|
124
|
+
baseUrl: server?.baseUrl
|
|
125
|
+
});
|
|
126
|
+
} else if (void 0 !== configured) result[entryName] = configured;
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
if (false === ssgOptions) return false;
|
|
131
|
+
if (true === ssgOptions) return entrypoints.reduce((opt, entry)=>{
|
|
132
|
+
opt[entry.entryName] = ssgOptions;
|
|
133
|
+
return opt;
|
|
134
|
+
}, {});
|
|
135
|
+
if ('object' == typeof ssgOptions) {
|
|
136
|
+
const isSingle = (0, utils_namespaceObject.isSingleEntry)(entrypoints);
|
|
137
|
+
if (isSingle) return {
|
|
138
|
+
main: ssgOptions
|
|
139
|
+
};
|
|
140
|
+
return entrypoints.reduce((opt, entry)=>{
|
|
141
|
+
opt[entry.entryName] = ssgOptions;
|
|
142
|
+
return opt;
|
|
143
|
+
}, {});
|
|
144
|
+
}
|
|
145
|
+
if ('function' == typeof ssgOptions) {
|
|
146
|
+
const intermediateOptions = {};
|
|
147
|
+
for (const entrypoint of entrypoints){
|
|
148
|
+
const { entryName } = entrypoint;
|
|
149
|
+
const routesForEntry = routes.filter((r)=>r.entryName === entryName);
|
|
150
|
+
if (Array.isArray(server?.baseUrl)) for (const url of server.baseUrl)routesForEntry.filter((r)=>'string' == typeof r.urlPath && r.urlPath.startsWith(url)).forEach((r)=>{
|
|
151
|
+
intermediateOptions[r.urlPath] = ssgOptions(entryName, {
|
|
152
|
+
baseUrl: url
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
else intermediateOptions[entryName] = ssgOptions(entryName, {
|
|
156
|
+
baseUrl: server?.baseUrl
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return intermediateOptions;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
};
|
|
163
|
+
const openRouteSSR = (routes, entries = [])=>routes.map((ssgRoute)=>({
|
|
164
|
+
...ssgRoute,
|
|
165
|
+
isSSR: entries.includes(ssgRoute.entryName),
|
|
166
|
+
bundle: `${utils_namespaceObject.SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
167
|
+
}));
|
|
168
|
+
const flattenRoutes = (routes)=>{
|
|
169
|
+
const parents = [];
|
|
170
|
+
const newRoutes = [];
|
|
171
|
+
const traverseRoute = (route)=>{
|
|
172
|
+
const parent = parents[parents.length - 1];
|
|
173
|
+
let path = parent ? `${parent.path}/${route.path || ''}`.replace(/\/+/g, '/') : route.path || '';
|
|
174
|
+
path = path.replace(/\/$/, '');
|
|
175
|
+
if (route._component && ('/' !== path || '/' === path && !parent)) newRoutes.push({
|
|
176
|
+
...route,
|
|
177
|
+
path
|
|
178
|
+
});
|
|
179
|
+
if (route.children) {
|
|
180
|
+
parents.push({
|
|
181
|
+
...route,
|
|
182
|
+
path
|
|
183
|
+
});
|
|
184
|
+
route.children.forEach(traverseRoute);
|
|
185
|
+
parents.pop();
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
routes.forEach(traverseRoute);
|
|
189
|
+
return newRoutes;
|
|
190
|
+
};
|
|
191
|
+
function chunkArray(arr, size) {
|
|
192
|
+
const result = [];
|
|
193
|
+
for(let i = 0; i < arr.length; i += size)result.push(arr.slice(i, i + size));
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
exports.chunkArray = __webpack_exports__.chunkArray;
|
|
197
|
+
exports.flattenRoutes = __webpack_exports__.flattenRoutes;
|
|
198
|
+
exports.formatOutput = __webpack_exports__.formatOutput;
|
|
199
|
+
exports.formatPath = __webpack_exports__.formatPath;
|
|
200
|
+
exports.getOutput = __webpack_exports__.getOutput;
|
|
201
|
+
exports.getUrlPrefix = __webpack_exports__.getUrlPrefix;
|
|
202
|
+
exports.isDynamicUrl = __webpack_exports__.isDynamicUrl;
|
|
203
|
+
exports.openRouteSSR = __webpack_exports__.openRouteSSR;
|
|
204
|
+
exports.readJSONSpec = __webpack_exports__.readJSONSpec;
|
|
205
|
+
exports.replaceWithAlias = __webpack_exports__.replaceWithAlias;
|
|
206
|
+
exports.standardOptions = __webpack_exports__.standardOptions;
|
|
207
|
+
exports.writeJSONSpec = __webpack_exports__.writeJSONSpec;
|
|
208
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
209
|
+
"chunkArray",
|
|
210
|
+
"flattenRoutes",
|
|
211
|
+
"formatOutput",
|
|
212
|
+
"formatPath",
|
|
213
|
+
"getOutput",
|
|
214
|
+
"getUrlPrefix",
|
|
215
|
+
"isDynamicUrl",
|
|
216
|
+
"openRouteSSR",
|
|
217
|
+
"readJSONSpec",
|
|
218
|
+
"replaceWithAlias",
|
|
219
|
+
"standardOptions",
|
|
220
|
+
"writeJSONSpec"
|
|
221
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
222
|
+
Object.defineProperty(exports, '__esModule', {
|
|
223
|
+
value: true
|
|
224
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
CLOSE_SIGN: ()=>CLOSE_SIGN
|
|
28
|
+
});
|
|
29
|
+
const CLOSE_SIGN = 'modern_close_server';
|
|
30
|
+
exports.CLOSE_SIGN = __webpack_exports__.CLOSE_SIGN;
|
|
31
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
32
|
+
"CLOSE_SIGN"
|
|
33
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
34
|
+
Object.defineProperty(exports, '__esModule', {
|
|
35
|
+
value: true
|
|
36
|
+
});
|