@modern-js/plugin-ssg 1.0.0 → 1.1.2-rc.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/.eslintrc.js +6 -0
- package/CHANGELOG.md +42 -0
- package/README.md +1 -4
- package/dist/js/modern/index.js +97 -58
- package/dist/js/modern/libs/make.js +37 -0
- package/dist/js/modern/libs/output.js +2 -1
- package/dist/js/modern/libs/replace.js +5 -4
- package/dist/js/modern/libs/util.js +39 -22
- package/dist/js/modern/server/index.js +4 -3
- package/dist/js/modern/server/prerender.js +2 -2
- package/dist/js/modern/server/process.js +8 -7
- package/dist/js/node/index.js +97 -56
- package/dist/js/node/libs/make.js +50 -0
- package/dist/js/node/libs/output.js +7 -3
- package/dist/js/node/libs/replace.js +5 -4
- package/dist/js/node/libs/util.js +43 -30
- package/dist/js/node/server/index.js +5 -3
- package/dist/js/node/server/prerender.js +2 -2
- package/dist/js/node/server/process.js +7 -6
- package/dist/types/libs/make.d.ts +5 -0
- package/dist/types/libs/replace.d.ts +1 -1
- package/dist/types/libs/util.d.ts +4 -8
- package/dist/types/types.d.ts +13 -17
- package/package.json +10 -11
- package/src/index.ts +85 -89
- package/src/libs/make.ts +45 -0
- package/src/libs/output.ts +3 -2
- package/src/libs/replace.ts +7 -4
- package/src/libs/util.ts +40 -27
- package/src/server/index.ts +3 -2
- package/src/server/process.ts +7 -5
- package/src/types.ts +26 -20
- package/tests/.eslintrc.js +6 -0
- package/tests/lib.test.ts +49 -170
- package/tests/util.test.ts +71 -32
- package/dist/js/modern/libs/createPage.js +0 -46
- package/dist/js/modern/libs/invoker.js +0 -55
- package/dist/js/modern/libs/render.js +0 -15
- package/dist/js/modern/loader/index.js +0 -105
- package/dist/js/modern/manifest-op.js +0 -100
- package/dist/js/node/libs/createPage.js +0 -57
- package/dist/js/node/libs/invoker.js +0 -66
- package/dist/js/node/libs/render.js +0 -22
- package/dist/js/node/loader/index.js +0 -115
- package/dist/js/node/manifest-op.js +0 -120
- package/dist/types/libs/createPage.d.ts +0 -2
- package/dist/types/libs/invoker.d.ts +0 -5
- package/dist/types/libs/render.d.ts +0 -3
- package/dist/types/loader/index.d.ts +0 -4
- package/dist/types/manifest-op.d.ts +0 -18
- package/src/libs/createPage.ts +0 -42
- package/src/libs/invoker.ts +0 -55
- package/src/libs/render.ts +0 -16
- package/src/loader/index.ts +0 -99
- package/src/manifest-op.ts +0 -110
- package/tests/operate.test.ts +0 -39
package/.eslintrc.js
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
# @modern-js/plugin-ssg
|
|
2
2
|
|
|
3
|
+
## 1.1.2-rc.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d73ff455: support multi process product
|
|
8
|
+
- d73ff455: support multi process product
|
|
9
|
+
- d73ff455: support multi process product
|
|
10
|
+
- d73ff455: support multi process product
|
|
11
|
+
- d73ff455: support multi process product
|
|
12
|
+
- Updated dependencies [d927bc83]
|
|
13
|
+
- Updated dependencies [d73ff455]
|
|
14
|
+
- Updated dependencies [9c1ab865]
|
|
15
|
+
- Updated dependencies [d73ff455]
|
|
16
|
+
- Updated dependencies [d73ff455]
|
|
17
|
+
- Updated dependencies [d73ff455]
|
|
18
|
+
- Updated dependencies [d73ff455]
|
|
19
|
+
- @modern-js/utils@1.1.4-rc.0
|
|
20
|
+
- @modern-js/core@1.1.4-rc.0
|
|
21
|
+
|
|
22
|
+
## 1.1.1
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- 0fa83663: support more .env files
|
|
27
|
+
- Updated dependencies [6f7fe574]
|
|
28
|
+
- Updated dependencies [0fa83663]
|
|
29
|
+
- Updated dependencies [f594fbc8]
|
|
30
|
+
- @modern-js/core@1.1.2
|
|
31
|
+
- @modern-js/utils@1.1.2
|
|
32
|
+
|
|
33
|
+
## 1.1.0
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- 96119db2: Relese v1.1.0
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- Updated dependencies [96119db2]
|
|
42
|
+
- @modern-js/core@1.1.0
|
|
43
|
+
- @modern-js/utils@1.1.0
|
|
44
|
+
|
|
3
45
|
## 1.0.0
|
|
4
46
|
|
|
5
47
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -17,10 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.
|
|
19
19
|
|
|
20
|
-
-
|
|
21
|
-
- [迈入现代 Web 开发](https://zhuanlan.zhihu.com/p/386607009)
|
|
22
|
-
- [现代 Web 开发者问卷调查报告](https://zhuanlan.zhihu.com/p/403206195)
|
|
23
|
-
- [字节跳动是如何落地微前端的](https://mp.weixin.qq.com/s/L9wbfNG5fTXF5bx7dcgj4Q)
|
|
20
|
+
- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)
|
|
24
21
|
|
|
25
22
|
## Getting Started
|
|
26
23
|
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1,37 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
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; }
|
|
2
|
+
|
|
3
|
+
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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { logger, PLUGIN_SCHEMAS } from '@modern-js/utils';
|
|
2
9
|
import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
|
3
|
-
import {
|
|
4
|
-
import { formatOutput,
|
|
5
|
-
import { invoker } from "./libs/invoker";
|
|
10
|
+
import { generatePath } from 'react-router-dom';
|
|
11
|
+
import { formatOutput, isDynamicUrl, readJSONSpec, standardOptions, writeJSONSpec } from "./libs/util";
|
|
6
12
|
import { createServer } from "./server";
|
|
7
13
|
import { writeHtmlFile } from "./libs/output";
|
|
8
14
|
import { replaceRoute } from "./libs/replace";
|
|
9
|
-
|
|
10
|
-
const listStaticFiles = (pwd, entriesDir, useSSG) => {
|
|
11
|
-
const absEntriesDir = path.join(pwd, entriesDir);
|
|
12
|
-
const staticRenderLevel = getSSGRenderLevel(useSSG);
|
|
13
|
-
const staticFiles = new LoaderManifest().get(absEntriesDir, staticRenderLevel); // 将绝对路径转换成 alias,因为获取到的约定路由也是使用别名的
|
|
14
|
-
|
|
15
|
-
const staticAlias = staticFiles.map(filepath => replaceWithAlias(path.join(pwd, 'src'), filepath, INTERNAL_SRC_ALIAS));
|
|
16
|
-
return staticAlias;
|
|
17
|
-
};
|
|
18
|
-
|
|
15
|
+
import { makeRoute } from "./libs/make";
|
|
19
16
|
export default createPlugin(() => {
|
|
20
17
|
const agreedRouteMap = {};
|
|
21
18
|
return {
|
|
22
|
-
config() {
|
|
23
|
-
return {
|
|
24
|
-
tools: {
|
|
25
|
-
babel(config, {
|
|
26
|
-
chain
|
|
27
|
-
}) {
|
|
28
|
-
chain.plugin('./loader').use(upath.normalizeSafe(require.resolve("./loader")));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
},
|
|
34
|
-
|
|
35
19
|
validateSchema() {
|
|
36
20
|
return PLUGIN_SCHEMAS['@modern-js/plugin-ssg'];
|
|
37
21
|
},
|
|
@@ -57,16 +41,11 @@ export default createPlugin(() => {
|
|
|
57
41
|
|
|
58
42
|
const appContext = useAppContext();
|
|
59
43
|
const {
|
|
60
|
-
appDirectory
|
|
44
|
+
appDirectory,
|
|
45
|
+
entrypoints
|
|
61
46
|
} = appContext;
|
|
62
47
|
const {
|
|
63
|
-
output
|
|
64
|
-
server: {
|
|
65
|
-
baseUrl
|
|
66
|
-
},
|
|
67
|
-
source: {
|
|
68
|
-
entriesDir
|
|
69
|
-
}
|
|
48
|
+
output
|
|
70
49
|
} = resolvedConfig;
|
|
71
50
|
const {
|
|
72
51
|
ssg,
|
|
@@ -78,13 +57,8 @@ export default createPlugin(() => {
|
|
|
78
57
|
return;
|
|
79
58
|
}
|
|
80
59
|
|
|
81
|
-
const {
|
|
82
|
-
useSSG,
|
|
83
|
-
userHook
|
|
84
|
-
} = parsedSSGConfig(ssgOptions);
|
|
85
60
|
const buildDir = path.join(appDirectory, outputPath);
|
|
86
|
-
const routes = readJSONSpec(buildDir);
|
|
87
|
-
const staticAlias = listStaticFiles(appDirectory, entriesDir, useSSG); // filter all routes not web
|
|
61
|
+
const routes = readJSONSpec(buildDir); // filter all routes not web
|
|
88
62
|
|
|
89
63
|
const pageRoutes = routes.filter(route => !route.isApi);
|
|
90
64
|
const apiRoutes = routes.filter(route => route.isApi); // if no web page route, skip ssg render
|
|
@@ -93,27 +67,91 @@ export default createPlugin(() => {
|
|
|
93
67
|
return;
|
|
94
68
|
}
|
|
95
69
|
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
const listener = (route, agreed) => {
|
|
99
|
-
const urlPrefix = getUrlPrefix(route, baseUrl);
|
|
100
|
-
const ssgOutput = getOutput(route, urlPrefix, agreed);
|
|
101
|
-
route.output = formatOutput(route.entryPath, ssgOutput);
|
|
102
|
-
ssgRoutes.push(route);
|
|
103
|
-
}; // check if every allowed agreed route was collected
|
|
104
|
-
|
|
70
|
+
const intermediateOptions = standardOptions(ssgOptions, entrypoints);
|
|
105
71
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return false;
|
|
110
|
-
} // if allowed, return collection state
|
|
72
|
+
if (!intermediateOptions) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
111
75
|
|
|
76
|
+
const ssgRoutes = []; // each route will try to match the configuration
|
|
77
|
+
|
|
78
|
+
pageRoutes.forEach(pageRoute => {
|
|
79
|
+
const {
|
|
80
|
+
entryName,
|
|
81
|
+
entryPath
|
|
82
|
+
} = pageRoute;
|
|
83
|
+
const agreedRoutes = agreedRouteMap[entryName];
|
|
84
|
+
let entryOptions = intermediateOptions[entryName];
|
|
85
|
+
|
|
86
|
+
if (!agreedRoutes) {
|
|
87
|
+
var _entryOptions$routes;
|
|
88
|
+
|
|
89
|
+
// default behavior for non-agreed route
|
|
90
|
+
if (!entryOptions) {
|
|
91
|
+
return;
|
|
92
|
+
} // only add entry route if entryOptions is true
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if (entryOptions === true) {
|
|
96
|
+
ssgRoutes.push(_objectSpread(_objectSpread({}, pageRoute), {}, {
|
|
97
|
+
output: entryPath
|
|
98
|
+
}));
|
|
99
|
+
} else if (((_entryOptions$routes = entryOptions.routes) === null || _entryOptions$routes === void 0 ? void 0 : _entryOptions$routes.length) > 0) {
|
|
100
|
+
// if entryOptions is object and has routes options
|
|
101
|
+
// add every route in options
|
|
102
|
+
const {
|
|
103
|
+
routes: enrtyRoutes,
|
|
104
|
+
headers
|
|
105
|
+
} = entryOptions;
|
|
106
|
+
enrtyRoutes.forEach(route => {
|
|
107
|
+
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
// Unless entryOptions is set to false
|
|
112
|
+
// the default behavior is to add all file-based routes
|
|
113
|
+
if (entryOptions === false) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
112
116
|
|
|
113
|
-
|
|
114
|
-
|
|
117
|
+
if (!entryOptions || entryOptions === true) {
|
|
118
|
+
entryOptions = {
|
|
119
|
+
preventDefault: [],
|
|
120
|
+
routes: [],
|
|
121
|
+
headers: {}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
115
124
|
|
|
116
|
-
|
|
125
|
+
const {
|
|
126
|
+
preventDefault = [],
|
|
127
|
+
routes: userRoutes = [],
|
|
128
|
+
headers
|
|
129
|
+
} = entryOptions; // if the user sets the routes, then only add them
|
|
130
|
+
|
|
131
|
+
if (userRoutes.length > 0) {
|
|
132
|
+
userRoutes.forEach(route => {
|
|
133
|
+
if (typeof route === 'string') {
|
|
134
|
+
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
135
|
+
} else if (Array.isArray(route.params)) {
|
|
136
|
+
route.params.forEach(param => {
|
|
137
|
+
ssgRoutes.push(makeRoute(pageRoute, _objectSpread(_objectSpread({}, route), {}, {
|
|
138
|
+
url: generatePath(route.url, param)
|
|
139
|
+
}), headers));
|
|
140
|
+
});
|
|
141
|
+
} else {
|
|
142
|
+
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
} else {
|
|
146
|
+
// otherwith add all except dynamic routes
|
|
147
|
+
agreedRoutes.filter(route => !preventDefault.includes(route.path)).forEach(route => {
|
|
148
|
+
if (!isDynamicUrl(route.path)) {
|
|
149
|
+
ssgRoutes.push(makeRoute(pageRoute, route.path, headers));
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
117
155
|
|
|
118
156
|
if (ssgRoutes.length === 0) {
|
|
119
157
|
return;
|
|
@@ -132,6 +170,7 @@ export default createPlugin(() => {
|
|
|
132
170
|
}
|
|
133
171
|
|
|
134
172
|
ssgRoute.isSSR = false;
|
|
173
|
+
ssgRoute.output = formatOutput(ssgRoute.output);
|
|
135
174
|
});
|
|
136
175
|
const htmlAry = await createServer(ssgRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
137
176
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
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; }
|
|
2
|
+
|
|
3
|
+
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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import normalize from 'normalize-path';
|
|
9
|
+
export function makeRender(ssgRoutes, render, port) {
|
|
10
|
+
return ssgRoutes.map(ssgRoute => render({
|
|
11
|
+
url: ssgRoute.urlPath,
|
|
12
|
+
headers: _objectSpread({
|
|
13
|
+
host: `localhost:${port}`
|
|
14
|
+
}, ssgRoute.headers),
|
|
15
|
+
connection: {}
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
export function makeRoute(baseRoute, route, headers = {}) {
|
|
19
|
+
const {
|
|
20
|
+
urlPath,
|
|
21
|
+
entryPath
|
|
22
|
+
} = baseRoute;
|
|
23
|
+
|
|
24
|
+
if (typeof route === 'string') {
|
|
25
|
+
return _objectSpread(_objectSpread({}, baseRoute), {}, {
|
|
26
|
+
urlPath: normalize(`${urlPath}${route}`) || '/',
|
|
27
|
+
headers,
|
|
28
|
+
output: path.join(entryPath, `..${route}`)
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
return _objectSpread(_objectSpread({}, baseRoute), {}, {
|
|
32
|
+
urlPath: normalize(`${urlPath}${route.url}`) || '/',
|
|
33
|
+
headers: _objectSpread(_objectSpread({}, headers), route.headers),
|
|
34
|
+
output: route.output ? path.normalize(route.output) : path.join(entryPath, `..${route.url}`)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const _excluded = ["output"];
|
|
1
|
+
const _excluded = ["output", "headers"];
|
|
2
2
|
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
3
|
+
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; }
|
|
4
4
|
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
5
|
+
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; }
|
|
6
6
|
|
|
7
7
|
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; }
|
|
8
8
|
|
|
@@ -27,7 +27,8 @@ export function replaceRoute(ssgRoutes, pageRoutes) {
|
|
|
27
27
|
// remove redundant fields and replace rendered entryPath
|
|
28
28
|
const cleanSsgRoutes = ssgRoutes.map(ssgRoute => {
|
|
29
29
|
const {
|
|
30
|
-
output
|
|
30
|
+
output,
|
|
31
|
+
headers
|
|
31
32
|
} = ssgRoute,
|
|
32
33
|
cleanSsgRoute = _objectWithoutProperties(ssgRoute, _excluded);
|
|
33
34
|
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
export function formatOutput(
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
return path.join(dirname, file);
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { ROUTE_SPEC_FILE, fs, isSingleEntry } from '@modern-js/utils';
|
|
3
|
+
export function formatOutput(filename) {
|
|
4
|
+
const outputPath = path.extname(filename) ? filename : `${filename}/index.html`;
|
|
5
|
+
return outputPath;
|
|
7
6
|
}
|
|
8
7
|
export function formatPath(str) {
|
|
9
8
|
let addr = str;
|
|
@@ -89,22 +88,40 @@ export const writeJSONSpec = (dir, routes) => {
|
|
|
89
88
|
spaces: 2
|
|
90
89
|
});
|
|
91
90
|
};
|
|
92
|
-
export const
|
|
93
|
-
|
|
91
|
+
export const replaceWithAlias = (base, filePath, alias) => path.posix.join(alias, path.posix.relative(base, filePath));
|
|
92
|
+
export const standardOptions = (ssgOptions, entrypoints) => {
|
|
93
|
+
if (ssgOptions === false) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (ssgOptions === true) {
|
|
98
|
+
return entrypoints.reduce((opt, entry) => {
|
|
99
|
+
opt[entry.entryName] = ssgOptions;
|
|
100
|
+
return opt;
|
|
101
|
+
}, {});
|
|
102
|
+
} else if (typeof ssgOptions === 'object') {
|
|
103
|
+
const isSingle = isSingleEntry(entrypoints);
|
|
104
|
+
|
|
105
|
+
if (isSingle && typeof ssgOptions.main === 'undefined') {
|
|
106
|
+
return {
|
|
107
|
+
main: ssgOptions
|
|
108
|
+
};
|
|
109
|
+
} else {
|
|
110
|
+
return ssgOptions;
|
|
111
|
+
}
|
|
112
|
+
} else if (typeof ssgOptions === 'function') {
|
|
113
|
+
const intermediateOptions = {};
|
|
114
|
+
|
|
115
|
+
for (const entrypoint of entrypoints) {
|
|
116
|
+
const {
|
|
117
|
+
entryName
|
|
118
|
+
} = entrypoint; // Todo may be async function
|
|
94
119
|
|
|
95
|
-
|
|
96
|
-
|
|
120
|
+
intermediateOptions[entryName] = ssgOptions(entryName);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return intermediateOptions;
|
|
97
124
|
}
|
|
98
125
|
|
|
99
|
-
return
|
|
100
|
-
};
|
|
101
|
-
export const parsedSSGConfig = ssg => {
|
|
102
|
-
const useSSG = Boolean(ssg); // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
103
|
-
|
|
104
|
-
const userHook = typeof ssg === 'function' ? ssg : () => {};
|
|
105
|
-
return {
|
|
106
|
-
useSSG,
|
|
107
|
-
userHook
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
export const replaceWithAlias = (base, filePath, alias) => path.join(alias, path.relative(base, filePath));
|
|
126
|
+
return false;
|
|
127
|
+
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
1
|
+
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; }
|
|
2
2
|
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
3
|
+
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; }
|
|
4
4
|
|
|
5
5
|
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; }
|
|
6
6
|
|
|
7
7
|
import childProcess from 'child_process';
|
|
8
|
-
import
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { logger, SERVER_BUNDLE_DIRECTORY } from '@modern-js/utils';
|
|
9
10
|
import { useAppContext } from '@modern-js/core';
|
|
10
11
|
import { CLOSE_SIGN } from "./consts";
|
|
11
12
|
export const createServer = (ssgRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
1
|
+
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; }
|
|
2
2
|
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
3
|
+
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; }
|
|
4
4
|
|
|
5
5
|
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; }
|
|
6
6
|
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import Server from '@modern-js/server';
|
|
2
2
|
import portfinder from 'portfinder';
|
|
3
|
-
import { compatRequire
|
|
4
|
-
import { makeRender } from "../libs/
|
|
3
|
+
import { compatRequire } from '@modern-js/utils';
|
|
4
|
+
import { makeRender } from "../libs/make";
|
|
5
5
|
import { compile as createRender } from "./prerender";
|
|
6
6
|
import { CLOSE_SIGN } from "./consts";
|
|
7
7
|
|
|
8
8
|
const safetyRequire = (filename, base) => {
|
|
9
9
|
try {
|
|
10
|
-
return compatRequire(
|
|
10
|
+
return compatRequire(require.resolve(`${filename}/server`, {
|
|
11
11
|
paths: [base]
|
|
12
|
-
}))
|
|
12
|
+
}));
|
|
13
13
|
} catch (e) {
|
|
14
|
-
return compatRequire(
|
|
14
|
+
return compatRequire(require.resolve(filename, {
|
|
15
15
|
paths: [base]
|
|
16
|
-
}))
|
|
16
|
+
}));
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -56,7 +56,8 @@ process.on('message', async chunk => {
|
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
const render = createRender(modernServer.getRequestHandler());
|
|
59
|
-
const renderPromiseAry = makeRender(routes.filter(route => !route.isApi), render, port);
|
|
59
|
+
const renderPromiseAry = makeRender(routes.filter(route => !route.isApi), render, port); // eslint-disable-next-line promise/no-promise-in-callback
|
|
60
|
+
|
|
60
61
|
const htmlAry = await Promise.all(renderPromiseAry);
|
|
61
62
|
htmlAry.forEach(html => {
|
|
62
63
|
process.send(html);
|