@modern-js/plugin-ssg 1.2.1 → 1.2.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 +44 -0
- package/dist/js/modern/index.js +1 -1
- package/dist/js/modern/libs/make.js +2 -2
- package/dist/js/modern/libs/util.js +12 -2
- package/dist/js/modern/server/index.js +6 -13
- package/dist/js/modern/server/process.js +6 -5
- package/dist/js/node/index.js +1 -1
- package/dist/js/node/libs/make.js +2 -2
- package/dist/js/node/libs/util.js +15 -2
- package/dist/js/node/server/index.js +6 -12
- package/dist/js/node/server/process.js +4 -3
- package/dist/types/libs/util.d.ts +11 -1
- package/dist/types/server/index.d.ts +1 -1
- package/package.json +7 -8
- package/tests/util.test.ts +54 -41
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# @modern-js/plugin-ssg
|
|
2
2
|
|
|
3
|
+
## 1.2.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 02fb4146: support product server
|
|
8
|
+
- cc8501c1: fix ssg build after modify server
|
|
9
|
+
- Updated dependencies [969f172f]
|
|
10
|
+
- Updated dependencies [4c792f68]
|
|
11
|
+
- Updated dependencies [4b5d4bf4]
|
|
12
|
+
- Updated dependencies [62f5b8c8]
|
|
13
|
+
- Updated dependencies [55e18278]
|
|
14
|
+
- Updated dependencies [4499a674]
|
|
15
|
+
- Updated dependencies [403f5169]
|
|
16
|
+
- Updated dependencies [a7f42f48]
|
|
17
|
+
- @modern-js/core@1.4.4
|
|
18
|
+
- @modern-js/utils@1.3.3
|
|
19
|
+
|
|
20
|
+
## 1.2.3
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- 1e17ef11: fix: fix ssg with new plugin route logic
|
|
25
|
+
- Updated dependencies [53aca274]
|
|
26
|
+
- Updated dependencies [78279953]
|
|
27
|
+
- Updated dependencies [e116ace5]
|
|
28
|
+
- Updated dependencies [4d72edea]
|
|
29
|
+
- @modern-js/core@1.4.1
|
|
30
|
+
- @modern-js/utils@1.3.1
|
|
31
|
+
|
|
32
|
+
## 1.2.2
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- 5a7901d7: fix ssg url
|
|
37
|
+
- Updated dependencies [d9cc5ea9]
|
|
38
|
+
- Updated dependencies [bd819a8d]
|
|
39
|
+
- Updated dependencies [ec4dbffb]
|
|
40
|
+
- Updated dependencies [d099e5c5]
|
|
41
|
+
- Updated dependencies [bada2879]
|
|
42
|
+
- Updated dependencies [24f616ca]
|
|
43
|
+
- Updated dependencies [bd819a8d]
|
|
44
|
+
- @modern-js/core@1.4.0
|
|
45
|
+
- @modern-js/utils@1.3.0
|
|
46
|
+
|
|
3
47
|
## 1.2.1
|
|
4
48
|
|
|
5
49
|
### Patch Changes
|
package/dist/js/modern/index.js
CHANGED
|
@@ -172,7 +172,7 @@ export default createPlugin(() => {
|
|
|
172
172
|
ssgRoute.isSSR = false;
|
|
173
173
|
ssgRoute.output = formatOutput(ssgRoute.output);
|
|
174
174
|
});
|
|
175
|
-
const htmlAry = await createServer(ssgRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
175
|
+
const htmlAry = await createServer(ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
176
176
|
|
|
177
177
|
writeHtmlFile(htmlAry, ssgRoutes, buildDir); // format route info, side effect
|
|
178
178
|
|
|
@@ -25,13 +25,13 @@ export function makeRoute(baseRoute, route, headers = {}) {
|
|
|
25
25
|
return _objectSpread(_objectSpread({}, baseRoute), {}, {
|
|
26
26
|
urlPath: normalize(`${urlPath}${route}`) || '/',
|
|
27
27
|
headers,
|
|
28
|
-
output: path.join(entryPath, `..${route}`)
|
|
28
|
+
output: path.join(entryPath, `..${route === '/' ? '' : route}`)
|
|
29
29
|
});
|
|
30
30
|
} else {
|
|
31
31
|
return _objectSpread(_objectSpread({}, baseRoute), {}, {
|
|
32
32
|
urlPath: normalize(`${urlPath}${route.url}`) || '/',
|
|
33
33
|
headers: _objectSpread(_objectSpread({}, headers), route.headers),
|
|
34
|
-
output: route.output ? path.normalize(route.output) : path.join(entryPath, `..${route.url}`)
|
|
34
|
+
output: route.output ? path.normalize(route.output) : path.join(entryPath, `..${route.url === '/' ? '' : route.url}`)
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -1,5 +1,11 @@
|
|
|
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
|
+
|
|
1
7
|
import path from 'path';
|
|
2
|
-
import { ROUTE_SPEC_FILE, fs, isSingleEntry } from '@modern-js/utils';
|
|
8
|
+
import { ROUTE_SPEC_FILE, fs, isSingleEntry, SERVER_BUNDLE_DIRECTORY } from '@modern-js/utils';
|
|
3
9
|
export function formatOutput(filename) {
|
|
4
10
|
const outputPath = path.extname(filename) ? filename : `${filename}/index.html`;
|
|
5
11
|
return outputPath;
|
|
@@ -124,4 +130,8 @@ export const standardOptions = (ssgOptions, entrypoints) => {
|
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
return false;
|
|
127
|
-
};
|
|
133
|
+
};
|
|
134
|
+
export const openRouteSSR = routes => routes.map(ssgRoute => _objectSpread(_objectSpread({}, ssgRoute), {}, {
|
|
135
|
+
isSSR: true,
|
|
136
|
+
bundle: `${SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
137
|
+
}));
|
|
@@ -1,21 +1,13 @@
|
|
|
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
1
|
import childProcess from 'child_process';
|
|
8
2
|
import path from 'path';
|
|
9
|
-
import { logger
|
|
3
|
+
import { logger } from '@modern-js/utils';
|
|
10
4
|
import { useAppContext } from '@modern-js/core';
|
|
5
|
+
import { openRouteSSR } from "../libs/util";
|
|
11
6
|
import { CLOSE_SIGN } from "./consts";
|
|
12
|
-
export const createServer = (ssgRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
7
|
+
export const createServer = (ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
13
8
|
// this side of the shallow copy of a route for subsequent render processing, to prevent the modification of the current field
|
|
14
9
|
// manually enable the server-side rendering configuration for all routes that require SSG
|
|
15
|
-
const backup =
|
|
16
|
-
isSSR: true,
|
|
17
|
-
bundle: `${SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
18
|
-
}));
|
|
10
|
+
const backup = openRouteSSR(pageRoutes);
|
|
19
11
|
const total = backup.concat(apiRoutes);
|
|
20
12
|
const cp = childProcess.fork(path.join(__dirname, 'process'), {
|
|
21
13
|
cwd: appDirectory,
|
|
@@ -26,6 +18,7 @@ export const createServer = (ssgRoutes, apiRoutes, options, appDirectory) => new
|
|
|
26
18
|
const plugins = serverPlugins.map(p => p.name);
|
|
27
19
|
cp.send(JSON.stringify({
|
|
28
20
|
options,
|
|
21
|
+
renderRoutes: ssgRoutes,
|
|
29
22
|
routes: total,
|
|
30
23
|
appDirectory,
|
|
31
24
|
plugins
|
|
@@ -41,7 +34,7 @@ export const createServer = (ssgRoutes, apiRoutes, options, appDirectory) => new
|
|
|
41
34
|
htmlChunks.length = 0;
|
|
42
35
|
}
|
|
43
36
|
|
|
44
|
-
if (htmlAry.length ===
|
|
37
|
+
if (htmlAry.length === ssgRoutes.length) {
|
|
45
38
|
cp.send(CLOSE_SIGN);
|
|
46
39
|
resolve(htmlAry);
|
|
47
40
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import server from '@modern-js/server';
|
|
2
2
|
import portfinder from 'portfinder';
|
|
3
3
|
import { compatRequire } from '@modern-js/utils';
|
|
4
4
|
import { makeRender } from "../libs/make";
|
|
@@ -26,6 +26,7 @@ process.on('message', async chunk => {
|
|
|
26
26
|
const context = JSON.parse(chunk);
|
|
27
27
|
const {
|
|
28
28
|
routes,
|
|
29
|
+
renderRoutes,
|
|
29
30
|
options,
|
|
30
31
|
appDirectory,
|
|
31
32
|
plugins
|
|
@@ -35,13 +36,13 @@ process.on('message', async chunk => {
|
|
|
35
36
|
|
|
36
37
|
try {
|
|
37
38
|
const {
|
|
38
|
-
server
|
|
39
|
+
server: serverOptions
|
|
39
40
|
} = options; // start server in default port
|
|
40
41
|
|
|
41
|
-
const defaultPort = Number(process.env.PORT) ||
|
|
42
|
+
const defaultPort = Number(process.env.PORT) || serverOptions.port;
|
|
42
43
|
portfinder.basePort = defaultPort;
|
|
43
44
|
const port = await portfinder.getPortPromise();
|
|
44
|
-
modernServer = await
|
|
45
|
+
modernServer = await server({
|
|
45
46
|
pwd: appDirectory,
|
|
46
47
|
config: options,
|
|
47
48
|
routes,
|
|
@@ -60,7 +61,7 @@ process.on('message', async chunk => {
|
|
|
60
61
|
|
|
61
62
|
|
|
62
63
|
const render = createRender(modernServer.getRequestHandler());
|
|
63
|
-
const renderPromiseAry = makeRender(
|
|
64
|
+
const renderPromiseAry = makeRender(renderRoutes, render, port); // eslint-disable-next-line promise/no-promise-in-callback
|
|
64
65
|
|
|
65
66
|
const htmlAry = await Promise.all(renderPromiseAry);
|
|
66
67
|
htmlAry.forEach(html => {
|
package/dist/js/node/index.js
CHANGED
|
@@ -191,7 +191,7 @@ var _default = (0, _core.createPlugin)(() => {
|
|
|
191
191
|
ssgRoute.isSSR = false;
|
|
192
192
|
ssgRoute.output = (0, _util.formatOutput)(ssgRoute.output);
|
|
193
193
|
});
|
|
194
|
-
const htmlAry = await (0, _server.createServer)(ssgRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
194
|
+
const htmlAry = await (0, _server.createServer)(ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
195
195
|
|
|
196
196
|
(0, _output.writeHtmlFile)(htmlAry, ssgRoutes, buildDir); // format route info, side effect
|
|
197
197
|
|
|
@@ -38,13 +38,13 @@ function makeRoute(baseRoute, route, headers = {}) {
|
|
|
38
38
|
return _objectSpread(_objectSpread({}, baseRoute), {}, {
|
|
39
39
|
urlPath: (0, _normalizePath.default)(`${urlPath}${route}`) || '/',
|
|
40
40
|
headers,
|
|
41
|
-
output: _path.default.join(entryPath, `..${route}`)
|
|
41
|
+
output: _path.default.join(entryPath, `..${route === '/' ? '' : route}`)
|
|
42
42
|
});
|
|
43
43
|
} else {
|
|
44
44
|
return _objectSpread(_objectSpread({}, baseRoute), {}, {
|
|
45
45
|
urlPath: (0, _normalizePath.default)(`${urlPath}${route.url}`) || '/',
|
|
46
46
|
headers: _objectSpread(_objectSpread({}, headers), route.headers),
|
|
47
|
-
output: route.output ? _path.default.normalize(route.output) : _path.default.join(entryPath, `..${route.url}`)
|
|
47
|
+
output: route.output ? _path.default.normalize(route.output) : _path.default.join(entryPath, `..${route.url === '/' ? '' : route.url}`)
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -8,7 +8,7 @@ exports.formatPath = formatPath;
|
|
|
8
8
|
exports.getOutput = getOutput;
|
|
9
9
|
exports.getUrlPrefix = getUrlPrefix;
|
|
10
10
|
exports.isDynamicUrl = isDynamicUrl;
|
|
11
|
-
exports.writeJSONSpec = exports.standardOptions = exports.replaceWithAlias = exports.readJSONSpec = void 0;
|
|
11
|
+
exports.writeJSONSpec = exports.standardOptions = exports.replaceWithAlias = exports.readJSONSpec = exports.openRouteSSR = void 0;
|
|
12
12
|
|
|
13
13
|
var _path = _interopRequireDefault(require("path"));
|
|
14
14
|
|
|
@@ -16,6 +16,12 @@ var _utils = require("@modern-js/utils");
|
|
|
16
16
|
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
18
|
|
|
19
|
+
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; }
|
|
20
|
+
|
|
21
|
+
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; }
|
|
22
|
+
|
|
23
|
+
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; }
|
|
24
|
+
|
|
19
25
|
function formatOutput(filename) {
|
|
20
26
|
const outputPath = _path.default.extname(filename) ? filename : `${filename}/index.html`;
|
|
21
27
|
return outputPath;
|
|
@@ -157,4 +163,11 @@ const standardOptions = (ssgOptions, entrypoints) => {
|
|
|
157
163
|
return false;
|
|
158
164
|
};
|
|
159
165
|
|
|
160
|
-
exports.standardOptions = standardOptions;
|
|
166
|
+
exports.standardOptions = standardOptions;
|
|
167
|
+
|
|
168
|
+
const openRouteSSR = routes => routes.map(ssgRoute => _objectSpread(_objectSpread({}, ssgRoute), {}, {
|
|
169
|
+
isSSR: true,
|
|
170
|
+
bundle: `${_utils.SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
171
|
+
}));
|
|
172
|
+
|
|
173
|
+
exports.openRouteSSR = openRouteSSR;
|
|
@@ -13,23 +13,16 @@ var _utils = require("@modern-js/utils");
|
|
|
13
13
|
|
|
14
14
|
var _core = require("@modern-js/core");
|
|
15
15
|
|
|
16
|
+
var _util = require("../libs/util");
|
|
17
|
+
|
|
16
18
|
var _consts = require("./consts");
|
|
17
19
|
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
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; }
|
|
23
|
-
|
|
24
|
-
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; }
|
|
25
|
-
|
|
26
|
-
const createServer = (ssgRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
22
|
+
const createServer = (ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
27
23
|
// this side of the shallow copy of a route for subsequent render processing, to prevent the modification of the current field
|
|
28
24
|
// manually enable the server-side rendering configuration for all routes that require SSG
|
|
29
|
-
const backup =
|
|
30
|
-
isSSR: true,
|
|
31
|
-
bundle: `${_utils.SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
32
|
-
}));
|
|
25
|
+
const backup = (0, _util.openRouteSSR)(pageRoutes);
|
|
33
26
|
const total = backup.concat(apiRoutes);
|
|
34
27
|
|
|
35
28
|
const cp = _child_process.default.fork(_path.default.join(__dirname, 'process'), {
|
|
@@ -42,6 +35,7 @@ const createServer = (ssgRoutes, apiRoutes, options, appDirectory) => new Promis
|
|
|
42
35
|
const plugins = serverPlugins.map(p => p.name);
|
|
43
36
|
cp.send(JSON.stringify({
|
|
44
37
|
options,
|
|
38
|
+
renderRoutes: ssgRoutes,
|
|
45
39
|
routes: total,
|
|
46
40
|
appDirectory,
|
|
47
41
|
plugins
|
|
@@ -57,7 +51,7 @@ const createServer = (ssgRoutes, apiRoutes, options, appDirectory) => new Promis
|
|
|
57
51
|
htmlChunks.length = 0;
|
|
58
52
|
}
|
|
59
53
|
|
|
60
|
-
if (htmlAry.length ===
|
|
54
|
+
if (htmlAry.length === ssgRoutes.length) {
|
|
61
55
|
cp.send(_consts.CLOSE_SIGN);
|
|
62
56
|
resolve(htmlAry);
|
|
63
57
|
}
|
|
@@ -35,6 +35,7 @@ process.on('message', async chunk => {
|
|
|
35
35
|
const context = JSON.parse(chunk);
|
|
36
36
|
const {
|
|
37
37
|
routes,
|
|
38
|
+
renderRoutes,
|
|
38
39
|
options,
|
|
39
40
|
appDirectory,
|
|
40
41
|
plugins
|
|
@@ -44,10 +45,10 @@ process.on('message', async chunk => {
|
|
|
44
45
|
|
|
45
46
|
try {
|
|
46
47
|
const {
|
|
47
|
-
server
|
|
48
|
+
server: serverOptions
|
|
48
49
|
} = options; // start server in default port
|
|
49
50
|
|
|
50
|
-
const defaultPort = Number(process.env.PORT) ||
|
|
51
|
+
const defaultPort = Number(process.env.PORT) || serverOptions.port;
|
|
51
52
|
_portfinder.default.basePort = defaultPort;
|
|
52
53
|
const port = await _portfinder.default.getPortPromise();
|
|
53
54
|
modernServer = await (0, _server.default)({
|
|
@@ -69,7 +70,7 @@ process.on('message', async chunk => {
|
|
|
69
70
|
|
|
70
71
|
|
|
71
72
|
const render = (0, _prerender.compile)(modernServer.getRequestHandler());
|
|
72
|
-
const renderPromiseAry = (0, _make.makeRender)(
|
|
73
|
+
const renderPromiseAry = (0, _make.makeRender)(renderRoutes, render, port); // eslint-disable-next-line promise/no-promise-in-callback
|
|
73
74
|
|
|
74
75
|
const htmlAry = await Promise.all(renderPromiseAry);
|
|
75
76
|
htmlAry.forEach(html => {
|
|
@@ -8,4 +8,14 @@ export declare function getOutput(route: SsgRoute, base: string, agreed?: boolea
|
|
|
8
8
|
export declare const readJSONSpec: (dir: string) => ModernRoute[];
|
|
9
9
|
export declare const writeJSONSpec: (dir: string, routes: ModernRoute[]) => void;
|
|
10
10
|
export declare const replaceWithAlias: (base: string, filePath: string, alias: string) => string;
|
|
11
|
-
export declare const standardOptions: (ssgOptions: SSG, entrypoints: EntryPoint[]) => false | MultiEntryOptions;
|
|
11
|
+
export declare const standardOptions: (ssgOptions: SSG, entrypoints: EntryPoint[]) => false | MultiEntryOptions;
|
|
12
|
+
export declare const openRouteSSR: (routes: ModernRoute[]) => {
|
|
13
|
+
isSSR: boolean;
|
|
14
|
+
bundle: string;
|
|
15
|
+
entryName?: string | undefined;
|
|
16
|
+
urlPath: string;
|
|
17
|
+
entryPath: string;
|
|
18
|
+
isSPA?: boolean | undefined;
|
|
19
|
+
isApi?: boolean | undefined;
|
|
20
|
+
enableModernMode?: boolean | undefined;
|
|
21
|
+
}[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { NormalizedConfig } from '@modern-js/core';
|
|
2
2
|
import { ServerRoute as ModernRoute } from '@modern-js/types';
|
|
3
3
|
import { SsgRoute } from '../types';
|
|
4
|
-
export declare const createServer: (ssgRoutes: SsgRoute[], apiRoutes: ModernRoute[], options: NormalizedConfig, appDirectory: string) => Promise<string[]>;
|
|
4
|
+
export declare const createServer: (ssgRoutes: SsgRoute[], pageRoutes: ModernRoute[], apiRoutes: ModernRoute[], options: NormalizedConfig, appDirectory: string) => Promise<string[]>;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.2.
|
|
14
|
+
"version": "1.2.4",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -37,15 +37,15 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@babel/runtime": "^7",
|
|
40
|
-
"@modern-js/utils": "^1.
|
|
40
|
+
"@modern-js/utils": "^1.3.3",
|
|
41
41
|
"node-mocks-http": "^1.10.1",
|
|
42
42
|
"normalize-path": "^3.0.0",
|
|
43
43
|
"portfinder": "^1.0.28",
|
|
44
44
|
"react-router-dom": "^5.2.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@modern-js/server": "^1.
|
|
48
|
-
"@modern-js/types": "^1.
|
|
47
|
+
"@modern-js/server": "^1.4.4",
|
|
48
|
+
"@modern-js/types": "^1.3.4",
|
|
49
49
|
"@types/jest": "^26",
|
|
50
50
|
"@types/node": "^14",
|
|
51
51
|
"@types/react": "^17",
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
"@types/react-router": "^5.1.16",
|
|
54
54
|
"@types/react-router-dom": "^5.1.8",
|
|
55
55
|
"typescript": "^4",
|
|
56
|
-
"@modern-js/core": "^1.
|
|
56
|
+
"@modern-js/core": "^1.4.4",
|
|
57
57
|
"@scripts/build": "0.0.0",
|
|
58
58
|
"jest": "^27",
|
|
59
59
|
"@scripts/jest-config": "0.0.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"@modern-js/core": "^1.
|
|
62
|
+
"@modern-js/core": "^1.4.4"
|
|
63
63
|
},
|
|
64
64
|
"sideEffects": false,
|
|
65
65
|
"modernConfig": {
|
|
@@ -69,8 +69,7 @@
|
|
|
69
69
|
},
|
|
70
70
|
"publishConfig": {
|
|
71
71
|
"registry": "https://registry.npmjs.org/",
|
|
72
|
-
"access": "public"
|
|
73
|
-
"types": "./dist/types/index.d.ts"
|
|
72
|
+
"access": "public"
|
|
74
73
|
},
|
|
75
74
|
"scripts": {
|
|
76
75
|
"new": "modern new",
|
package/tests/util.test.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
getOutput,
|
|
7
7
|
replaceWithAlias,
|
|
8
8
|
standardOptions,
|
|
9
|
+
openRouteSSR,
|
|
9
10
|
} from '../src/libs/util';
|
|
10
11
|
|
|
11
12
|
describe('test ssg util function', () => {
|
|
@@ -73,6 +74,7 @@ describe('test ssg util function', () => {
|
|
|
73
74
|
expect(replaceWithAlias('/src', '/src/app.js', '@src')).toBe('@src/app.js');
|
|
74
75
|
});
|
|
75
76
|
|
|
77
|
+
// eslint-disable-next-line max-statements
|
|
76
78
|
it('should starndar user config correctly', () => {
|
|
77
79
|
const opt0 = standardOptions(false, []);
|
|
78
80
|
expect(opt0).toBeFalsy();
|
|
@@ -98,47 +100,58 @@ describe('test ssg util function', () => {
|
|
|
98
100
|
};
|
|
99
101
|
const opt4 = standardOptions(ssg1, [{ entryName: 'main', entry: '' }]);
|
|
100
102
|
expect(opt4).toEqual({ main: ssg1 });
|
|
103
|
+
|
|
104
|
+
// error usage, just test
|
|
105
|
+
const ssg2 = {
|
|
106
|
+
routes: ['/foo', { url: '/baz' }],
|
|
107
|
+
};
|
|
108
|
+
const opt5 = standardOptions(ssg2, [
|
|
109
|
+
{ entryName: 'main', entry: '' },
|
|
110
|
+
{ entryName: 'home', entry: '' },
|
|
111
|
+
]);
|
|
112
|
+
expect(opt5).toEqual(ssg2);
|
|
113
|
+
|
|
114
|
+
const ssg3 = {
|
|
115
|
+
main: { routes: ['/foo', { url: '/baz' }] },
|
|
116
|
+
home: false,
|
|
117
|
+
};
|
|
118
|
+
const opt6 = standardOptions(ssg3, [
|
|
119
|
+
{ entryName: 'main', entry: '' },
|
|
120
|
+
{ entryName: 'home', entry: '' },
|
|
121
|
+
]);
|
|
122
|
+
expect(opt6).toEqual(ssg3);
|
|
123
|
+
|
|
124
|
+
const ssg4 = () => true;
|
|
125
|
+
const opt7 = standardOptions(ssg4, [
|
|
126
|
+
{ entryName: 'main', entry: '' },
|
|
127
|
+
{ entryName: 'home', entry: '' },
|
|
128
|
+
]);
|
|
129
|
+
expect(opt7).toEqual({ main: true, home: true });
|
|
130
|
+
|
|
131
|
+
const ssg5 = (entryName: string) => {
|
|
132
|
+
if (entryName === 'main') {
|
|
133
|
+
return true;
|
|
134
|
+
} else {
|
|
135
|
+
return {
|
|
136
|
+
routes: ['/foo'],
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const opt8 = standardOptions(ssg5, [
|
|
141
|
+
{ entryName: 'main', entry: '' },
|
|
142
|
+
{ entryName: 'home', entry: '' },
|
|
143
|
+
]);
|
|
144
|
+
expect(opt8).toEqual({ main: true, home: { routes: ['/foo'] } });
|
|
101
145
|
});
|
|
102
146
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const ssg3 = {
|
|
114
|
-
main: { routes: ['/foo', { url: '/baz' }] },
|
|
115
|
-
home: false,
|
|
116
|
-
};
|
|
117
|
-
const opt6 = standardOptions(ssg3, [
|
|
118
|
-
{ entryName: 'main', entry: '' },
|
|
119
|
-
{ entryName: 'home', entry: '' },
|
|
120
|
-
]);
|
|
121
|
-
expect(opt6).toEqual(ssg3);
|
|
122
|
-
|
|
123
|
-
const ssg4 = () => true;
|
|
124
|
-
const opt7 = standardOptions(ssg4, [
|
|
125
|
-
{ entryName: 'main', entry: '' },
|
|
126
|
-
{ entryName: 'home', entry: '' },
|
|
127
|
-
]);
|
|
128
|
-
expect(opt7).toEqual({ main: true, home: true });
|
|
129
|
-
|
|
130
|
-
const ssg5 = (entryName: string) => {
|
|
131
|
-
if (entryName === 'main') {
|
|
132
|
-
return true;
|
|
133
|
-
} else {
|
|
134
|
-
return {
|
|
135
|
-
routes: ['/foo'],
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
const opt8 = standardOptions(ssg5, [
|
|
140
|
-
{ entryName: 'main', entry: '' },
|
|
141
|
-
{ entryName: 'home', entry: '' },
|
|
142
|
-
]);
|
|
143
|
-
expect(opt8).toEqual({ main: true, home: { routes: ['/foo'] } });
|
|
147
|
+
it('should get ssr route correctly', () => {
|
|
148
|
+
const ssrRoutes = openRouteSSR([
|
|
149
|
+
{
|
|
150
|
+
isSSR: false,
|
|
151
|
+
},
|
|
152
|
+
] as any);
|
|
153
|
+
|
|
154
|
+
expect(ssrRoutes[0].isSSR).toBeTruthy();
|
|
155
|
+
expect(ssrRoutes[0].bundle).toBeDefined();
|
|
156
|
+
});
|
|
144
157
|
});
|