@modern-js/plugin-ssg 2.14.0 → 2.16.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 +19 -0
- package/dist/cjs/index.js +62 -95
- package/dist/cjs/libs/make.js +34 -48
- package/dist/cjs/libs/output.js +18 -41
- package/dist/cjs/libs/replace.js +24 -41
- package/dist/cjs/libs/util.js +48 -72
- package/dist/cjs/server/consts.js +7 -25
- package/dist/cjs/server/index.js +67 -90
- package/dist/cjs/server/prerender.js +20 -41
- package/dist/cjs/server/process.js +22 -45
- package/dist/cjs/types.js +4 -15
- package/dist/esm/index.js +316 -309
- package/dist/esm/libs/make.js +70 -71
- package/dist/esm/libs/output.js +9 -10
- package/dist/esm/libs/replace.js +113 -100
- package/dist/esm/libs/util.js +211 -210
- package/dist/esm/server/consts.js +1 -2
- package/dist/esm/server/index.js +56 -57
- package/dist/esm/server/prerender.js +85 -86
- package/dist/esm/server/process.js +220 -213
- package/dist/esm/types.js +1 -1
- package/dist/esm-node/index.js +29 -51
- package/dist/esm-node/libs/make.js +14 -14
- package/dist/esm-node/libs/output.js +1 -4
- package/dist/esm-node/libs/replace.js +8 -11
- package/dist/esm-node/libs/util.js +26 -41
- package/dist/esm-node/server/consts.js +1 -4
- package/dist/esm-node/server/index.js +49 -52
- package/dist/esm-node/server/prerender.js +4 -5
- package/dist/esm-node/server/process.js +3 -13
- package/dist/esm-node/types.js +1 -0
- package/package.json +12 -8
package/dist/esm/index.js
CHANGED
|
@@ -1,178 +1,185 @@
|
|
|
1
1
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(void 0);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
function _define_property(obj, key, value) {
|
|
31
|
+
if (key in obj) {
|
|
32
|
+
Object.defineProperty(obj, key, {
|
|
33
|
+
value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
obj[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
ownKeys.forEach(function(key) {
|
|
53
|
-
_defineProperty(target, key, source[key]);
|
|
54
|
-
});
|
|
43
|
+
function _object_spread(target) {
|
|
44
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
45
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
46
|
+
var ownKeys2 = Object.keys(source);
|
|
47
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
48
|
+
ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
49
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
50
|
+
}));
|
|
55
51
|
}
|
|
56
|
-
|
|
52
|
+
ownKeys2.forEach(function(key) {
|
|
53
|
+
_define_property(target, key, source[key]);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return target;
|
|
57
57
|
}
|
|
58
58
|
function ownKeys(object, enumerableOnly) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
keys.push.apply(keys, symbols);
|
|
59
|
+
var keys = Object.keys(object);
|
|
60
|
+
if (Object.getOwnPropertySymbols) {
|
|
61
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
62
|
+
if (enumerableOnly) {
|
|
63
|
+
symbols = symbols.filter(function(sym) {
|
|
64
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
65
|
+
});
|
|
68
66
|
}
|
|
69
|
-
|
|
67
|
+
keys.push.apply(keys, symbols);
|
|
68
|
+
}
|
|
69
|
+
return keys;
|
|
70
70
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
function _object_spread_props(target, source) {
|
|
72
|
+
source = source != null ? source : {};
|
|
73
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
74
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
75
|
+
} else {
|
|
76
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
77
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return target;
|
|
81
81
|
}
|
|
82
|
-
var __generator =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
82
|
+
var __generator = function(thisArg, body) {
|
|
83
|
+
var f, y, t, g, _ = {
|
|
84
|
+
label: 0,
|
|
85
|
+
sent: function() {
|
|
86
|
+
if (t[0] & 1)
|
|
87
|
+
throw t[1];
|
|
88
|
+
return t[1];
|
|
89
|
+
},
|
|
90
|
+
trys: [],
|
|
91
|
+
ops: []
|
|
92
|
+
};
|
|
93
|
+
return g = {
|
|
94
|
+
next: verb(0),
|
|
95
|
+
"throw": verb(1),
|
|
96
|
+
"return": verb(2)
|
|
97
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
98
|
+
return this;
|
|
99
|
+
}), g;
|
|
100
|
+
function verb(n) {
|
|
101
|
+
return function(v) {
|
|
102
|
+
return step([
|
|
103
|
+
n,
|
|
104
|
+
v
|
|
105
|
+
]);
|
|
91
106
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
break;
|
|
120
|
-
case 4:
|
|
121
|
-
_.label++;
|
|
122
|
-
return {
|
|
123
|
-
value: op[1],
|
|
124
|
-
done: false
|
|
125
|
-
};
|
|
126
|
-
case 5:
|
|
127
|
-
_.label++;
|
|
128
|
-
y = op[1];
|
|
129
|
-
op = [
|
|
130
|
-
0
|
|
131
|
-
];
|
|
132
|
-
continue;
|
|
133
|
-
case 7:
|
|
134
|
-
op = _.ops.pop();
|
|
135
|
-
_.trys.pop();
|
|
136
|
-
continue;
|
|
137
|
-
default:
|
|
138
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
139
|
-
_ = 0;
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
143
|
-
_.label = op[1];
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
147
|
-
_.label = t[1];
|
|
148
|
-
t = op;
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
if (t && _.label < t[2]) {
|
|
152
|
-
_.label = t[2];
|
|
153
|
-
_.ops.push(op);
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
if (t[2]) _.ops.pop();
|
|
157
|
-
_.trys.pop();
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
op = body.call(thisArg, _);
|
|
161
|
-
} catch (e) {
|
|
107
|
+
}
|
|
108
|
+
function step(op) {
|
|
109
|
+
if (f)
|
|
110
|
+
throw new TypeError("Generator is already executing.");
|
|
111
|
+
while (_)
|
|
112
|
+
try {
|
|
113
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
114
|
+
return t;
|
|
115
|
+
if (y = 0, t)
|
|
116
|
+
op = [
|
|
117
|
+
op[0] & 2,
|
|
118
|
+
t.value
|
|
119
|
+
];
|
|
120
|
+
switch (op[0]) {
|
|
121
|
+
case 0:
|
|
122
|
+
case 1:
|
|
123
|
+
t = op;
|
|
124
|
+
break;
|
|
125
|
+
case 4:
|
|
126
|
+
_.label++;
|
|
127
|
+
return {
|
|
128
|
+
value: op[1],
|
|
129
|
+
done: false
|
|
130
|
+
};
|
|
131
|
+
case 5:
|
|
132
|
+
_.label++;
|
|
133
|
+
y = op[1];
|
|
162
134
|
op = [
|
|
163
|
-
|
|
164
|
-
e
|
|
135
|
+
0
|
|
165
136
|
];
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
137
|
+
continue;
|
|
138
|
+
case 7:
|
|
139
|
+
op = _.ops.pop();
|
|
140
|
+
_.trys.pop();
|
|
141
|
+
continue;
|
|
142
|
+
default:
|
|
143
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
144
|
+
_ = 0;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
148
|
+
_.label = op[1];
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
152
|
+
_.label = t[1];
|
|
153
|
+
t = op;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
if (t && _.label < t[2]) {
|
|
157
|
+
_.label = t[2];
|
|
158
|
+
_.ops.push(op);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
if (t[2])
|
|
162
|
+
_.ops.pop();
|
|
163
|
+
_.trys.pop();
|
|
164
|
+
continue;
|
|
169
165
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
166
|
+
op = body.call(thisArg, _);
|
|
167
|
+
} catch (e) {
|
|
168
|
+
op = [
|
|
169
|
+
6,
|
|
170
|
+
e
|
|
171
|
+
];
|
|
172
|
+
y = 0;
|
|
173
|
+
} finally {
|
|
174
|
+
f = t = 0;
|
|
175
|
+
}
|
|
176
|
+
if (op[0] & 5)
|
|
177
|
+
throw op[1];
|
|
178
|
+
return {
|
|
179
|
+
value: op[0] ? op[1] : void 0,
|
|
180
|
+
done: true
|
|
181
|
+
};
|
|
182
|
+
}
|
|
176
183
|
};
|
|
177
184
|
import path from "path";
|
|
178
185
|
import { logger, PLUGIN_SCHEMAS } from "@modern-js/utils";
|
|
@@ -182,153 +189,153 @@ import { createServer } from "./server";
|
|
|
182
189
|
import { writeHtmlFile } from "./libs/output";
|
|
183
190
|
import { replaceRoute } from "./libs/replace";
|
|
184
191
|
import { makeRoute } from "./libs/make";
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
} else {
|
|
259
|
-
if (!entryOptions) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
if (entryOptions === true) {
|
|
263
|
-
entryOptions = {
|
|
264
|
-
preventDefault: [],
|
|
265
|
-
routes: [],
|
|
266
|
-
headers: {}
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
var _entryOptions_preventDefault = entryOptions.preventDefault, preventDefault = _entryOptions_preventDefault === void 0 ? [] : _entryOptions_preventDefault, tmp = entryOptions.routes, userRoutes = tmp === void 0 ? [] : tmp, headers1 = entryOptions.headers;
|
|
270
|
-
if (userRoutes.length > 0) {
|
|
271
|
-
userRoutes.forEach(function(route) {
|
|
272
|
-
if (typeof route === "string") {
|
|
273
|
-
ssgRoutes.push(makeRoute(pageRoute, route, headers1));
|
|
274
|
-
} else if (Array.isArray(route.params)) {
|
|
275
|
-
route.params.forEach(function(param) {
|
|
276
|
-
ssgRoutes.push(makeRoute(pageRoute, _objectSpreadProps(_objectSpread({}, route), {
|
|
277
|
-
url: generatePath(route.url, param)
|
|
278
|
-
}), headers1));
|
|
279
|
-
});
|
|
280
|
-
} else {
|
|
281
|
-
ssgRoutes.push(makeRoute(pageRoute, route, headers1));
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
} else {
|
|
285
|
-
agreedRoutes.filter(function(route) {
|
|
286
|
-
return !preventDefault.includes(route.path);
|
|
287
|
-
}).forEach(function(route) {
|
|
288
|
-
if (!isDynamicUrl(route.path)) {
|
|
289
|
-
ssgRoutes.push(makeRoute(pageRoute, route.path, headers1));
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
if (ssgRoutes.length === 0) {
|
|
296
|
-
return [
|
|
297
|
-
2
|
|
298
|
-
];
|
|
299
|
-
}
|
|
300
|
-
ssgRoutes.forEach(function(ssgRoute) {
|
|
301
|
-
if (ssgRoute.isSSR) {
|
|
302
|
-
var isOriginRoute = pageRoutes.some(function(pageRoute) {
|
|
303
|
-
return pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName;
|
|
304
|
-
});
|
|
305
|
-
if (isOriginRoute) {
|
|
306
|
-
throw new Error("ssg can not using with ssr,url - ".concat(ssgRoute.urlPath, ", entry - ").concat(ssgRoute.entryName, " "));
|
|
307
|
-
}
|
|
308
|
-
logger.warn("new ssg route ".concat(ssgRoute.urlPath, " is using ssr now,maybe from parent route ").concat(ssgRoute.entryName, ",close ssr"));
|
|
309
|
-
}
|
|
310
|
-
ssgRoute.isSSR = false;
|
|
311
|
-
ssgRoute.output = formatOutput(ssgRoute.output);
|
|
312
|
-
});
|
|
313
|
-
return [
|
|
314
|
-
4,
|
|
315
|
-
createServer(api, ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory)
|
|
316
|
-
];
|
|
317
|
-
case 1:
|
|
318
|
-
htmlAry = _state.sent();
|
|
319
|
-
writeHtmlFile(htmlAry, ssgRoutes, buildDir);
|
|
320
|
-
replaceRoute(ssgRoutes, pageRoutes);
|
|
321
|
-
writeJSONSpec(buildDir, pageRoutes.concat(apiRoutes));
|
|
322
|
-
logger.info("ssg Compiled successfully");
|
|
323
|
-
return [
|
|
324
|
-
2
|
|
325
|
-
];
|
|
326
|
-
}
|
|
192
|
+
export default function() {
|
|
193
|
+
return {
|
|
194
|
+
name: "@modern-js/plugin-ssg",
|
|
195
|
+
pre: [
|
|
196
|
+
"@modern-js/plugin-server",
|
|
197
|
+
"@modern-js/plugin-bff"
|
|
198
|
+
],
|
|
199
|
+
setup: function(api) {
|
|
200
|
+
var agreedRouteMap = {};
|
|
201
|
+
return {
|
|
202
|
+
validateSchema: function validateSchema() {
|
|
203
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-ssg"];
|
|
204
|
+
},
|
|
205
|
+
modifyFileSystemRoutes: function modifyFileSystemRoutes(param) {
|
|
206
|
+
var entrypoint = param.entrypoint, routes = param.routes;
|
|
207
|
+
var entryName = entrypoint.entryName;
|
|
208
|
+
var flattedRoutes = flattenRoutes(routes);
|
|
209
|
+
agreedRouteMap[entryName] = flattedRoutes;
|
|
210
|
+
return {
|
|
211
|
+
entrypoint,
|
|
212
|
+
routes
|
|
213
|
+
};
|
|
214
|
+
},
|
|
215
|
+
afterBuild: function afterBuild() {
|
|
216
|
+
return _async_to_generator(function() {
|
|
217
|
+
var resolvedConfig, appContext, appDirectory, entrypoints, output, server, ssg, tmp, _ref, outputPath, ssgOptions, buildDir, routes, pageRoutes, apiRoutes, intermediateOptions, ssgRoutes, htmlAry;
|
|
218
|
+
return __generator(this, function(_state) {
|
|
219
|
+
switch (_state.label) {
|
|
220
|
+
case 0:
|
|
221
|
+
resolvedConfig = api.useResolvedConfigContext();
|
|
222
|
+
appContext = api.useAppContext();
|
|
223
|
+
appDirectory = appContext.appDirectory, entrypoints = appContext.entrypoints;
|
|
224
|
+
output = resolvedConfig.output, server = resolvedConfig.server;
|
|
225
|
+
ssg = output.ssg, tmp = output.distPath, _ref = tmp === void 0 ? {} : tmp, outputPath = _ref.root;
|
|
226
|
+
ssgOptions = (Array.isArray(ssg) ? ssg.pop() : ssg) || true;
|
|
227
|
+
buildDir = path.join(appDirectory, outputPath);
|
|
228
|
+
routes = readJSONSpec(buildDir);
|
|
229
|
+
pageRoutes = routes.filter(function(route) {
|
|
230
|
+
return !route.isApi;
|
|
231
|
+
});
|
|
232
|
+
apiRoutes = routes.filter(function(route) {
|
|
233
|
+
return route.isApi;
|
|
234
|
+
});
|
|
235
|
+
if (pageRoutes.length === 0) {
|
|
236
|
+
return [
|
|
237
|
+
2
|
|
238
|
+
];
|
|
239
|
+
}
|
|
240
|
+
intermediateOptions = standardOptions(ssgOptions, entrypoints, pageRoutes, server);
|
|
241
|
+
if (!intermediateOptions) {
|
|
242
|
+
return [
|
|
243
|
+
2
|
|
244
|
+
];
|
|
245
|
+
}
|
|
246
|
+
ssgRoutes = [];
|
|
247
|
+
pageRoutes.forEach(function(pageRoute) {
|
|
248
|
+
var entryName = pageRoute.entryName, entryPath = pageRoute.entryPath;
|
|
249
|
+
var agreedRoutes = agreedRouteMap[entryName];
|
|
250
|
+
var entryOptions = intermediateOptions[entryName] || intermediateOptions[pageRoute.urlPath];
|
|
251
|
+
if (!agreedRoutes) {
|
|
252
|
+
if (!entryOptions) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (entryOptions === true) {
|
|
256
|
+
ssgRoutes.push(_object_spread_props(_object_spread({}, pageRoute), {
|
|
257
|
+
output: entryPath
|
|
258
|
+
}));
|
|
259
|
+
} else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
260
|
+
var enrtyRoutes = entryOptions.routes, headers = entryOptions.headers;
|
|
261
|
+
enrtyRoutes.forEach(function(route) {
|
|
262
|
+
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
327
263
|
});
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
264
|
+
}
|
|
265
|
+
} else {
|
|
266
|
+
if (!entryOptions) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (entryOptions === true) {
|
|
270
|
+
entryOptions = {
|
|
271
|
+
preventDefault: [],
|
|
272
|
+
routes: [],
|
|
273
|
+
headers: {}
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
var _entryOptions_preventDefault = entryOptions.preventDefault, preventDefault = _entryOptions_preventDefault === void 0 ? [] : _entryOptions_preventDefault, tmp2 = entryOptions.routes, userRoutes = tmp2 === void 0 ? [] : tmp2, headers1 = entryOptions.headers;
|
|
277
|
+
if (userRoutes.length > 0) {
|
|
278
|
+
userRoutes.forEach(function(route) {
|
|
279
|
+
if (typeof route === "string") {
|
|
280
|
+
ssgRoutes.push(makeRoute(pageRoute, route, headers1));
|
|
281
|
+
} else if (Array.isArray(route.params)) {
|
|
282
|
+
route.params.forEach(function(param) {
|
|
283
|
+
ssgRoutes.push(makeRoute(pageRoute, _object_spread_props(_object_spread({}, route), {
|
|
284
|
+
url: generatePath(route.url, param)
|
|
285
|
+
}), headers1));
|
|
286
|
+
});
|
|
287
|
+
} else {
|
|
288
|
+
ssgRoutes.push(makeRoute(pageRoute, route, headers1));
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
} else {
|
|
292
|
+
agreedRoutes.filter(function(route) {
|
|
293
|
+
return !preventDefault.includes(route.path);
|
|
294
|
+
}).forEach(function(route) {
|
|
295
|
+
if (!isDynamicUrl(route.path)) {
|
|
296
|
+
ssgRoutes.push(makeRoute(pageRoute, route.path, headers1));
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
if (ssgRoutes.length === 0) {
|
|
303
|
+
return [
|
|
304
|
+
2
|
|
305
|
+
];
|
|
306
|
+
}
|
|
307
|
+
ssgRoutes.forEach(function(ssgRoute) {
|
|
308
|
+
if (ssgRoute.isSSR) {
|
|
309
|
+
var isOriginRoute = pageRoutes.some(function(pageRoute) {
|
|
310
|
+
return pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName;
|
|
311
|
+
});
|
|
312
|
+
if (isOriginRoute) {
|
|
313
|
+
throw new Error("ssg can not using with ssr,url - ".concat(ssgRoute.urlPath, ", entry - ").concat(ssgRoute.entryName, " "));
|
|
314
|
+
}
|
|
315
|
+
logger.warn("new ssg route ".concat(ssgRoute.urlPath, " is using ssr now,maybe from parent route ").concat(ssgRoute.entryName, ",close ssr"));
|
|
316
|
+
}
|
|
317
|
+
ssgRoute.isSSR = false;
|
|
318
|
+
ssgRoute.output = formatOutput(ssgRoute.output);
|
|
319
|
+
});
|
|
320
|
+
return [
|
|
321
|
+
4,
|
|
322
|
+
createServer(api, ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory)
|
|
323
|
+
];
|
|
324
|
+
case 1:
|
|
325
|
+
htmlAry = _state.sent();
|
|
326
|
+
writeHtmlFile(htmlAry, ssgRoutes, buildDir);
|
|
327
|
+
replaceRoute(ssgRoutes, pageRoutes);
|
|
328
|
+
writeJSONSpec(buildDir, pageRoutes.concat(apiRoutes));
|
|
329
|
+
logger.info("ssg Compiled successfully");
|
|
330
|
+
return [
|
|
331
|
+
2
|
|
332
|
+
];
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
})();
|
|
331
336
|
}
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
;
|