@modern-js/plugin-ssg 1.2.5 → 1.2.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 +8 -0
- package/dist/js/modern/index.js +146 -148
- package/dist/js/node/index.js +145 -148
- package/dist/types/index.d.ts +3 -1
- package/package.json +5 -8
- package/tests/index.test.ts +1 -0
package/CHANGELOG.md
CHANGED
package/dist/js/modern/index.js
CHANGED
|
@@ -6,181 +6,179 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
6
6
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { logger, PLUGIN_SCHEMAS } from '@modern-js/utils';
|
|
9
|
-
import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
|
10
9
|
import { generatePath } from 'react-router-dom';
|
|
11
10
|
import { formatOutput, isDynamicUrl, readJSONSpec, standardOptions, writeJSONSpec } from "./libs/util";
|
|
12
11
|
import { createServer } from "./server";
|
|
13
12
|
import { writeHtmlFile } from "./libs/output";
|
|
14
13
|
import { replaceRoute } from "./libs/replace";
|
|
15
14
|
import { makeRoute } from "./libs/make";
|
|
16
|
-
export default
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}) {
|
|
27
|
-
const {
|
|
28
|
-
entryName
|
|
29
|
-
} = entrypoint;
|
|
30
|
-
agreedRouteMap[entryName] = routes;
|
|
31
|
-
return {
|
|
15
|
+
export default (() => ({
|
|
16
|
+
name: '@modern-js/plugin-ssg',
|
|
17
|
+
setup: api => {
|
|
18
|
+
const agreedRouteMap = {};
|
|
19
|
+
return {
|
|
20
|
+
validateSchema() {
|
|
21
|
+
return PLUGIN_SCHEMAS['@modern-js/plugin-ssg'];
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
modifyFileSystemRoutes({
|
|
32
25
|
entrypoint,
|
|
33
26
|
routes
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
27
|
+
}) {
|
|
28
|
+
const {
|
|
29
|
+
entryName
|
|
30
|
+
} = entrypoint;
|
|
31
|
+
agreedRouteMap[entryName] = routes;
|
|
32
|
+
return {
|
|
33
|
+
entrypoint,
|
|
34
|
+
routes
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
// eslint-disable-next-line max-statements
|
|
39
|
+
async afterBuild() {
|
|
40
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
41
|
+
const appContext = api.useAppContext();
|
|
42
|
+
const {
|
|
43
|
+
appDirectory,
|
|
44
|
+
entrypoints
|
|
45
|
+
} = appContext;
|
|
46
|
+
const {
|
|
47
|
+
output
|
|
48
|
+
} = resolvedConfig;
|
|
49
|
+
const {
|
|
50
|
+
ssg,
|
|
51
|
+
path: outputPath
|
|
52
|
+
} = output;
|
|
53
|
+
const ssgOptions = Array.isArray(ssg) ? ssg.pop() : ssg; // no ssg configuration, skip ssg render.
|
|
59
54
|
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
if (!ssgOptions) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
62
58
|
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
const buildDir = path.join(appDirectory, outputPath);
|
|
60
|
+
const routes = readJSONSpec(buildDir); // filter all routes not web
|
|
65
61
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
62
|
+
const pageRoutes = routes.filter(route => !route.isApi);
|
|
63
|
+
const apiRoutes = routes.filter(route => route.isApi); // if no web page route, skip ssg render
|
|
69
64
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
65
|
+
if (pageRoutes.length === 0) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
75
68
|
|
|
76
|
-
|
|
69
|
+
const intermediateOptions = standardOptions(ssgOptions, entrypoints);
|
|
77
70
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
entryPath
|
|
82
|
-
} = pageRoute;
|
|
83
|
-
const agreedRoutes = agreedRouteMap[entryName];
|
|
84
|
-
let entryOptions = intermediateOptions[entryName];
|
|
85
|
-
|
|
86
|
-
if (!agreedRoutes) {
|
|
87
|
-
// default behavior for non-agreed route
|
|
88
|
-
if (!entryOptions) {
|
|
89
|
-
return;
|
|
90
|
-
} // only add entry route if entryOptions is true
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (entryOptions === true) {
|
|
94
|
-
ssgRoutes.push(_objectSpread(_objectSpread({}, pageRoute), {}, {
|
|
95
|
-
output: entryPath
|
|
96
|
-
}));
|
|
97
|
-
} else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
98
|
-
// if entryOptions is object and has routes options
|
|
99
|
-
// add every route in options
|
|
100
|
-
const {
|
|
101
|
-
routes: enrtyRoutes,
|
|
102
|
-
headers
|
|
103
|
-
} = entryOptions;
|
|
104
|
-
enrtyRoutes.forEach(route => {
|
|
105
|
-
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
// Unless entryOptions is set to false
|
|
110
|
-
// the default behavior is to add all file-based routes
|
|
111
|
-
if (entryOptions === false) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
71
|
+
if (!intermediateOptions) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
114
74
|
|
|
115
|
-
|
|
116
|
-
entryOptions = {
|
|
117
|
-
preventDefault: [],
|
|
118
|
-
routes: [],
|
|
119
|
-
headers: {}
|
|
120
|
-
};
|
|
121
|
-
}
|
|
75
|
+
const ssgRoutes = []; // each route will try to match the configuration
|
|
122
76
|
|
|
77
|
+
pageRoutes.forEach(pageRoute => {
|
|
123
78
|
const {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
79
|
+
entryName,
|
|
80
|
+
entryPath
|
|
81
|
+
} = pageRoute;
|
|
82
|
+
const agreedRoutes = agreedRouteMap[entryName];
|
|
83
|
+
let entryOptions = intermediateOptions[entryName];
|
|
84
|
+
|
|
85
|
+
if (!agreedRoutes) {
|
|
86
|
+
// default behavior for non-agreed route
|
|
87
|
+
if (!entryOptions) {
|
|
88
|
+
return;
|
|
89
|
+
} // only add entry route if entryOptions is true
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
if (entryOptions === true) {
|
|
93
|
+
ssgRoutes.push(_objectSpread(_objectSpread({}, pageRoute), {}, {
|
|
94
|
+
output: entryPath
|
|
95
|
+
}));
|
|
96
|
+
} else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
97
|
+
// if entryOptions is object and has routes options
|
|
98
|
+
// add every route in options
|
|
99
|
+
const {
|
|
100
|
+
routes: enrtyRoutes,
|
|
101
|
+
headers
|
|
102
|
+
} = entryOptions;
|
|
103
|
+
enrtyRoutes.forEach(route => {
|
|
132
104
|
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
ssgRoutes.push(makeRoute(pageRoute, _objectSpread(_objectSpread({}, route), {}, {
|
|
136
|
-
url: generatePath(route.url, param)
|
|
137
|
-
}), headers));
|
|
138
|
-
});
|
|
139
|
-
} else {
|
|
140
|
-
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
141
|
-
}
|
|
142
|
-
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
143
107
|
} else {
|
|
144
|
-
//
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
108
|
+
// Unless entryOptions is set to false
|
|
109
|
+
// the default behavior is to add all file-based routes
|
|
110
|
+
if (entryOptions === false) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!entryOptions || entryOptions === true) {
|
|
115
|
+
entryOptions = {
|
|
116
|
+
preventDefault: [],
|
|
117
|
+
routes: [],
|
|
118
|
+
headers: {}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const {
|
|
123
|
+
preventDefault = [],
|
|
124
|
+
routes: userRoutes = [],
|
|
125
|
+
headers
|
|
126
|
+
} = entryOptions; // if the user sets the routes, then only add them
|
|
127
|
+
|
|
128
|
+
if (userRoutes.length > 0) {
|
|
129
|
+
userRoutes.forEach(route => {
|
|
130
|
+
if (typeof route === 'string') {
|
|
131
|
+
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
132
|
+
} else if (Array.isArray(route.params)) {
|
|
133
|
+
route.params.forEach(param => {
|
|
134
|
+
ssgRoutes.push(makeRoute(pageRoute, _objectSpread(_objectSpread({}, route), {}, {
|
|
135
|
+
url: generatePath(route.url, param)
|
|
136
|
+
}), headers));
|
|
137
|
+
});
|
|
138
|
+
} else {
|
|
139
|
+
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
} else {
|
|
143
|
+
// otherwith add all except dynamic routes
|
|
144
|
+
agreedRoutes.filter(route => !preventDefault.includes(route.path)).forEach(route => {
|
|
145
|
+
if (!isDynamicUrl(route.path)) {
|
|
146
|
+
ssgRoutes.push(makeRoute(pageRoute, route.path, headers));
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
150
|
}
|
|
151
|
-
}
|
|
152
|
-
});
|
|
151
|
+
});
|
|
153
152
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
if (ssgRoutes.length === 0) {
|
|
154
|
+
return;
|
|
155
|
+
} // currently SSG and SSR cannot be turned on at the same time、same route
|
|
157
156
|
|
|
158
157
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
ssgRoutes.forEach(ssgRoute => {
|
|
159
|
+
if (ssgRoute.isSSR) {
|
|
160
|
+
const isOriginRoute = pageRoutes.some(pageRoute => pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName);
|
|
162
161
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
if (isOriginRoute) {
|
|
163
|
+
throw new Error(`ssg can not using with ssr,url - ${ssgRoute.urlPath}, entry - ${ssgRoute.entryName} `);
|
|
164
|
+
}
|
|
166
165
|
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
logger.warn(`new ssg route ${ssgRoute.urlPath} is using ssr now,maybe from parent route ${ssgRoute.entryName},close ssr`);
|
|
167
|
+
}
|
|
169
168
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
169
|
+
ssgRoute.isSSR = false;
|
|
170
|
+
ssgRoute.output = formatOutput(ssgRoute.output);
|
|
171
|
+
});
|
|
172
|
+
const htmlAry = await createServer(ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
174
173
|
|
|
175
|
-
|
|
174
|
+
writeHtmlFile(htmlAry, ssgRoutes, buildDir); // format route info, side effect
|
|
176
175
|
|
|
177
|
-
|
|
176
|
+
replaceRoute(ssgRoutes, pageRoutes); // write routes to spec file
|
|
178
177
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
178
|
+
writeJSONSpec(buildDir, pageRoutes.concat(apiRoutes));
|
|
179
|
+
logger.info('ssg Compiled successfully');
|
|
180
|
+
}
|
|
182
181
|
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
});
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}));
|
package/dist/js/node/index.js
CHANGED
|
@@ -9,8 +9,6 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
9
9
|
|
|
10
10
|
var _utils = require("@modern-js/utils");
|
|
11
11
|
|
|
12
|
-
var _core = require("@modern-js/core");
|
|
13
|
-
|
|
14
12
|
var _reactRouterDom = require("react-router-dom");
|
|
15
13
|
|
|
16
14
|
var _util = require("./libs/util");
|
|
@@ -31,178 +29,177 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
31
29
|
|
|
32
30
|
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; }
|
|
33
31
|
|
|
34
|
-
var _default = (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}) {
|
|
45
|
-
const {
|
|
46
|
-
entryName
|
|
47
|
-
} = entrypoint;
|
|
48
|
-
agreedRouteMap[entryName] = routes;
|
|
49
|
-
return {
|
|
32
|
+
var _default = () => ({
|
|
33
|
+
name: '@modern-js/plugin-ssg',
|
|
34
|
+
setup: api => {
|
|
35
|
+
const agreedRouteMap = {};
|
|
36
|
+
return {
|
|
37
|
+
validateSchema() {
|
|
38
|
+
return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-ssg'];
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
modifyFileSystemRoutes({
|
|
50
42
|
entrypoint,
|
|
51
43
|
routes
|
|
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
|
-
|
|
44
|
+
}) {
|
|
45
|
+
const {
|
|
46
|
+
entryName
|
|
47
|
+
} = entrypoint;
|
|
48
|
+
agreedRouteMap[entryName] = routes;
|
|
49
|
+
return {
|
|
50
|
+
entrypoint,
|
|
51
|
+
routes
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
// eslint-disable-next-line max-statements
|
|
56
|
+
async afterBuild() {
|
|
57
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
58
|
+
const appContext = api.useAppContext();
|
|
59
|
+
const {
|
|
60
|
+
appDirectory,
|
|
61
|
+
entrypoints
|
|
62
|
+
} = appContext;
|
|
63
|
+
const {
|
|
64
|
+
output
|
|
65
|
+
} = resolvedConfig;
|
|
66
|
+
const {
|
|
67
|
+
ssg,
|
|
68
|
+
path: outputPath
|
|
69
|
+
} = output;
|
|
70
|
+
const ssgOptions = Array.isArray(ssg) ? ssg.pop() : ssg; // no ssg configuration, skip ssg render.
|
|
79
71
|
|
|
80
|
-
|
|
72
|
+
if (!ssgOptions) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
81
75
|
|
|
82
|
-
|
|
83
|
-
const apiRoutes = routes.filter(route => route.isApi); // if no web page route, skip ssg render
|
|
76
|
+
const buildDir = _path.default.join(appDirectory, outputPath);
|
|
84
77
|
|
|
85
|
-
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
78
|
+
const routes = (0, _util.readJSONSpec)(buildDir); // filter all routes not web
|
|
88
79
|
|
|
89
|
-
|
|
80
|
+
const pageRoutes = routes.filter(route => !route.isApi);
|
|
81
|
+
const apiRoutes = routes.filter(route => route.isApi); // if no web page route, skip ssg render
|
|
90
82
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
if (pageRoutes.length === 0) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
94
86
|
|
|
95
|
-
|
|
87
|
+
const intermediateOptions = (0, _util.standardOptions)(ssgOptions, entrypoints);
|
|
96
88
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
entryPath
|
|
101
|
-
} = pageRoute;
|
|
102
|
-
const agreedRoutes = agreedRouteMap[entryName];
|
|
103
|
-
let entryOptions = intermediateOptions[entryName];
|
|
104
|
-
|
|
105
|
-
if (!agreedRoutes) {
|
|
106
|
-
// default behavior for non-agreed route
|
|
107
|
-
if (!entryOptions) {
|
|
108
|
-
return;
|
|
109
|
-
} // only add entry route if entryOptions is true
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (entryOptions === true) {
|
|
113
|
-
ssgRoutes.push(_objectSpread(_objectSpread({}, pageRoute), {}, {
|
|
114
|
-
output: entryPath
|
|
115
|
-
}));
|
|
116
|
-
} else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
117
|
-
// if entryOptions is object and has routes options
|
|
118
|
-
// add every route in options
|
|
119
|
-
const {
|
|
120
|
-
routes: enrtyRoutes,
|
|
121
|
-
headers
|
|
122
|
-
} = entryOptions;
|
|
123
|
-
enrtyRoutes.forEach(route => {
|
|
124
|
-
ssgRoutes.push((0, _make.makeRoute)(pageRoute, route, headers));
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
// Unless entryOptions is set to false
|
|
129
|
-
// the default behavior is to add all file-based routes
|
|
130
|
-
if (entryOptions === false) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
89
|
+
if (!intermediateOptions) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
133
92
|
|
|
134
|
-
|
|
135
|
-
entryOptions = {
|
|
136
|
-
preventDefault: [],
|
|
137
|
-
routes: [],
|
|
138
|
-
headers: {}
|
|
139
|
-
};
|
|
140
|
-
}
|
|
93
|
+
const ssgRoutes = []; // each route will try to match the configuration
|
|
141
94
|
|
|
95
|
+
pageRoutes.forEach(pageRoute => {
|
|
142
96
|
const {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
97
|
+
entryName,
|
|
98
|
+
entryPath
|
|
99
|
+
} = pageRoute;
|
|
100
|
+
const agreedRoutes = agreedRouteMap[entryName];
|
|
101
|
+
let entryOptions = intermediateOptions[entryName];
|
|
102
|
+
|
|
103
|
+
if (!agreedRoutes) {
|
|
104
|
+
// default behavior for non-agreed route
|
|
105
|
+
if (!entryOptions) {
|
|
106
|
+
return;
|
|
107
|
+
} // only add entry route if entryOptions is true
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if (entryOptions === true) {
|
|
111
|
+
ssgRoutes.push(_objectSpread(_objectSpread({}, pageRoute), {}, {
|
|
112
|
+
output: entryPath
|
|
113
|
+
}));
|
|
114
|
+
} else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
115
|
+
// if entryOptions is object and has routes options
|
|
116
|
+
// add every route in options
|
|
117
|
+
const {
|
|
118
|
+
routes: enrtyRoutes,
|
|
119
|
+
headers
|
|
120
|
+
} = entryOptions;
|
|
121
|
+
enrtyRoutes.forEach(route => {
|
|
159
122
|
ssgRoutes.push((0, _make.makeRoute)(pageRoute, route, headers));
|
|
160
|
-
}
|
|
161
|
-
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
162
125
|
} else {
|
|
163
|
-
//
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
126
|
+
// Unless entryOptions is set to false
|
|
127
|
+
// the default behavior is to add all file-based routes
|
|
128
|
+
if (entryOptions === false) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (!entryOptions || entryOptions === true) {
|
|
133
|
+
entryOptions = {
|
|
134
|
+
preventDefault: [],
|
|
135
|
+
routes: [],
|
|
136
|
+
headers: {}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const {
|
|
141
|
+
preventDefault = [],
|
|
142
|
+
routes: userRoutes = [],
|
|
143
|
+
headers
|
|
144
|
+
} = entryOptions; // if the user sets the routes, then only add them
|
|
145
|
+
|
|
146
|
+
if (userRoutes.length > 0) {
|
|
147
|
+
userRoutes.forEach(route => {
|
|
148
|
+
if (typeof route === 'string') {
|
|
149
|
+
ssgRoutes.push((0, _make.makeRoute)(pageRoute, route, headers));
|
|
150
|
+
} else if (Array.isArray(route.params)) {
|
|
151
|
+
route.params.forEach(param => {
|
|
152
|
+
ssgRoutes.push((0, _make.makeRoute)(pageRoute, _objectSpread(_objectSpread({}, route), {}, {
|
|
153
|
+
url: (0, _reactRouterDom.generatePath)(route.url, param)
|
|
154
|
+
}), headers));
|
|
155
|
+
});
|
|
156
|
+
} else {
|
|
157
|
+
ssgRoutes.push((0, _make.makeRoute)(pageRoute, route, headers));
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
} else {
|
|
161
|
+
// otherwith add all except dynamic routes
|
|
162
|
+
agreedRoutes.filter(route => !preventDefault.includes(route.path)).forEach(route => {
|
|
163
|
+
if (!(0, _util.isDynamicUrl)(route.path)) {
|
|
164
|
+
ssgRoutes.push((0, _make.makeRoute)(pageRoute, route.path, headers));
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
169
168
|
}
|
|
170
|
-
}
|
|
171
|
-
});
|
|
169
|
+
});
|
|
172
170
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
if (ssgRoutes.length === 0) {
|
|
172
|
+
return;
|
|
173
|
+
} // currently SSG and SSR cannot be turned on at the same time、same route
|
|
176
174
|
|
|
177
175
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
176
|
+
ssgRoutes.forEach(ssgRoute => {
|
|
177
|
+
if (ssgRoute.isSSR) {
|
|
178
|
+
const isOriginRoute = pageRoutes.some(pageRoute => pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName);
|
|
181
179
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
180
|
+
if (isOriginRoute) {
|
|
181
|
+
throw new Error(`ssg can not using with ssr,url - ${ssgRoute.urlPath}, entry - ${ssgRoute.entryName} `);
|
|
182
|
+
}
|
|
185
183
|
|
|
186
|
-
|
|
187
|
-
|
|
184
|
+
_utils.logger.warn(`new ssg route ${ssgRoute.urlPath} is using ssr now,maybe from parent route ${ssgRoute.entryName},close ssr`);
|
|
185
|
+
}
|
|
188
186
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
187
|
+
ssgRoute.isSSR = false;
|
|
188
|
+
ssgRoute.output = (0, _util.formatOutput)(ssgRoute.output);
|
|
189
|
+
});
|
|
190
|
+
const htmlAry = await (0, _server.createServer)(ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
193
191
|
|
|
194
|
-
|
|
192
|
+
(0, _output.writeHtmlFile)(htmlAry, ssgRoutes, buildDir); // format route info, side effect
|
|
195
193
|
|
|
196
|
-
|
|
194
|
+
(0, _replace.replaceRoute)(ssgRoutes, pageRoutes); // write routes to spec file
|
|
197
195
|
|
|
198
|
-
|
|
196
|
+
(0, _util.writeJSONSpec)(buildDir, pageRoutes.concat(apiRoutes));
|
|
199
197
|
|
|
200
|
-
|
|
201
|
-
|
|
198
|
+
_utils.logger.info('ssg Compiled successfully');
|
|
199
|
+
}
|
|
202
200
|
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
name: '@modern-js/plugin-ssg'
|
|
201
|
+
};
|
|
202
|
+
}
|
|
206
203
|
});
|
|
207
204
|
|
|
208
205
|
exports.default = _default;
|
package/dist/types/index.d.ts
CHANGED
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.6",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -55,15 +55,15 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@babel/runtime": "^7",
|
|
58
|
-
"@modern-js/utils": "^1.3.
|
|
58
|
+
"@modern-js/utils": "^1.3.5",
|
|
59
59
|
"node-mocks-http": "^1.10.1",
|
|
60
60
|
"normalize-path": "^3.0.0",
|
|
61
61
|
"portfinder": "^1.0.28",
|
|
62
62
|
"react-router-dom": "^5.2.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@modern-js/types": "^1.3.
|
|
66
|
-
"@modern-js/prod-server": "^1.0.
|
|
65
|
+
"@modern-js/types": "^1.3.5",
|
|
66
|
+
"@modern-js/prod-server": "^1.0.4",
|
|
67
67
|
"@types/jest": "^26",
|
|
68
68
|
"@types/node": "^14",
|
|
69
69
|
"@types/react": "^17",
|
|
@@ -71,14 +71,11 @@
|
|
|
71
71
|
"@types/react-router": "^5.1.16",
|
|
72
72
|
"@types/react-router-dom": "^5.1.8",
|
|
73
73
|
"typescript": "^4",
|
|
74
|
-
"@modern-js/core": "^1.
|
|
74
|
+
"@modern-js/core": "^1.5.0",
|
|
75
75
|
"@scripts/build": "0.0.0",
|
|
76
76
|
"jest": "^27",
|
|
77
77
|
"@scripts/jest-config": "0.0.0"
|
|
78
78
|
},
|
|
79
|
-
"peerDependencies": {
|
|
80
|
-
"@modern-js/core": "^1.4.6"
|
|
81
|
-
},
|
|
82
79
|
"sideEffects": false,
|
|
83
80
|
"modernConfig": {
|
|
84
81
|
"output": {
|