@modern-js/plugin-ssg 2.0.0-beta.3 → 2.0.0-beta.4
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 +36 -0
- package/dist/js/modern/global.d.js +0 -0
- package/dist/js/modern/index.js +171 -155
- package/dist/js/modern/libs/make.js +44 -27
- package/dist/js/modern/libs/output.js +7 -4
- package/dist/js/modern/libs/replace.js +45 -27
- package/dist/js/modern/libs/util.js +91 -76
- package/dist/js/modern/server/consts.js +4 -1
- package/dist/js/modern/server/index.js +31 -28
- package/dist/js/modern/server/prerender.js +32 -15
- package/dist/js/modern/server/process.js +78 -57
- package/dist/js/modern/types.js +0 -1
- package/dist/js/node/global.d.js +0 -0
- package/dist/js/node/index.js +192 -166
- package/dist/js/node/libs/make.js +66 -32
- package/dist/js/node/libs/output.js +34 -13
- package/dist/js/node/libs/replace.js +68 -33
- package/dist/js/node/libs/util.js +107 -91
- package/dist/js/node/server/consts.js +22 -7
- package/dist/js/node/server/index.js +59 -39
- package/dist/js/node/server/prerender.js +56 -22
- package/dist/js/node/server/process.js +108 -62
- package/dist/js/node/types.js +0 -5
- package/dist/js/treeshaking/global.d.js +1 -0
- package/dist/js/treeshaking/index.js +339 -0
- package/dist/js/treeshaking/libs/make.js +83 -0
- package/dist/js/treeshaking/libs/output.js +13 -0
- package/dist/js/treeshaking/libs/replace.js +115 -0
- package/dist/js/treeshaking/libs/util.js +239 -0
- package/dist/js/treeshaking/server/consts.js +2 -0
- package/dist/js/treeshaking/server/index.js +63 -0
- package/dist/js/treeshaking/server/prerender.js +97 -0
- package/dist/js/treeshaking/server/process.js +226 -0
- package/dist/js/treeshaking/types.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/libs/util.d.ts +0 -1
- package/package.json +7 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# @modern-js/plugin-ssg
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.4
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9c3e: chore: v2
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 6604f1b: feat: support router basename
|
|
12
|
+
feat: router 插件支持设置 basename
|
|
13
|
+
- cc971eabfc: refactor: move server plugin load logic in `@modern-js/core`
|
|
14
|
+
refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑
|
|
15
|
+
- 8b8e1bb571: feat: support nested routes
|
|
16
|
+
feat: 支持嵌套路由
|
|
17
|
+
- Updated dependencies [7879e8f]
|
|
18
|
+
- Updated dependencies [6aca875]
|
|
19
|
+
- Updated dependencies [2e6031955e]
|
|
20
|
+
- Updated dependencies [7b7d12c]
|
|
21
|
+
- Updated dependencies [92f0eade39]
|
|
22
|
+
- Updated dependencies [edd1cfb1af]
|
|
23
|
+
- Updated dependencies [cc971eabfc]
|
|
24
|
+
- Updated dependencies [5b9049f2e9]
|
|
25
|
+
- Updated dependencies [92004d1906]
|
|
26
|
+
- Updated dependencies [b8bbe036c7]
|
|
27
|
+
- Updated dependencies [d5a31df781]
|
|
28
|
+
- Updated dependencies [dda38c9c3e]
|
|
29
|
+
- Updated dependencies [3bbea92b2a]
|
|
30
|
+
- Updated dependencies [b710adb843]
|
|
31
|
+
- Updated dependencies [ea7cf06]
|
|
32
|
+
- Updated dependencies [bbe4c4a]
|
|
33
|
+
- Updated dependencies [e4558a0]
|
|
34
|
+
- Updated dependencies [abf3421a75]
|
|
35
|
+
- Updated dependencies [543be9558e]
|
|
36
|
+
- Updated dependencies [14b712da84]
|
|
37
|
+
- @modern-js/utils@2.0.0-beta.4
|
|
38
|
+
|
|
3
39
|
## 2.0.0-beta.3
|
|
4
40
|
|
|
5
41
|
### Major Changes
|
|
File without changes
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1,176 +1,192 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
import path from "path";
|
|
41
|
+
import { logger, PLUGIN_SCHEMAS } from "@modern-js/utils";
|
|
42
|
+
import { generatePath } from "react-router-dom";
|
|
43
|
+
import {
|
|
44
|
+
flattenRoutes,
|
|
45
|
+
formatOutput,
|
|
46
|
+
isDynamicUrl,
|
|
47
|
+
readJSONSpec,
|
|
48
|
+
standardOptions,
|
|
49
|
+
writeJSONSpec
|
|
50
|
+
} from "./libs/util";
|
|
8
51
|
import { createServer } from "./server";
|
|
9
52
|
import { writeHtmlFile } from "./libs/output";
|
|
10
53
|
import { replaceRoute } from "./libs/replace";
|
|
11
54
|
import { makeRoute } from "./libs/make";
|
|
12
|
-
|
|
13
|
-
name:
|
|
14
|
-
pre: [
|
|
15
|
-
setup: api => {
|
|
55
|
+
var src_default = () => ({
|
|
56
|
+
name: "@modern-js/plugin-ssg",
|
|
57
|
+
pre: ["@modern-js/plugin-server", "@modern-js/plugin-bff"],
|
|
58
|
+
setup: (api) => {
|
|
16
59
|
const agreedRouteMap = {};
|
|
17
60
|
return {
|
|
18
61
|
validateSchema() {
|
|
19
|
-
return PLUGIN_SCHEMAS[
|
|
62
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-ssg"];
|
|
20
63
|
},
|
|
21
|
-
modifyFileSystemRoutes({
|
|
22
|
-
entrypoint
|
|
23
|
-
routes
|
|
24
|
-
}) {
|
|
25
|
-
const {
|
|
26
|
-
entryName
|
|
27
|
-
} = entrypoint;
|
|
64
|
+
modifyFileSystemRoutes({ entrypoint, routes }) {
|
|
65
|
+
const { entryName } = entrypoint;
|
|
28
66
|
const flattedRoutes = flattenRoutes(routes);
|
|
29
67
|
agreedRouteMap[entryName] = flattedRoutes;
|
|
30
|
-
return {
|
|
31
|
-
entrypoint,
|
|
32
|
-
routes
|
|
33
|
-
};
|
|
68
|
+
return { entrypoint, routes };
|
|
34
69
|
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
appDirectory,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// only add entry route if entryOptions is true
|
|
88
|
-
if (entryOptions === true) {
|
|
89
|
-
ssgRoutes.push(_objectSpread(_objectSpread({}, pageRoute), {}, {
|
|
90
|
-
output: entryPath
|
|
91
|
-
}));
|
|
92
|
-
} else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
93
|
-
// if entryOptions is object and has routes options
|
|
94
|
-
// add every route in options
|
|
70
|
+
afterBuild() {
|
|
71
|
+
return __async(this, null, function* () {
|
|
72
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
73
|
+
const appContext = api.useAppContext();
|
|
74
|
+
const { appDirectory, entrypoints } = appContext;
|
|
75
|
+
const { output, server } = resolvedConfig;
|
|
76
|
+
const { ssg, distPath: { root: outputPath } = {} } = output;
|
|
77
|
+
const ssgOptions = Array.isArray(ssg) ? ssg.pop() : ssg;
|
|
78
|
+
if (!ssgOptions) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const buildDir = path.join(appDirectory, outputPath);
|
|
82
|
+
const routes = readJSONSpec(buildDir);
|
|
83
|
+
const pageRoutes = routes.filter((route) => !route.isApi);
|
|
84
|
+
const apiRoutes = routes.filter((route) => route.isApi);
|
|
85
|
+
if (pageRoutes.length === 0) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const intermediateOptions = standardOptions(
|
|
89
|
+
ssgOptions,
|
|
90
|
+
entrypoints,
|
|
91
|
+
pageRoutes,
|
|
92
|
+
server
|
|
93
|
+
);
|
|
94
|
+
if (!intermediateOptions) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const ssgRoutes = [];
|
|
98
|
+
pageRoutes.forEach((pageRoute) => {
|
|
99
|
+
const { entryName, entryPath } = pageRoute;
|
|
100
|
+
const agreedRoutes = agreedRouteMap[entryName];
|
|
101
|
+
let entryOptions = intermediateOptions[entryName] || intermediateOptions[pageRoute.urlPath];
|
|
102
|
+
if (!agreedRoutes) {
|
|
103
|
+
if (!entryOptions) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (entryOptions === true) {
|
|
107
|
+
ssgRoutes.push(__spreadProps(__spreadValues({}, pageRoute), { output: entryPath }));
|
|
108
|
+
} else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
109
|
+
const { routes: enrtyRoutes, headers } = entryOptions;
|
|
110
|
+
enrtyRoutes.forEach((route) => {
|
|
111
|
+
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
if (!entryOptions) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (entryOptions === true) {
|
|
119
|
+
entryOptions = { preventDefault: [], routes: [], headers: {} };
|
|
120
|
+
}
|
|
95
121
|
const {
|
|
96
|
-
|
|
122
|
+
preventDefault = [],
|
|
123
|
+
routes: userRoutes = [],
|
|
97
124
|
headers
|
|
98
125
|
} = entryOptions;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (typeof route === 'string') {
|
|
125
|
-
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
126
|
-
} else if (Array.isArray(route.params)) {
|
|
127
|
-
route.params.forEach(param => {
|
|
128
|
-
ssgRoutes.push(makeRoute(pageRoute, _objectSpread(_objectSpread({}, route), {}, {
|
|
129
|
-
url: generatePath(route.url, param)
|
|
130
|
-
}), headers));
|
|
131
|
-
});
|
|
132
|
-
} else {
|
|
133
|
-
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
} else {
|
|
137
|
-
// otherwith add all except dynamic routes
|
|
138
|
-
agreedRoutes.filter(route => !preventDefault.includes(route.path)).forEach(route => {
|
|
139
|
-
if (!isDynamicUrl(route.path)) {
|
|
140
|
-
ssgRoutes.push(makeRoute(pageRoute, route.path, headers));
|
|
141
|
-
}
|
|
142
|
-
});
|
|
126
|
+
if (userRoutes.length > 0) {
|
|
127
|
+
userRoutes.forEach((route) => {
|
|
128
|
+
if (typeof route === "string") {
|
|
129
|
+
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
130
|
+
} else if (Array.isArray(route.params)) {
|
|
131
|
+
route.params.forEach((param) => {
|
|
132
|
+
ssgRoutes.push(
|
|
133
|
+
makeRoute(
|
|
134
|
+
pageRoute,
|
|
135
|
+
__spreadProps(__spreadValues({}, route), { url: generatePath(route.url, param) }),
|
|
136
|
+
headers
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
} else {
|
|
141
|
+
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
} else {
|
|
145
|
+
agreedRoutes.filter((route) => !preventDefault.includes(route.path)).forEach((route) => {
|
|
146
|
+
if (!isDynamicUrl(route.path)) {
|
|
147
|
+
ssgRoutes.push(makeRoute(pageRoute, route.path, headers));
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
143
151
|
}
|
|
152
|
+
});
|
|
153
|
+
if (ssgRoutes.length === 0) {
|
|
154
|
+
return;
|
|
144
155
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
+
ssgRoutes.forEach((ssgRoute) => {
|
|
157
|
+
if (ssgRoute.isSSR) {
|
|
158
|
+
const isOriginRoute = pageRoutes.some(
|
|
159
|
+
(pageRoute) => pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName
|
|
160
|
+
);
|
|
161
|
+
if (isOriginRoute) {
|
|
162
|
+
throw new Error(
|
|
163
|
+
`ssg can not using with ssr,url - ${ssgRoute.urlPath}, entry - ${ssgRoute.entryName} `
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
logger.warn(
|
|
167
|
+
`new ssg route ${ssgRoute.urlPath} is using ssr now,maybe from parent route ${ssgRoute.entryName},close ssr`
|
|
168
|
+
);
|
|
156
169
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
170
|
+
ssgRoute.isSSR = false;
|
|
171
|
+
ssgRoute.output = formatOutput(ssgRoute.output);
|
|
172
|
+
});
|
|
173
|
+
const htmlAry = yield createServer(
|
|
174
|
+
api,
|
|
175
|
+
ssgRoutes,
|
|
176
|
+
pageRoutes,
|
|
177
|
+
apiRoutes,
|
|
178
|
+
resolvedConfig,
|
|
179
|
+
appDirectory
|
|
180
|
+
);
|
|
181
|
+
writeHtmlFile(htmlAry, ssgRoutes, buildDir);
|
|
182
|
+
replaceRoute(ssgRoutes, pageRoutes);
|
|
183
|
+
writeJSONSpec(buildDir, pageRoutes.concat(apiRoutes));
|
|
184
|
+
logger.info("ssg Compiled successfully");
|
|
161
185
|
});
|
|
162
|
-
const htmlAry = await createServer(api, ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory);
|
|
163
|
-
|
|
164
|
-
// write to dist file
|
|
165
|
-
writeHtmlFile(htmlAry, ssgRoutes, buildDir);
|
|
166
|
-
|
|
167
|
-
// format route info, side effect
|
|
168
|
-
replaceRoute(ssgRoutes, pageRoutes);
|
|
169
|
-
|
|
170
|
-
// write routes to spec file
|
|
171
|
-
writeJSONSpec(buildDir, pageRoutes.concat(apiRoutes));
|
|
172
|
-
logger.info('ssg Compiled successfully');
|
|
173
186
|
}
|
|
174
187
|
};
|
|
175
188
|
}
|
|
176
|
-
})
|
|
189
|
+
});
|
|
190
|
+
export {
|
|
191
|
+
src_default as default
|
|
192
|
+
};
|
|
@@ -1,33 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import path from "path";
|
|
21
|
+
import normalize from "normalize-path";
|
|
22
|
+
function makeRender(ssgRoutes, render, port) {
|
|
23
|
+
return ssgRoutes.map(
|
|
24
|
+
(ssgRoute) => render({
|
|
25
|
+
url: ssgRoute.urlPath,
|
|
26
|
+
headers: __spreadValues({ host: `localhost:${port}` }, ssgRoute.headers),
|
|
27
|
+
connection: {}
|
|
28
|
+
})
|
|
29
|
+
);
|
|
14
30
|
}
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (typeof route === 'string') {
|
|
21
|
-
return _objectSpread(_objectSpread({}, baseRoute), {}, {
|
|
22
|
-
urlPath: normalize(`${urlPath}${route}`) || '/',
|
|
31
|
+
function makeRoute(baseRoute, route, headers = {}) {
|
|
32
|
+
const { urlPath, entryPath } = baseRoute;
|
|
33
|
+
if (typeof route === "string") {
|
|
34
|
+
return __spreadProps(__spreadValues({}, baseRoute), {
|
|
35
|
+
urlPath: normalize(`${urlPath}${route}`) || "/",
|
|
23
36
|
headers,
|
|
24
|
-
output: path.join(entryPath, `..${route ===
|
|
37
|
+
output: path.join(entryPath, `..${route === "/" ? "" : route}`)
|
|
25
38
|
});
|
|
26
39
|
} else {
|
|
27
|
-
return
|
|
28
|
-
urlPath: normalize(`${urlPath}${route.url}`) ||
|
|
29
|
-
headers:
|
|
30
|
-
output: route.output ? path.normalize(route.output) : path.join(entryPath, `..${route.url ===
|
|
40
|
+
return __spreadProps(__spreadValues({}, baseRoute), {
|
|
41
|
+
urlPath: normalize(`${urlPath}${route.url}`) || "/",
|
|
42
|
+
headers: __spreadValues(__spreadValues({}, headers), route.headers),
|
|
43
|
+
output: route.output ? path.normalize(route.output) : path.join(entryPath, `..${route.url === "/" ? "" : route.url}`)
|
|
31
44
|
});
|
|
32
45
|
}
|
|
33
|
-
}
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
makeRender,
|
|
49
|
+
makeRoute
|
|
50
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import { fs } from
|
|
3
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { fs } from "@modern-js/utils";
|
|
3
|
+
function writeHtmlFile(htmlAry, ssgRoutes, baseDir) {
|
|
4
4
|
htmlAry.forEach((html, index) => {
|
|
5
5
|
const ssgRoute = ssgRoutes[index];
|
|
6
6
|
const filepath = path.join(baseDir, ssgRoute.output);
|
|
@@ -9,4 +9,7 @@ export function writeHtmlFile(htmlAry, ssgRoutes, baseDir) {
|
|
|
9
9
|
}
|
|
10
10
|
fs.writeFileSync(filepath, html);
|
|
11
11
|
});
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
writeHtmlFile
|
|
15
|
+
};
|
|
@@ -1,12 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __objRest = (source, exclude) => {
|
|
18
|
+
var target = {};
|
|
19
|
+
for (var prop in source)
|
|
20
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
21
|
+
target[prop] = source[prop];
|
|
22
|
+
if (source != null && __getOwnPropSymbols)
|
|
23
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
24
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
};
|
|
29
|
+
import normalize from "normalize-path";
|
|
30
|
+
function exist(route, pageRoutes) {
|
|
31
|
+
return pageRoutes.slice().findIndex((pageRoute) => {
|
|
10
32
|
const urlEqual = normalize(pageRoute.urlPath) === normalize(route.urlPath);
|
|
11
33
|
const entryEqual = pageRoute.entryName === route.entryName;
|
|
12
34
|
if (urlEqual && entryEqual) {
|
|
@@ -15,31 +37,27 @@ export function exist(route, pageRoutes) {
|
|
|
15
37
|
return false;
|
|
16
38
|
});
|
|
17
39
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
cleanSsgRoute = _objectWithoutProperties(ssgRoute, _excluded);
|
|
26
|
-
return Object.assign(cleanSsgRoute, output ? {
|
|
27
|
-
entryPath: output
|
|
28
|
-
} : {});
|
|
40
|
+
function replaceRoute(ssgRoutes, pageRoutes) {
|
|
41
|
+
const cleanSsgRoutes = ssgRoutes.map((ssgRoute) => {
|
|
42
|
+
const _a = ssgRoute, { output, headers } = _a, cleanSsgRoute = __objRest(_a, ["output", "headers"]);
|
|
43
|
+
return Object.assign(
|
|
44
|
+
cleanSsgRoute,
|
|
45
|
+
output ? { entryPath: output } : {}
|
|
46
|
+
);
|
|
29
47
|
});
|
|
30
|
-
|
|
31
|
-
// all routes that need to be added and replaced
|
|
32
48
|
const freshRoutes = [];
|
|
33
|
-
cleanSsgRoutes.forEach(ssgRoute => {
|
|
49
|
+
cleanSsgRoutes.forEach((ssgRoute) => {
|
|
34
50
|
const index = exist(ssgRoute, pageRoutes);
|
|
35
51
|
if (index < 0) {
|
|
36
|
-
|
|
37
|
-
freshRoutes.push(_objectSpread({}, ssgRoute));
|
|
52
|
+
freshRoutes.push(__spreadValues({}, ssgRoute));
|
|
38
53
|
} else {
|
|
39
|
-
// overwrite original entry
|
|
40
54
|
pageRoutes[index].entryPath = ssgRoute.entryPath;
|
|
41
55
|
}
|
|
42
56
|
});
|
|
43
57
|
pageRoutes.push(...freshRoutes);
|
|
44
58
|
return pageRoutes;
|
|
45
|
-
}
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
exist,
|
|
62
|
+
replaceRoute
|
|
63
|
+
};
|