@modern-js/plugin-ssg 2.4.1-beta.0 → 2.5.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/CHANGELOG.md +10 -2
- package/dist/cjs/index.js +168 -0
- package/dist/{js/node → cjs}/libs/make.js +8 -23
- package/dist/{js/node → cjs}/libs/output.js +0 -0
- package/dist/{js/node → cjs}/libs/replace.js +2 -28
- package/dist/{js/node → cjs}/libs/util.js +8 -22
- package/dist/{js/node → cjs}/server/consts.js +0 -0
- package/dist/{js/node → cjs}/server/index.js +0 -0
- package/dist/{js/node → cjs}/server/prerender.js +3 -19
- package/dist/{js/node → cjs}/server/process.js +7 -27
- package/dist/{js/node → cjs}/types.js +0 -0
- package/dist/{js/treeshaking → esm}/index.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/make.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/output.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/replace.js +0 -0
- package/dist/{js/treeshaking → esm}/libs/util.js +0 -0
- package/dist/{js/treeshaking → esm}/server/consts.js +0 -0
- package/dist/{js/treeshaking → esm}/server/index.js +0 -0
- package/dist/{js/treeshaking → esm}/server/prerender.js +0 -0
- package/dist/{js/treeshaking → esm}/server/process.js +0 -0
- package/dist/{js/treeshaking → esm}/types.js +0 -0
- package/dist/esm-node/index.js +148 -0
- package/dist/esm-node/libs/make.js +33 -0
- package/dist/{js/modern → esm-node}/libs/output.js +0 -0
- package/dist/esm-node/libs/replace.js +35 -0
- package/dist/{js/modern → esm-node}/libs/util.js +8 -24
- package/dist/{js/modern → esm-node}/server/consts.js +0 -0
- package/dist/{js/modern → esm-node}/server/index.js +0 -0
- package/dist/esm-node/server/prerender.js +35 -0
- package/dist/esm-node/server/process.js +55 -0
- package/dist/{js/modern → esm-node}/types.js +0 -0
- package/package.json +18 -19
- package/dist/js/modern/index.js +0 -189
- package/dist/js/modern/libs/make.js +0 -50
- package/dist/js/modern/libs/replace.js +0 -63
- package/dist/js/modern/server/prerender.js +0 -53
- package/dist/js/modern/server/process.js +0 -84
- package/dist/js/node/index.js +0 -207
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
# @modern-js/plugin-ssg
|
|
2
2
|
|
|
3
|
-
## 2.
|
|
3
|
+
## 2.5.0
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
+
- 89ca6cc: refactor: merge build-config into scripts/build
|
|
8
|
+
|
|
9
|
+
refactor: 把 build-config 合并进 scripts/build
|
|
10
|
+
|
|
11
|
+
- 30614fa: chore: modify package.json entry fields and build config
|
|
12
|
+
chore: 更改 package.json entry 字段以及构建配置
|
|
13
|
+
- Updated dependencies [30614fa]
|
|
14
|
+
- Updated dependencies [1b0ce87]
|
|
7
15
|
- Updated dependencies [11c053b]
|
|
8
|
-
- @modern-js/utils@2.
|
|
16
|
+
- @modern-js/utils@2.5.0
|
|
9
17
|
|
|
10
18
|
## 2.4.0
|
|
11
19
|
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var src_exports = {};
|
|
25
|
+
__export(src_exports, {
|
|
26
|
+
default: () => src_default
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(src_exports);
|
|
29
|
+
var import_path = __toESM(require("path"));
|
|
30
|
+
var import_utils = require("@modern-js/utils");
|
|
31
|
+
var import_react_router_dom = require("react-router-dom");
|
|
32
|
+
var import_util = require("./libs/util");
|
|
33
|
+
var import_server = require("./server");
|
|
34
|
+
var import_output = require("./libs/output");
|
|
35
|
+
var import_replace = require("./libs/replace");
|
|
36
|
+
var import_make = require("./libs/make");
|
|
37
|
+
var src_default = () => ({
|
|
38
|
+
name: "@modern-js/plugin-ssg",
|
|
39
|
+
pre: ["@modern-js/plugin-server", "@modern-js/plugin-bff"],
|
|
40
|
+
setup: (api) => {
|
|
41
|
+
const agreedRouteMap = {};
|
|
42
|
+
return {
|
|
43
|
+
validateSchema() {
|
|
44
|
+
return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-ssg"];
|
|
45
|
+
},
|
|
46
|
+
modifyFileSystemRoutes({ entrypoint, routes }) {
|
|
47
|
+
const { entryName } = entrypoint;
|
|
48
|
+
const flattedRoutes = (0, import_util.flattenRoutes)(routes);
|
|
49
|
+
agreedRouteMap[entryName] = flattedRoutes;
|
|
50
|
+
return { entrypoint, routes };
|
|
51
|
+
},
|
|
52
|
+
async afterBuild() {
|
|
53
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
54
|
+
const appContext = api.useAppContext();
|
|
55
|
+
const { appDirectory, entrypoints } = appContext;
|
|
56
|
+
const { output, server } = resolvedConfig;
|
|
57
|
+
const { ssg, distPath: { root: outputPath } = {} } = output;
|
|
58
|
+
const ssgOptions = (Array.isArray(ssg) ? ssg.pop() : ssg) || true;
|
|
59
|
+
const buildDir = import_path.default.join(appDirectory, outputPath);
|
|
60
|
+
const routes = (0, import_util.readJSONSpec)(buildDir);
|
|
61
|
+
const pageRoutes = routes.filter((route) => !route.isApi);
|
|
62
|
+
const apiRoutes = routes.filter((route) => route.isApi);
|
|
63
|
+
if (pageRoutes.length === 0) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const intermediateOptions = (0, import_util.standardOptions)(
|
|
67
|
+
ssgOptions,
|
|
68
|
+
entrypoints,
|
|
69
|
+
pageRoutes,
|
|
70
|
+
server
|
|
71
|
+
);
|
|
72
|
+
if (!intermediateOptions) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const ssgRoutes = [];
|
|
76
|
+
pageRoutes.forEach((pageRoute) => {
|
|
77
|
+
const { entryName, entryPath } = pageRoute;
|
|
78
|
+
const agreedRoutes = agreedRouteMap[entryName];
|
|
79
|
+
let entryOptions = intermediateOptions[entryName] || intermediateOptions[pageRoute.urlPath];
|
|
80
|
+
if (!agreedRoutes) {
|
|
81
|
+
if (!entryOptions) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (entryOptions === true) {
|
|
85
|
+
ssgRoutes.push({ ...pageRoute, output: entryPath });
|
|
86
|
+
} else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
87
|
+
const { routes: enrtyRoutes, headers } = entryOptions;
|
|
88
|
+
enrtyRoutes.forEach((route) => {
|
|
89
|
+
ssgRoutes.push((0, import_make.makeRoute)(pageRoute, route, headers));
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
if (!entryOptions) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (entryOptions === true) {
|
|
97
|
+
entryOptions = { preventDefault: [], routes: [], headers: {} };
|
|
98
|
+
}
|
|
99
|
+
const {
|
|
100
|
+
preventDefault = [],
|
|
101
|
+
routes: userRoutes = [],
|
|
102
|
+
headers
|
|
103
|
+
} = entryOptions;
|
|
104
|
+
if (userRoutes.length > 0) {
|
|
105
|
+
userRoutes.forEach((route) => {
|
|
106
|
+
if (typeof route === "string") {
|
|
107
|
+
ssgRoutes.push((0, import_make.makeRoute)(pageRoute, route, headers));
|
|
108
|
+
} else if (Array.isArray(route.params)) {
|
|
109
|
+
route.params.forEach((param) => {
|
|
110
|
+
ssgRoutes.push(
|
|
111
|
+
(0, import_make.makeRoute)(
|
|
112
|
+
pageRoute,
|
|
113
|
+
{ ...route, url: (0, import_react_router_dom.generatePath)(route.url, param) },
|
|
114
|
+
headers
|
|
115
|
+
)
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
ssgRoutes.push((0, import_make.makeRoute)(pageRoute, route, headers));
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
} else {
|
|
123
|
+
agreedRoutes.filter((route) => !preventDefault.includes(route.path)).forEach((route) => {
|
|
124
|
+
if (!(0, import_util.isDynamicUrl)(route.path)) {
|
|
125
|
+
ssgRoutes.push((0, import_make.makeRoute)(pageRoute, route.path, headers));
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
if (ssgRoutes.length === 0) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
ssgRoutes.forEach((ssgRoute) => {
|
|
135
|
+
if (ssgRoute.isSSR) {
|
|
136
|
+
const isOriginRoute = pageRoutes.some(
|
|
137
|
+
(pageRoute) => pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName
|
|
138
|
+
);
|
|
139
|
+
if (isOriginRoute) {
|
|
140
|
+
throw new Error(
|
|
141
|
+
`ssg can not using with ssr,url - ${ssgRoute.urlPath}, entry - ${ssgRoute.entryName} `
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
import_utils.logger.warn(
|
|
145
|
+
`new ssg route ${ssgRoute.urlPath} is using ssr now,maybe from parent route ${ssgRoute.entryName},close ssr`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
ssgRoute.isSSR = false;
|
|
149
|
+
ssgRoute.output = (0, import_util.formatOutput)(ssgRoute.output);
|
|
150
|
+
});
|
|
151
|
+
const htmlAry = await (0, import_server.createServer)(
|
|
152
|
+
api,
|
|
153
|
+
ssgRoutes,
|
|
154
|
+
pageRoutes,
|
|
155
|
+
apiRoutes,
|
|
156
|
+
resolvedConfig,
|
|
157
|
+
appDirectory
|
|
158
|
+
);
|
|
159
|
+
(0, import_output.writeHtmlFile)(htmlAry, ssgRoutes, buildDir);
|
|
160
|
+
(0, import_replace.replaceRoute)(ssgRoutes, pageRoutes);
|
|
161
|
+
(0, import_util.writeJSONSpec)(buildDir, pageRoutes.concat(apiRoutes));
|
|
162
|
+
import_utils.logger.info("ssg Compiled successfully");
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
168
|
+
0 && (module.exports = {});
|
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
7
|
var __export = (target, all) => {
|
|
25
8
|
for (var name in all)
|
|
26
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -50,7 +33,7 @@ function makeRender(ssgRoutes, render, port) {
|
|
|
50
33
|
return ssgRoutes.map(
|
|
51
34
|
(ssgRoute) => render({
|
|
52
35
|
url: ssgRoute.urlPath,
|
|
53
|
-
headers:
|
|
36
|
+
headers: { host: `localhost:${port}`, ...ssgRoute.headers },
|
|
54
37
|
connection: {}
|
|
55
38
|
})
|
|
56
39
|
);
|
|
@@ -58,17 +41,19 @@ function makeRender(ssgRoutes, render, port) {
|
|
|
58
41
|
function makeRoute(baseRoute, route, headers = {}) {
|
|
59
42
|
const { urlPath, entryPath } = baseRoute;
|
|
60
43
|
if (typeof route === "string") {
|
|
61
|
-
return
|
|
44
|
+
return {
|
|
45
|
+
...baseRoute,
|
|
62
46
|
urlPath: (0, import_normalize_path.default)(`${urlPath}${route}`) || "/",
|
|
63
47
|
headers,
|
|
64
48
|
output: import_path.default.join(entryPath, `..${route === "/" ? "" : route}`)
|
|
65
|
-
}
|
|
49
|
+
};
|
|
66
50
|
} else {
|
|
67
|
-
return
|
|
51
|
+
return {
|
|
52
|
+
...baseRoute,
|
|
68
53
|
urlPath: (0, import_normalize_path.default)(`${urlPath}${route.url}`) || "/",
|
|
69
|
-
headers:
|
|
54
|
+
headers: { ...headers, ...route.headers },
|
|
70
55
|
output: route.output ? import_path.default.normalize(route.output) : import_path.default.join(entryPath, `..${route.url === "/" ? "" : route.url}`)
|
|
71
|
-
}
|
|
56
|
+
};
|
|
72
57
|
}
|
|
73
58
|
}
|
|
74
59
|
// Annotate the CommonJS export names for ESM import in node:
|
|
File without changes
|
|
@@ -2,34 +2,8 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __spreadValues = (a, b) => {
|
|
11
|
-
for (var prop in b || (b = {}))
|
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
if (__getOwnPropSymbols)
|
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
-
if (__propIsEnum.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
}
|
|
19
|
-
return a;
|
|
20
|
-
};
|
|
21
|
-
var __objRest = (source, exclude) => {
|
|
22
|
-
var target = {};
|
|
23
|
-
for (var prop in source)
|
|
24
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
-
target[prop] = source[prop];
|
|
26
|
-
if (source != null && __getOwnPropSymbols)
|
|
27
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
}
|
|
31
|
-
return target;
|
|
32
|
-
};
|
|
33
7
|
var __export = (target, all) => {
|
|
34
8
|
for (var name in all)
|
|
35
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -66,7 +40,7 @@ function exist(route, pageRoutes) {
|
|
|
66
40
|
}
|
|
67
41
|
function replaceRoute(ssgRoutes, pageRoutes) {
|
|
68
42
|
const cleanSsgRoutes = ssgRoutes.map((ssgRoute) => {
|
|
69
|
-
const
|
|
43
|
+
const { output, headers, ...cleanSsgRoute } = ssgRoute;
|
|
70
44
|
return Object.assign(
|
|
71
45
|
cleanSsgRoute,
|
|
72
46
|
output ? { entryPath: output } : {}
|
|
@@ -76,7 +50,7 @@ function replaceRoute(ssgRoutes, pageRoutes) {
|
|
|
76
50
|
cleanSsgRoutes.forEach((ssgRoute) => {
|
|
77
51
|
const index = exist(ssgRoute, pageRoutes);
|
|
78
52
|
if (index < 0) {
|
|
79
|
-
freshRoutes.push(
|
|
53
|
+
freshRoutes.push({ ...ssgRoute });
|
|
80
54
|
} else {
|
|
81
55
|
pageRoutes[index].entryPath = ssgRoute.entryPath;
|
|
82
56
|
}
|
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
7
|
var __export = (target, all) => {
|
|
25
8
|
for (var name in all)
|
|
26
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -160,7 +143,8 @@ const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
|
160
143
|
}
|
|
161
144
|
return false;
|
|
162
145
|
};
|
|
163
|
-
const openRouteSSR = (routes, entries = []) => routes.map((ssgRoute) =>
|
|
146
|
+
const openRouteSSR = (routes, entries = []) => routes.map((ssgRoute) => ({
|
|
147
|
+
...ssgRoute,
|
|
164
148
|
isSSR: entries.includes(ssgRoute.entryName),
|
|
165
149
|
bundle: `${import_utils.SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
166
150
|
}));
|
|
@@ -172,14 +156,16 @@ const flattenRoutes = (routes) => {
|
|
|
172
156
|
let path2 = parent ? `${parent.path}/${route.path || ""}`.replace(/\/+/g, "/") : route.path || "";
|
|
173
157
|
path2 = path2.replace(/\/$/, "");
|
|
174
158
|
if (route._component && (path2 !== "/" || path2 === "/" && !parent)) {
|
|
175
|
-
newRoutes.push(
|
|
159
|
+
newRoutes.push({
|
|
160
|
+
...route,
|
|
176
161
|
path: path2
|
|
177
|
-
})
|
|
162
|
+
});
|
|
178
163
|
}
|
|
179
164
|
if (route.children) {
|
|
180
|
-
parents.push(
|
|
165
|
+
parents.push({
|
|
166
|
+
...route,
|
|
181
167
|
path: path2
|
|
182
|
-
})
|
|
168
|
+
});
|
|
183
169
|
route.children.forEach(traverseRoute);
|
|
184
170
|
parents.pop();
|
|
185
171
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
7
|
var __export = (target, all) => {
|
|
25
8
|
for (var name in all)
|
|
26
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -47,9 +30,10 @@ var import_events = __toESM(require("events"));
|
|
|
47
30
|
var import_stream = require("stream");
|
|
48
31
|
var import_node_mocks_http = __toESM(require("node-mocks-http"));
|
|
49
32
|
const compile = (requestHandler) => (options, extend = {}) => new Promise((resolve, reject) => {
|
|
50
|
-
const req = import_node_mocks_http.default.createRequest(
|
|
33
|
+
const req = import_node_mocks_http.default.createRequest({
|
|
34
|
+
...options,
|
|
51
35
|
eventEmitter: import_stream.Readable
|
|
52
|
-
})
|
|
36
|
+
});
|
|
53
37
|
const res = import_node_mocks_http.default.createResponse({ eventEmitter: import_events.default });
|
|
54
38
|
Object.assign(req, extend);
|
|
55
39
|
const proxyRes = new Proxy(res, {
|
|
@@ -16,32 +16,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
16
16
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
17
17
|
mod
|
|
18
18
|
));
|
|
19
|
-
var __async = (__this, __arguments, generator) => {
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
var fulfilled = (value) => {
|
|
22
|
-
try {
|
|
23
|
-
step(generator.next(value));
|
|
24
|
-
} catch (e) {
|
|
25
|
-
reject(e);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var rejected = (value) => {
|
|
29
|
-
try {
|
|
30
|
-
step(generator.throw(value));
|
|
31
|
-
} catch (e) {
|
|
32
|
-
reject(e);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
19
|
var import_prod_server = __toESM(require("@modern-js/prod-server"));
|
|
40
20
|
var import_portfinder = __toESM(require("portfinder"));
|
|
41
21
|
var import_make = require("../libs/make");
|
|
42
22
|
var import_prerender = require("./prerender");
|
|
43
23
|
var import_consts = require("./consts");
|
|
44
|
-
process.on("message", (chunk) =>
|
|
24
|
+
process.on("message", async (chunk) => {
|
|
45
25
|
if (chunk === import_consts.CLOSE_SIGN) {
|
|
46
26
|
process.exit();
|
|
47
27
|
}
|
|
@@ -58,15 +38,15 @@ process.on("message", (chunk) => __async(exports, null, function* () {
|
|
|
58
38
|
const { server: serverOptions } = options;
|
|
59
39
|
const defaultPort = Number(process.env.PORT) || serverOptions.port;
|
|
60
40
|
import_portfinder.default.basePort = defaultPort;
|
|
61
|
-
const port =
|
|
62
|
-
modernServer =
|
|
41
|
+
const port = await import_portfinder.default.getPortPromise();
|
|
42
|
+
modernServer = await (0, import_prod_server.default)({
|
|
63
43
|
pwd: appDirectory,
|
|
64
44
|
config: options,
|
|
65
45
|
routes,
|
|
66
46
|
staticGenerate: true,
|
|
67
47
|
internalPlugins: plugins
|
|
68
48
|
});
|
|
69
|
-
modernServer.listen(port, (err) =>
|
|
49
|
+
modernServer.listen(port, async (err) => {
|
|
70
50
|
if (err) {
|
|
71
51
|
throw err;
|
|
72
52
|
}
|
|
@@ -79,15 +59,15 @@ process.on("message", (chunk) => __async(exports, null, function* () {
|
|
|
79
59
|
render,
|
|
80
60
|
port
|
|
81
61
|
);
|
|
82
|
-
const htmlAry =
|
|
62
|
+
const htmlAry = await Promise.all(renderPromiseAry);
|
|
83
63
|
htmlAry.forEach((html) => {
|
|
84
64
|
process.send(html);
|
|
85
65
|
process.send(null);
|
|
86
66
|
});
|
|
87
67
|
modernServer.close();
|
|
88
|
-
})
|
|
68
|
+
});
|
|
89
69
|
} catch (e) {
|
|
90
70
|
modernServer == null ? void 0 : modernServer.close();
|
|
91
71
|
throw e;
|
|
92
72
|
}
|
|
93
|
-
})
|
|
73
|
+
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { logger, PLUGIN_SCHEMAS } from "@modern-js/utils";
|
|
3
|
+
import { generatePath } from "react-router-dom";
|
|
4
|
+
import {
|
|
5
|
+
flattenRoutes,
|
|
6
|
+
formatOutput,
|
|
7
|
+
isDynamicUrl,
|
|
8
|
+
readJSONSpec,
|
|
9
|
+
standardOptions,
|
|
10
|
+
writeJSONSpec
|
|
11
|
+
} from "./libs/util";
|
|
12
|
+
import { createServer } from "./server";
|
|
13
|
+
import { writeHtmlFile } from "./libs/output";
|
|
14
|
+
import { replaceRoute } from "./libs/replace";
|
|
15
|
+
import { makeRoute } from "./libs/make";
|
|
16
|
+
var src_default = () => ({
|
|
17
|
+
name: "@modern-js/plugin-ssg",
|
|
18
|
+
pre: ["@modern-js/plugin-server", "@modern-js/plugin-bff"],
|
|
19
|
+
setup: (api) => {
|
|
20
|
+
const agreedRouteMap = {};
|
|
21
|
+
return {
|
|
22
|
+
validateSchema() {
|
|
23
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-ssg"];
|
|
24
|
+
},
|
|
25
|
+
modifyFileSystemRoutes({ entrypoint, routes }) {
|
|
26
|
+
const { entryName } = entrypoint;
|
|
27
|
+
const flattedRoutes = flattenRoutes(routes);
|
|
28
|
+
agreedRouteMap[entryName] = flattedRoutes;
|
|
29
|
+
return { entrypoint, routes };
|
|
30
|
+
},
|
|
31
|
+
async afterBuild() {
|
|
32
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
33
|
+
const appContext = api.useAppContext();
|
|
34
|
+
const { appDirectory, entrypoints } = appContext;
|
|
35
|
+
const { output, server } = resolvedConfig;
|
|
36
|
+
const { ssg, distPath: { root: outputPath } = {} } = output;
|
|
37
|
+
const ssgOptions = (Array.isArray(ssg) ? ssg.pop() : ssg) || true;
|
|
38
|
+
const buildDir = path.join(appDirectory, outputPath);
|
|
39
|
+
const routes = readJSONSpec(buildDir);
|
|
40
|
+
const pageRoutes = routes.filter((route) => !route.isApi);
|
|
41
|
+
const apiRoutes = routes.filter((route) => route.isApi);
|
|
42
|
+
if (pageRoutes.length === 0) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const intermediateOptions = standardOptions(
|
|
46
|
+
ssgOptions,
|
|
47
|
+
entrypoints,
|
|
48
|
+
pageRoutes,
|
|
49
|
+
server
|
|
50
|
+
);
|
|
51
|
+
if (!intermediateOptions) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const ssgRoutes = [];
|
|
55
|
+
pageRoutes.forEach((pageRoute) => {
|
|
56
|
+
const { entryName, entryPath } = pageRoute;
|
|
57
|
+
const agreedRoutes = agreedRouteMap[entryName];
|
|
58
|
+
let entryOptions = intermediateOptions[entryName] || intermediateOptions[pageRoute.urlPath];
|
|
59
|
+
if (!agreedRoutes) {
|
|
60
|
+
if (!entryOptions) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (entryOptions === true) {
|
|
64
|
+
ssgRoutes.push({ ...pageRoute, output: entryPath });
|
|
65
|
+
} else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
66
|
+
const { routes: enrtyRoutes, headers } = entryOptions;
|
|
67
|
+
enrtyRoutes.forEach((route) => {
|
|
68
|
+
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
if (!entryOptions) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (entryOptions === true) {
|
|
76
|
+
entryOptions = { preventDefault: [], routes: [], headers: {} };
|
|
77
|
+
}
|
|
78
|
+
const {
|
|
79
|
+
preventDefault = [],
|
|
80
|
+
routes: userRoutes = [],
|
|
81
|
+
headers
|
|
82
|
+
} = entryOptions;
|
|
83
|
+
if (userRoutes.length > 0) {
|
|
84
|
+
userRoutes.forEach((route) => {
|
|
85
|
+
if (typeof route === "string") {
|
|
86
|
+
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
87
|
+
} else if (Array.isArray(route.params)) {
|
|
88
|
+
route.params.forEach((param) => {
|
|
89
|
+
ssgRoutes.push(
|
|
90
|
+
makeRoute(
|
|
91
|
+
pageRoute,
|
|
92
|
+
{ ...route, url: generatePath(route.url, param) },
|
|
93
|
+
headers
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
} else {
|
|
98
|
+
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
agreedRoutes.filter((route) => !preventDefault.includes(route.path)).forEach((route) => {
|
|
103
|
+
if (!isDynamicUrl(route.path)) {
|
|
104
|
+
ssgRoutes.push(makeRoute(pageRoute, route.path, headers));
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
if (ssgRoutes.length === 0) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
ssgRoutes.forEach((ssgRoute) => {
|
|
114
|
+
if (ssgRoute.isSSR) {
|
|
115
|
+
const isOriginRoute = pageRoutes.some(
|
|
116
|
+
(pageRoute) => pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName
|
|
117
|
+
);
|
|
118
|
+
if (isOriginRoute) {
|
|
119
|
+
throw new Error(
|
|
120
|
+
`ssg can not using with ssr,url - ${ssgRoute.urlPath}, entry - ${ssgRoute.entryName} `
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
logger.warn(
|
|
124
|
+
`new ssg route ${ssgRoute.urlPath} is using ssr now,maybe from parent route ${ssgRoute.entryName},close ssr`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
ssgRoute.isSSR = false;
|
|
128
|
+
ssgRoute.output = formatOutput(ssgRoute.output);
|
|
129
|
+
});
|
|
130
|
+
const htmlAry = await createServer(
|
|
131
|
+
api,
|
|
132
|
+
ssgRoutes,
|
|
133
|
+
pageRoutes,
|
|
134
|
+
apiRoutes,
|
|
135
|
+
resolvedConfig,
|
|
136
|
+
appDirectory
|
|
137
|
+
);
|
|
138
|
+
writeHtmlFile(htmlAry, ssgRoutes, buildDir);
|
|
139
|
+
replaceRoute(ssgRoutes, pageRoutes);
|
|
140
|
+
writeJSONSpec(buildDir, pageRoutes.concat(apiRoutes));
|
|
141
|
+
logger.info("ssg Compiled successfully");
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
export {
|
|
147
|
+
src_default as default
|
|
148
|
+
};
|