@modern-js/plugin-ssg 2.0.0-beta.3 → 2.0.0-beta.6
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 +73 -0
- package/dist/js/modern/global.d.js +0 -0
- package/dist/js/modern/index.js +168 -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 +189 -166
- package/dist/js/node/libs/make.js +69 -32
- package/dist/js/node/libs/output.js +38 -13
- package/dist/js/node/libs/replace.js +71 -33
- package/dist/js/node/libs/util.js +119 -91
- package/dist/js/node/server/consts.js +26 -7
- package/dist/js/node/server/index.js +63 -39
- package/dist/js/node/server/prerender.js +58 -22
- package/dist/js/node/server/process.js +61 -34
- package/dist/js/node/types.js +15 -5
- package/dist/js/treeshaking/global.d.js +1 -0
- package/dist/js/treeshaking/index.js +334 -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 +9 -14
package/dist/js/node/index.js
CHANGED
|
@@ -1,184 +1,207 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
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
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
40
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
var __async = (__this, __arguments, generator) => {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
var fulfilled = (value) => {
|
|
44
|
+
try {
|
|
45
|
+
step(generator.next(value));
|
|
46
|
+
} catch (e) {
|
|
47
|
+
reject(e);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var rejected = (value) => {
|
|
51
|
+
try {
|
|
52
|
+
step(generator.throw(value));
|
|
53
|
+
} catch (e) {
|
|
54
|
+
reject(e);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
58
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
var src_exports = {};
|
|
62
|
+
__export(src_exports, {
|
|
63
|
+
default: () => src_default
|
|
5
64
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var _default = () => ({
|
|
20
|
-
name: '@modern-js/plugin-ssg',
|
|
21
|
-
pre: ['@modern-js/plugin-server', '@modern-js/plugin-bff'],
|
|
22
|
-
setup: api => {
|
|
65
|
+
module.exports = __toCommonJS(src_exports);
|
|
66
|
+
var import_path = __toESM(require("path"));
|
|
67
|
+
var import_utils = require("@modern-js/utils");
|
|
68
|
+
var import_react_router_dom = require("react-router-dom");
|
|
69
|
+
var import_util = require("./libs/util");
|
|
70
|
+
var import_server = require("./server");
|
|
71
|
+
var import_output = require("./libs/output");
|
|
72
|
+
var import_replace = require("./libs/replace");
|
|
73
|
+
var import_make = require("./libs/make");
|
|
74
|
+
var src_default = () => ({
|
|
75
|
+
name: "@modern-js/plugin-ssg",
|
|
76
|
+
pre: ["@modern-js/plugin-server", "@modern-js/plugin-bff"],
|
|
77
|
+
setup: (api) => {
|
|
23
78
|
const agreedRouteMap = {};
|
|
24
79
|
return {
|
|
25
80
|
validateSchema() {
|
|
26
|
-
return
|
|
81
|
+
return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-ssg"];
|
|
27
82
|
},
|
|
28
|
-
modifyFileSystemRoutes({
|
|
29
|
-
entrypoint
|
|
30
|
-
routes
|
|
31
|
-
}) {
|
|
32
|
-
const {
|
|
33
|
-
entryName
|
|
34
|
-
} = entrypoint;
|
|
35
|
-
const flattedRoutes = (0, _util.flattenRoutes)(routes);
|
|
83
|
+
modifyFileSystemRoutes({ entrypoint, routes }) {
|
|
84
|
+
const { entryName } = entrypoint;
|
|
85
|
+
const flattedRoutes = (0, import_util.flattenRoutes)(routes);
|
|
36
86
|
agreedRouteMap[entryName] = flattedRoutes;
|
|
37
|
-
return {
|
|
38
|
-
entrypoint,
|
|
39
|
-
routes
|
|
40
|
-
};
|
|
87
|
+
return { entrypoint, routes };
|
|
41
88
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
appDirectory,
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (!entryOptions) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// only add entry route if entryOptions is true
|
|
95
|
-
if (entryOptions === true) {
|
|
96
|
-
ssgRoutes.push(_objectSpread(_objectSpread({}, pageRoute), {}, {
|
|
97
|
-
output: entryPath
|
|
98
|
-
}));
|
|
99
|
-
} else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
100
|
-
// if entryOptions is object and has routes options
|
|
101
|
-
// add every route in options
|
|
89
|
+
afterBuild() {
|
|
90
|
+
return __async(this, null, function* () {
|
|
91
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
92
|
+
const appContext = api.useAppContext();
|
|
93
|
+
const { appDirectory, entrypoints } = appContext;
|
|
94
|
+
const { output, server } = resolvedConfig;
|
|
95
|
+
const { ssg, distPath: { root: outputPath } = {} } = output;
|
|
96
|
+
const ssgOptions = (Array.isArray(ssg) ? ssg.pop() : ssg) || true;
|
|
97
|
+
const buildDir = import_path.default.join(appDirectory, outputPath);
|
|
98
|
+
const routes = (0, import_util.readJSONSpec)(buildDir);
|
|
99
|
+
const pageRoutes = routes.filter((route) => !route.isApi);
|
|
100
|
+
const apiRoutes = routes.filter((route) => route.isApi);
|
|
101
|
+
if (pageRoutes.length === 0) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const intermediateOptions = (0, import_util.standardOptions)(
|
|
105
|
+
ssgOptions,
|
|
106
|
+
entrypoints,
|
|
107
|
+
pageRoutes,
|
|
108
|
+
server
|
|
109
|
+
);
|
|
110
|
+
if (!intermediateOptions) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const ssgRoutes = [];
|
|
114
|
+
pageRoutes.forEach((pageRoute) => {
|
|
115
|
+
const { entryName, entryPath } = pageRoute;
|
|
116
|
+
const agreedRoutes = agreedRouteMap[entryName];
|
|
117
|
+
let entryOptions = intermediateOptions[entryName] || intermediateOptions[pageRoute.urlPath];
|
|
118
|
+
if (!agreedRoutes) {
|
|
119
|
+
if (!entryOptions) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (entryOptions === true) {
|
|
123
|
+
ssgRoutes.push(__spreadProps(__spreadValues({}, pageRoute), { output: entryPath }));
|
|
124
|
+
} else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
125
|
+
const { routes: enrtyRoutes, headers } = entryOptions;
|
|
126
|
+
enrtyRoutes.forEach((route) => {
|
|
127
|
+
ssgRoutes.push((0, import_make.makeRoute)(pageRoute, route, headers));
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
if (!entryOptions) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (entryOptions === true) {
|
|
135
|
+
entryOptions = { preventDefault: [], routes: [], headers: {} };
|
|
136
|
+
}
|
|
102
137
|
const {
|
|
103
|
-
|
|
138
|
+
preventDefault = [],
|
|
139
|
+
routes: userRoutes = [],
|
|
104
140
|
headers
|
|
105
141
|
} = entryOptions;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (typeof route === 'string') {
|
|
132
|
-
ssgRoutes.push((0, _make.makeRoute)(pageRoute, route, headers));
|
|
133
|
-
} else if (Array.isArray(route.params)) {
|
|
134
|
-
route.params.forEach(param => {
|
|
135
|
-
ssgRoutes.push((0, _make.makeRoute)(pageRoute, _objectSpread(_objectSpread({}, route), {}, {
|
|
136
|
-
url: (0, _reactRouterDom.generatePath)(route.url, param)
|
|
137
|
-
}), headers));
|
|
138
|
-
});
|
|
139
|
-
} else {
|
|
140
|
-
ssgRoutes.push((0, _make.makeRoute)(pageRoute, route, headers));
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
} else {
|
|
144
|
-
// otherwith add all except dynamic routes
|
|
145
|
-
agreedRoutes.filter(route => !preventDefault.includes(route.path)).forEach(route => {
|
|
146
|
-
if (!(0, _util.isDynamicUrl)(route.path)) {
|
|
147
|
-
ssgRoutes.push((0, _make.makeRoute)(pageRoute, route.path, headers));
|
|
148
|
-
}
|
|
149
|
-
});
|
|
142
|
+
if (userRoutes.length > 0) {
|
|
143
|
+
userRoutes.forEach((route) => {
|
|
144
|
+
if (typeof route === "string") {
|
|
145
|
+
ssgRoutes.push((0, import_make.makeRoute)(pageRoute, route, headers));
|
|
146
|
+
} else if (Array.isArray(route.params)) {
|
|
147
|
+
route.params.forEach((param) => {
|
|
148
|
+
ssgRoutes.push(
|
|
149
|
+
(0, import_make.makeRoute)(
|
|
150
|
+
pageRoute,
|
|
151
|
+
__spreadProps(__spreadValues({}, route), { url: (0, import_react_router_dom.generatePath)(route.url, param) }),
|
|
152
|
+
headers
|
|
153
|
+
)
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
} else {
|
|
157
|
+
ssgRoutes.push((0, import_make.makeRoute)(pageRoute, route, headers));
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
} else {
|
|
161
|
+
agreedRoutes.filter((route) => !preventDefault.includes(route.path)).forEach((route) => {
|
|
162
|
+
if (!(0, import_util.isDynamicUrl)(route.path)) {
|
|
163
|
+
ssgRoutes.push((0, import_make.makeRoute)(pageRoute, route.path, headers));
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
150
167
|
}
|
|
168
|
+
});
|
|
169
|
+
if (ssgRoutes.length === 0) {
|
|
170
|
+
return;
|
|
151
171
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
172
|
+
ssgRoutes.forEach((ssgRoute) => {
|
|
173
|
+
if (ssgRoute.isSSR) {
|
|
174
|
+
const isOriginRoute = pageRoutes.some(
|
|
175
|
+
(pageRoute) => pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName
|
|
176
|
+
);
|
|
177
|
+
if (isOriginRoute) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
`ssg can not using with ssr,url - ${ssgRoute.urlPath}, entry - ${ssgRoute.entryName} `
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
import_utils.logger.warn(
|
|
183
|
+
`new ssg route ${ssgRoute.urlPath} is using ssr now,maybe from parent route ${ssgRoute.entryName},close ssr`
|
|
184
|
+
);
|
|
163
185
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
186
|
+
ssgRoute.isSSR = false;
|
|
187
|
+
ssgRoute.output = (0, import_util.formatOutput)(ssgRoute.output);
|
|
188
|
+
});
|
|
189
|
+
const htmlAry = yield (0, import_server.createServer)(
|
|
190
|
+
api,
|
|
191
|
+
ssgRoutes,
|
|
192
|
+
pageRoutes,
|
|
193
|
+
apiRoutes,
|
|
194
|
+
resolvedConfig,
|
|
195
|
+
appDirectory
|
|
196
|
+
);
|
|
197
|
+
(0, import_output.writeHtmlFile)(htmlAry, ssgRoutes, buildDir);
|
|
198
|
+
(0, import_replace.replaceRoute)(ssgRoutes, pageRoutes);
|
|
199
|
+
(0, import_util.writeJSONSpec)(buildDir, pageRoutes.concat(apiRoutes));
|
|
200
|
+
import_utils.logger.info("ssg Compiled successfully");
|
|
168
201
|
});
|
|
169
|
-
const htmlAry = await (0, _server.createServer)(api, ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory);
|
|
170
|
-
|
|
171
|
-
// write to dist file
|
|
172
|
-
(0, _output.writeHtmlFile)(htmlAry, ssgRoutes, buildDir);
|
|
173
|
-
|
|
174
|
-
// format route info, side effect
|
|
175
|
-
(0, _replace.replaceRoute)(ssgRoutes, pageRoutes);
|
|
176
|
-
|
|
177
|
-
// write routes to spec file
|
|
178
|
-
(0, _util.writeJSONSpec)(buildDir, pageRoutes.concat(apiRoutes));
|
|
179
|
-
_utils.logger.info('ssg Compiled successfully');
|
|
180
202
|
}
|
|
181
203
|
};
|
|
182
204
|
}
|
|
183
205
|
});
|
|
184
|
-
|
|
206
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
207
|
+
0 && (module.exports = {});
|
|
@@ -1,41 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
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
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
40
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
var make_exports = {};
|
|
42
|
+
__export(make_exports, {
|
|
43
|
+
makeRender: () => makeRender,
|
|
44
|
+
makeRoute: () => makeRoute
|
|
5
45
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
var _normalizePath = _interopRequireDefault(require("normalize-path"));
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
46
|
+
module.exports = __toCommonJS(make_exports);
|
|
47
|
+
var import_path = __toESM(require("path"));
|
|
48
|
+
var import_normalize_path = __toESM(require("normalize-path"));
|
|
14
49
|
function makeRender(ssgRoutes, render, port) {
|
|
15
|
-
return ssgRoutes.map(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
host: `localhost:${port}`
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
50
|
+
return ssgRoutes.map(
|
|
51
|
+
(ssgRoute) => render({
|
|
52
|
+
url: ssgRoute.urlPath,
|
|
53
|
+
headers: __spreadValues({ host: `localhost:${port}` }, ssgRoute.headers),
|
|
54
|
+
connection: {}
|
|
55
|
+
})
|
|
56
|
+
);
|
|
22
57
|
}
|
|
23
58
|
function makeRoute(baseRoute, route, headers = {}) {
|
|
24
|
-
const {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (typeof route === 'string') {
|
|
29
|
-
return _objectSpread(_objectSpread({}, baseRoute), {}, {
|
|
30
|
-
urlPath: (0, _normalizePath.default)(`${urlPath}${route}`) || '/',
|
|
59
|
+
const { urlPath, entryPath } = baseRoute;
|
|
60
|
+
if (typeof route === "string") {
|
|
61
|
+
return __spreadProps(__spreadValues({}, baseRoute), {
|
|
62
|
+
urlPath: (0, import_normalize_path.default)(`${urlPath}${route}`) || "/",
|
|
31
63
|
headers,
|
|
32
|
-
output:
|
|
64
|
+
output: import_path.default.join(entryPath, `..${route === "/" ? "" : route}`)
|
|
33
65
|
});
|
|
34
66
|
} else {
|
|
35
|
-
return
|
|
36
|
-
urlPath: (0,
|
|
37
|
-
headers:
|
|
38
|
-
output: route.output ?
|
|
67
|
+
return __spreadProps(__spreadValues({}, baseRoute), {
|
|
68
|
+
urlPath: (0, import_normalize_path.default)(`${urlPath}${route.url}`) || "/",
|
|
69
|
+
headers: __spreadValues(__spreadValues({}, headers), route.headers),
|
|
70
|
+
output: route.output ? import_path.default.normalize(route.output) : import_path.default.join(entryPath, `..${route.url === "/" ? "" : route.url}`)
|
|
39
71
|
});
|
|
40
72
|
}
|
|
41
|
-
}
|
|
73
|
+
}
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
makeRender,
|
|
77
|
+
makeRoute
|
|
78
|
+
});
|
|
@@ -1,19 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 output_exports = {};
|
|
25
|
+
__export(output_exports, {
|
|
26
|
+
writeHtmlFile: () => writeHtmlFile
|
|
5
27
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
28
|
+
module.exports = __toCommonJS(output_exports);
|
|
29
|
+
var import_path = __toESM(require("path"));
|
|
30
|
+
var import_utils = require("@modern-js/utils");
|
|
10
31
|
function writeHtmlFile(htmlAry, ssgRoutes, baseDir) {
|
|
11
32
|
htmlAry.forEach((html, index) => {
|
|
12
33
|
const ssgRoute = ssgRoutes[index];
|
|
13
|
-
const filepath =
|
|
14
|
-
if (!
|
|
15
|
-
|
|
34
|
+
const filepath = import_path.default.join(baseDir, ssgRoute.output);
|
|
35
|
+
if (!import_utils.fs.existsSync(import_path.default.dirname(filepath))) {
|
|
36
|
+
import_utils.fs.ensureDirSync(import_path.default.dirname(filepath));
|
|
16
37
|
}
|
|
17
|
-
|
|
38
|
+
import_utils.fs.writeFileSync(filepath, html);
|
|
18
39
|
});
|
|
19
|
-
}
|
|
40
|
+
}
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
writeHtmlFile
|
|
44
|
+
});
|