@modern-js/plugin-ssg 2.4.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/index.js +168 -0
  3. package/dist/{js/node → cjs}/libs/make.js +8 -23
  4. package/dist/{js/node → cjs}/libs/output.js +0 -0
  5. package/dist/{js/node → cjs}/libs/replace.js +2 -28
  6. package/dist/{js/node → cjs}/libs/util.js +8 -22
  7. package/dist/{js/node → cjs}/server/consts.js +0 -0
  8. package/dist/{js/node → cjs}/server/index.js +0 -0
  9. package/dist/{js/node → cjs}/server/prerender.js +3 -19
  10. package/dist/{js/node → cjs}/server/process.js +7 -27
  11. package/dist/{js/node → cjs}/types.js +0 -0
  12. package/dist/{js/treeshaking → esm}/index.js +3 -3
  13. package/dist/{js/treeshaking → esm}/libs/make.js +0 -0
  14. package/dist/{js/treeshaking → esm}/libs/output.js +0 -0
  15. package/dist/{js/treeshaking → esm}/libs/replace.js +0 -0
  16. package/dist/{js/treeshaking → esm}/libs/util.js +0 -0
  17. package/dist/{js/treeshaking → esm}/server/consts.js +0 -0
  18. package/dist/{js/treeshaking → esm}/server/index.js +0 -0
  19. package/dist/{js/treeshaking → esm}/server/prerender.js +0 -0
  20. package/dist/{js/treeshaking → esm}/server/process.js +0 -0
  21. package/dist/{js/treeshaking → esm}/types.js +0 -0
  22. package/dist/esm-node/index.js +148 -0
  23. package/dist/esm-node/libs/make.js +33 -0
  24. package/dist/{js/modern → esm-node}/libs/output.js +0 -0
  25. package/dist/esm-node/libs/replace.js +35 -0
  26. package/dist/{js/modern → esm-node}/libs/util.js +8 -24
  27. package/dist/{js/modern → esm-node}/server/consts.js +0 -0
  28. package/dist/{js/modern → esm-node}/server/index.js +0 -0
  29. package/dist/esm-node/server/prerender.js +35 -0
  30. package/dist/esm-node/server/process.js +55 -0
  31. package/dist/{js/modern → esm-node}/types.js +0 -0
  32. package/dist/types/libs/util.d.ts +1 -0
  33. package/package.json +18 -19
  34. package/dist/js/modern/index.js +0 -189
  35. package/dist/js/modern/libs/make.js +0 -50
  36. package/dist/js/modern/libs/replace.js +0 -63
  37. package/dist/js/modern/server/prerender.js +0 -53
  38. package/dist/js/modern/server/process.js +0 -84
  39. package/dist/js/node/index.js +0 -207
@@ -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
+ };
@@ -0,0 +1,33 @@
1
+ import path from "path";
2
+ import normalize from "normalize-path";
3
+ function makeRender(ssgRoutes, render, port) {
4
+ return ssgRoutes.map(
5
+ (ssgRoute) => render({
6
+ url: ssgRoute.urlPath,
7
+ headers: { host: `localhost:${port}`, ...ssgRoute.headers },
8
+ connection: {}
9
+ })
10
+ );
11
+ }
12
+ function makeRoute(baseRoute, route, headers = {}) {
13
+ const { urlPath, entryPath } = baseRoute;
14
+ if (typeof route === "string") {
15
+ return {
16
+ ...baseRoute,
17
+ urlPath: normalize(`${urlPath}${route}`) || "/",
18
+ headers,
19
+ output: path.join(entryPath, `..${route === "/" ? "" : route}`)
20
+ };
21
+ } else {
22
+ return {
23
+ ...baseRoute,
24
+ urlPath: normalize(`${urlPath}${route.url}`) || "/",
25
+ headers: { ...headers, ...route.headers },
26
+ output: route.output ? path.normalize(route.output) : path.join(entryPath, `..${route.url === "/" ? "" : route.url}`)
27
+ };
28
+ }
29
+ }
30
+ export {
31
+ makeRender,
32
+ makeRoute
33
+ };
File without changes
@@ -0,0 +1,35 @@
1
+ import normalize from "normalize-path";
2
+ function exist(route, pageRoutes) {
3
+ return pageRoutes.slice().findIndex((pageRoute) => {
4
+ const urlEqual = normalize(pageRoute.urlPath) === normalize(route.urlPath);
5
+ const entryEqual = pageRoute.entryName === route.entryName;
6
+ if (urlEqual && entryEqual) {
7
+ return true;
8
+ }
9
+ return false;
10
+ });
11
+ }
12
+ function replaceRoute(ssgRoutes, pageRoutes) {
13
+ const cleanSsgRoutes = ssgRoutes.map((ssgRoute) => {
14
+ const { output, headers, ...cleanSsgRoute } = ssgRoute;
15
+ return Object.assign(
16
+ cleanSsgRoute,
17
+ output ? { entryPath: output } : {}
18
+ );
19
+ });
20
+ const freshRoutes = [];
21
+ cleanSsgRoutes.forEach((ssgRoute) => {
22
+ const index = exist(ssgRoute, pageRoutes);
23
+ if (index < 0) {
24
+ freshRoutes.push({ ...ssgRoute });
25
+ } else {
26
+ pageRoutes[index].entryPath = ssgRoute.entryPath;
27
+ }
28
+ });
29
+ pageRoutes.push(...freshRoutes);
30
+ return pageRoutes;
31
+ }
32
+ export {
33
+ exist,
34
+ replaceRoute
35
+ };
@@ -1,22 +1,3 @@
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
1
  import path from "path";
21
2
  import {
22
3
  ROUTE_SPEC_FILE,
@@ -129,7 +110,8 @@ const standardOptions = (ssgOptions, entrypoints, routes, server) => {
129
110
  }
130
111
  return false;
131
112
  };
132
- const openRouteSSR = (routes, entries = []) => routes.map((ssgRoute) => __spreadProps(__spreadValues({}, ssgRoute), {
113
+ const openRouteSSR = (routes, entries = []) => routes.map((ssgRoute) => ({
114
+ ...ssgRoute,
133
115
  isSSR: entries.includes(ssgRoute.entryName),
134
116
  bundle: `${SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
135
117
  }));
@@ -141,14 +123,16 @@ const flattenRoutes = (routes) => {
141
123
  let path2 = parent ? `${parent.path}/${route.path || ""}`.replace(/\/+/g, "/") : route.path || "";
142
124
  path2 = path2.replace(/\/$/, "");
143
125
  if (route._component && (path2 !== "/" || path2 === "/" && !parent)) {
144
- newRoutes.push(__spreadProps(__spreadValues({}, route), {
126
+ newRoutes.push({
127
+ ...route,
145
128
  path: path2
146
- }));
129
+ });
147
130
  }
148
131
  if (route.children) {
149
- parents.push(__spreadProps(__spreadValues({}, route), {
132
+ parents.push({
133
+ ...route,
150
134
  path: path2
151
- }));
135
+ });
152
136
  route.children.forEach(traverseRoute);
153
137
  parents.pop();
154
138
  }
File without changes
File without changes
@@ -0,0 +1,35 @@
1
+ import EventEmitter from "events";
2
+ import { Readable } from "stream";
3
+ import httpMocks from "node-mocks-http";
4
+ const compile = (requestHandler) => (options, extend = {}) => new Promise((resolve, reject) => {
5
+ const req = httpMocks.createRequest({
6
+ ...options,
7
+ eventEmitter: Readable
8
+ });
9
+ const res = httpMocks.createResponse({ eventEmitter: EventEmitter });
10
+ Object.assign(req, extend);
11
+ const proxyRes = new Proxy(res, {
12
+ get(obj, prop) {
13
+ if (typeof prop === "symbol" && !obj[prop]) {
14
+ return null;
15
+ }
16
+ return obj[prop];
17
+ }
18
+ });
19
+ res.on("finish", () => {
20
+ if (res.statusCode !== 200) {
21
+ reject(new Error(res.statusMessage));
22
+ } else {
23
+ resolve(res._getData());
24
+ }
25
+ });
26
+ res.on("error", (e) => reject(e));
27
+ try {
28
+ requestHandler(req, proxyRes);
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ });
33
+ export {
34
+ compile
35
+ };
@@ -0,0 +1,55 @@
1
+ import server from "@modern-js/prod-server";
2
+ import portfinder from "portfinder";
3
+ import { makeRender } from "../libs/make";
4
+ import { compile as createRender } from "./prerender";
5
+ import { CLOSE_SIGN } from "./consts";
6
+ process.on("message", async (chunk) => {
7
+ if (chunk === CLOSE_SIGN) {
8
+ process.exit();
9
+ }
10
+ const context = JSON.parse(chunk);
11
+ const {
12
+ routes,
13
+ renderRoutes,
14
+ options,
15
+ appDirectory,
16
+ plugins
17
+ } = context;
18
+ let modernServer = null;
19
+ try {
20
+ const { server: serverOptions } = options;
21
+ const defaultPort = Number(process.env.PORT) || serverOptions.port;
22
+ portfinder.basePort = defaultPort;
23
+ const port = await portfinder.getPortPromise();
24
+ modernServer = await server({
25
+ pwd: appDirectory,
26
+ config: options,
27
+ routes,
28
+ staticGenerate: true,
29
+ internalPlugins: plugins
30
+ });
31
+ modernServer.listen(port, async (err) => {
32
+ if (err) {
33
+ throw err;
34
+ }
35
+ if (!modernServer) {
36
+ return;
37
+ }
38
+ const render = createRender(modernServer.getRequestHandler());
39
+ const renderPromiseAry = makeRender(
40
+ renderRoutes,
41
+ render,
42
+ port
43
+ );
44
+ const htmlAry = await Promise.all(renderPromiseAry);
45
+ htmlAry.forEach((html) => {
46
+ process.send(html);
47
+ process.send(null);
48
+ });
49
+ modernServer.close();
50
+ });
51
+ } catch (e) {
52
+ modernServer == null ? void 0 : modernServer.close();
53
+ throw e;
54
+ }
55
+ });
File without changes
@@ -18,6 +18,7 @@ export declare const openRouteSSR: (routes: ModernRoute[], entries?: string[]) =
18
18
  entryPath: string;
19
19
  isSPA?: boolean | undefined;
20
20
  isApi?: boolean | undefined;
21
+ worker?: string | undefined;
21
22
  responseHeaders?: Record<string, unknown> | undefined;
22
23
  }[];
23
24
  export declare const flattenRoutes: (routes: AgreedRoute[]) => AgreedRoute[];
package/package.json CHANGED
@@ -11,12 +11,11 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.4.0",
14
+ "version": "2.5.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
- "main": "./dist/js/node/index.js",
18
- "module": "./dist/js/treeshaking/index.js",
19
- "jsnext:modern": "./dist/js/modern/index.js",
17
+ "main": "./dist/cjs/index.js",
18
+ "module": "./dist/esm/index.js",
20
19
  "typesVersions": {
21
20
  "*": {
22
21
  ".": [
@@ -31,26 +30,26 @@
31
30
  ".": {
32
31
  "node": {
33
32
  "jsnext:source": "./src/index.ts",
34
- "import": "./dist/js/modern/index.js",
35
- "require": "./dist/js/node/index.js"
33
+ "import": "./dist/esm-node/index.js",
34
+ "require": "./dist/cjs/index.js"
36
35
  },
37
- "default": "./dist/js/treeshaking/index.js"
36
+ "default": "./dist/esm/index.js"
38
37
  },
39
38
  "./cli": {
40
39
  "jsnext:source": "./src/index.ts",
41
40
  "node": {
42
- "import": "./dist/js/modern/index.js",
43
- "require": "./dist/js/node/index.js"
41
+ "import": "./dist/esm-node/index.js",
42
+ "require": "./dist/cjs/index.js"
44
43
  },
45
- "default": "./dist/js/treeshaking/index.js"
44
+ "default": "./dist/esm/index.js"
46
45
  },
47
46
  "./types": {
48
47
  "node": {
49
- "import": "./dist/js/modern/types.js",
50
- "require": "./dist/js/node/types.js",
48
+ "import": "./dist/esm-node/types.js",
49
+ "require": "./dist/cjs/types.js",
51
50
  "types": "./dist/types/types.d.ts"
52
51
  },
53
- "default": "./dist/js/treeshaking/types.js"
52
+ "default": "./dist/esm/types.js"
54
53
  }
55
54
  },
56
55
  "dependencies": {
@@ -58,7 +57,7 @@
58
57
  "node-mocks-http": "^1.10.1",
59
58
  "normalize-path": "^3.0.0",
60
59
  "portfinder": "^1.0.28",
61
- "@modern-js/utils": "2.4.0"
60
+ "@modern-js/utils": "2.5.0"
62
61
  },
63
62
  "peerDependencies": {
64
63
  "react-router-dom": ">=5.1.2"
@@ -75,11 +74,11 @@
75
74
  "react": "^18",
76
75
  "react-router-dom": "^6.6.0",
77
76
  "typescript": "^4",
78
- "@modern-js/app-tools": "2.4.0",
79
- "@modern-js/prod-server": "2.4.0",
80
- "@modern-js/types": "2.4.0",
81
- "@scripts/build": "2.4.0",
82
- "@scripts/jest-config": "2.4.0"
77
+ "@modern-js/app-tools": "2.5.0",
78
+ "@modern-js/prod-server": "2.5.0",
79
+ "@modern-js/types": "2.5.0",
80
+ "@scripts/build": "2.5.0",
81
+ "@scripts/jest-config": "2.5.0"
83
82
  },
84
83
  "sideEffects": false,
85
84
  "publishConfig": {
@@ -1,189 +0,0 @@
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";
51
- import { createServer } from "./server";
52
- import { writeHtmlFile } from "./libs/output";
53
- import { replaceRoute } from "./libs/replace";
54
- import { makeRoute } from "./libs/make";
55
- var src_default = () => ({
56
- name: "@modern-js/plugin-ssg",
57
- pre: ["@modern-js/plugin-server", "@modern-js/plugin-bff"],
58
- setup: (api) => {
59
- const agreedRouteMap = {};
60
- return {
61
- validateSchema() {
62
- return PLUGIN_SCHEMAS["@modern-js/plugin-ssg"];
63
- },
64
- modifyFileSystemRoutes({ entrypoint, routes }) {
65
- const { entryName } = entrypoint;
66
- const flattedRoutes = flattenRoutes(routes);
67
- agreedRouteMap[entryName] = flattedRoutes;
68
- return { entrypoint, routes };
69
- },
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) || true;
78
- const buildDir = path.join(appDirectory, outputPath);
79
- const routes = readJSONSpec(buildDir);
80
- const pageRoutes = routes.filter((route) => !route.isApi);
81
- const apiRoutes = routes.filter((route) => route.isApi);
82
- if (pageRoutes.length === 0) {
83
- return;
84
- }
85
- const intermediateOptions = standardOptions(
86
- ssgOptions,
87
- entrypoints,
88
- pageRoutes,
89
- server
90
- );
91
- if (!intermediateOptions) {
92
- return;
93
- }
94
- const ssgRoutes = [];
95
- pageRoutes.forEach((pageRoute) => {
96
- const { entryName, entryPath } = pageRoute;
97
- const agreedRoutes = agreedRouteMap[entryName];
98
- let entryOptions = intermediateOptions[entryName] || intermediateOptions[pageRoute.urlPath];
99
- if (!agreedRoutes) {
100
- if (!entryOptions) {
101
- return;
102
- }
103
- if (entryOptions === true) {
104
- ssgRoutes.push(__spreadProps(__spreadValues({}, pageRoute), { output: entryPath }));
105
- } else if (entryOptions.routes && entryOptions.routes.length > 0) {
106
- const { routes: enrtyRoutes, headers } = entryOptions;
107
- enrtyRoutes.forEach((route) => {
108
- ssgRoutes.push(makeRoute(pageRoute, route, headers));
109
- });
110
- }
111
- } else {
112
- if (!entryOptions) {
113
- return;
114
- }
115
- if (entryOptions === true) {
116
- entryOptions = { preventDefault: [], routes: [], headers: {} };
117
- }
118
- const {
119
- preventDefault = [],
120
- routes: userRoutes = [],
121
- headers
122
- } = entryOptions;
123
- if (userRoutes.length > 0) {
124
- userRoutes.forEach((route) => {
125
- if (typeof route === "string") {
126
- ssgRoutes.push(makeRoute(pageRoute, route, headers));
127
- } else if (Array.isArray(route.params)) {
128
- route.params.forEach((param) => {
129
- ssgRoutes.push(
130
- makeRoute(
131
- pageRoute,
132
- __spreadProps(__spreadValues({}, route), { url: generatePath(route.url, param) }),
133
- headers
134
- )
135
- );
136
- });
137
- } else {
138
- ssgRoutes.push(makeRoute(pageRoute, route, headers));
139
- }
140
- });
141
- } else {
142
- agreedRoutes.filter((route) => !preventDefault.includes(route.path)).forEach((route) => {
143
- if (!isDynamicUrl(route.path)) {
144
- ssgRoutes.push(makeRoute(pageRoute, route.path, headers));
145
- }
146
- });
147
- }
148
- }
149
- });
150
- if (ssgRoutes.length === 0) {
151
- return;
152
- }
153
- ssgRoutes.forEach((ssgRoute) => {
154
- if (ssgRoute.isSSR) {
155
- const isOriginRoute = pageRoutes.some(
156
- (pageRoute) => pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName
157
- );
158
- if (isOriginRoute) {
159
- throw new Error(
160
- `ssg can not using with ssr,url - ${ssgRoute.urlPath}, entry - ${ssgRoute.entryName} `
161
- );
162
- }
163
- logger.warn(
164
- `new ssg route ${ssgRoute.urlPath} is using ssr now,maybe from parent route ${ssgRoute.entryName},close ssr`
165
- );
166
- }
167
- ssgRoute.isSSR = false;
168
- ssgRoute.output = formatOutput(ssgRoute.output);
169
- });
170
- const htmlAry = yield createServer(
171
- api,
172
- ssgRoutes,
173
- pageRoutes,
174
- apiRoutes,
175
- resolvedConfig,
176
- appDirectory
177
- );
178
- writeHtmlFile(htmlAry, ssgRoutes, buildDir);
179
- replaceRoute(ssgRoutes, pageRoutes);
180
- writeJSONSpec(buildDir, pageRoutes.concat(apiRoutes));
181
- logger.info("ssg Compiled successfully");
182
- });
183
- }
184
- };
185
- }
186
- });
187
- export {
188
- src_default as default
189
- };