@modern-js/plugin-ssg 1.0.0-rc.9 → 1.1.1
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 +249 -0
- package/README.md +19 -21
- package/dist/js/modern/index.js +96 -58
- package/dist/js/modern/libs/{render.js → make.js} +22 -0
- package/dist/js/modern/libs/replace.js +3 -2
- package/dist/js/modern/libs/util.js +38 -22
- package/dist/js/modern/server/index.js +1 -1
- package/dist/js/modern/server/process.js +3 -2
- package/dist/js/modern/types.js +1 -0
- package/dist/js/node/index.js +94 -57
- package/dist/js/node/libs/{render.js → make.js} +28 -0
- package/dist/js/node/libs/replace.js +3 -2
- package/dist/js/node/libs/util.js +38 -29
- package/dist/js/node/server/index.js +2 -2
- package/dist/js/node/server/process.js +3 -2
- 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 +21 -9
- package/src/index.ts +84 -83
- package/src/libs/make.ts +45 -0
- package/src/libs/replace.ts +7 -4
- package/src/libs/util.ts +40 -28
- package/src/server/index.ts +2 -2
- package/src/server/process.ts +4 -2
- package/src/types.ts +26 -20
- package/tests/.eslintrc.js +6 -0
- package/tests/lib.test.ts +48 -169
- 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/loader/index.js +0 -105
- package/dist/js/modern/manifest-op.js +0 -101
- package/dist/js/node/libs/createPage.js +0 -57
- package/dist/js/node/libs/invoker.js +0 -66
- package/dist/js/node/loader/index.js +0 -115
- package/dist/js/node/manifest-op.js +0 -124
- 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 -111
- package/tests/operate.test.ts +0 -39
package/.eslintrc.js
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,254 @@
|
|
|
1
1
|
# @modern-js/plugin-ssg
|
|
2
2
|
|
|
3
|
+
## 1.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0fa83663: support more .env files
|
|
8
|
+
- Updated dependencies [6f7fe574]
|
|
9
|
+
- Updated dependencies [0fa83663]
|
|
10
|
+
- Updated dependencies [f594fbc8]
|
|
11
|
+
- @modern-js/core@1.1.2
|
|
12
|
+
- @modern-js/utils@1.1.2
|
|
13
|
+
|
|
14
|
+
## 1.1.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- 96119db2: Relese v1.1.0
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [96119db2]
|
|
23
|
+
- @modern-js/core@1.1.0
|
|
24
|
+
- @modern-js/utils@1.1.0
|
|
25
|
+
|
|
26
|
+
## 1.0.0
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- 224f7fe: fix server route match
|
|
31
|
+
- 30ac27c: feat: add generator package description
|
|
32
|
+
- 0fd196e: feat: fix bugs
|
|
33
|
+
- 204c626: feat: initial
|
|
34
|
+
- 63be0a5: fix: #118 #104
|
|
35
|
+
- Updated dependencies [224f7fe]
|
|
36
|
+
- Updated dependencies [30ac27c]
|
|
37
|
+
- Updated dependencies [0fd196e]
|
|
38
|
+
- Updated dependencies [204c626]
|
|
39
|
+
- Updated dependencies [63be0a5]
|
|
40
|
+
- @modern-js/core@1.0.0
|
|
41
|
+
- @modern-js/babel-chain@1.0.0
|
|
42
|
+
- @modern-js/utils@1.0.0
|
|
43
|
+
|
|
44
|
+
## 1.0.0-rc.23
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- 224f7fe: fix server route match
|
|
49
|
+
- 30ac27c: feat: add generator package description
|
|
50
|
+
- 0fd196e: feat: fix bugs
|
|
51
|
+
- 204c626: feat: initial
|
|
52
|
+
- 63be0a5: fix: #118 #104
|
|
53
|
+
- Updated dependencies [224f7fe]
|
|
54
|
+
- Updated dependencies [30ac27c]
|
|
55
|
+
- Updated dependencies [0fd196e]
|
|
56
|
+
- Updated dependencies [204c626]
|
|
57
|
+
- Updated dependencies [63be0a5]
|
|
58
|
+
- @modern-js/core@1.0.0-rc.23
|
|
59
|
+
- @modern-js/babel-chain@1.0.0-rc.23
|
|
60
|
+
- @modern-js/utils@1.0.0-rc.23
|
|
61
|
+
|
|
62
|
+
## 1.0.0-rc.22
|
|
63
|
+
|
|
64
|
+
### Patch Changes
|
|
65
|
+
|
|
66
|
+
- 224f7fe: fix server route match
|
|
67
|
+
- 30ac27c: feat: add generator package description
|
|
68
|
+
- 0fd196e: feat: fix bugs
|
|
69
|
+
- 204c626: feat: initial
|
|
70
|
+
- 63be0a5: fix: #118 #104
|
|
71
|
+
- Updated dependencies [224f7fe]
|
|
72
|
+
- Updated dependencies [30ac27c]
|
|
73
|
+
- Updated dependencies [0fd196e]
|
|
74
|
+
- Updated dependencies [204c626]
|
|
75
|
+
- Updated dependencies [63be0a5]
|
|
76
|
+
- @modern-js/core@1.0.0-rc.22
|
|
77
|
+
- @modern-js/babel-chain@1.0.0-rc.22
|
|
78
|
+
- @modern-js/utils@1.0.0-rc.22
|
|
79
|
+
|
|
80
|
+
## 1.0.0-rc.21
|
|
81
|
+
|
|
82
|
+
### Patch Changes
|
|
83
|
+
|
|
84
|
+
- 224f7fe: fix server route match
|
|
85
|
+
- 30ac27c: feat: add generator package description
|
|
86
|
+
- 0fd196e: feat: fix bugs
|
|
87
|
+
- 204c626: feat: initial
|
|
88
|
+
- 63be0a5: fix: #118 #104
|
|
89
|
+
- Updated dependencies [224f7fe]
|
|
90
|
+
- Updated dependencies [30ac27c]
|
|
91
|
+
- Updated dependencies [0fd196e]
|
|
92
|
+
- Updated dependencies [204c626]
|
|
93
|
+
- Updated dependencies [63be0a5]
|
|
94
|
+
- @modern-js/core@1.0.0-rc.21
|
|
95
|
+
- @modern-js/babel-chain@1.0.0-rc.21
|
|
96
|
+
- @modern-js/utils@1.0.0-rc.21
|
|
97
|
+
|
|
98
|
+
## 1.0.0-rc.20
|
|
99
|
+
|
|
100
|
+
### Patch Changes
|
|
101
|
+
|
|
102
|
+
- 224f7fe: fix server route match
|
|
103
|
+
- 30ac27c: feat: add generator package description
|
|
104
|
+
- feat: fix bugs
|
|
105
|
+
- 204c626: feat: initial
|
|
106
|
+
- 63be0a5: fix: #118 #104
|
|
107
|
+
- Updated dependencies [224f7fe]
|
|
108
|
+
- Updated dependencies [30ac27c]
|
|
109
|
+
- Updated dependencies [undefined]
|
|
110
|
+
- Updated dependencies [204c626]
|
|
111
|
+
- Updated dependencies [63be0a5]
|
|
112
|
+
- @modern-js/core@1.0.0-rc.20
|
|
113
|
+
- @modern-js/babel-chain@1.0.0-rc.20
|
|
114
|
+
- @modern-js/utils@1.0.0-rc.20
|
|
115
|
+
|
|
116
|
+
## 1.0.0-rc.19
|
|
117
|
+
|
|
118
|
+
### Patch Changes
|
|
119
|
+
|
|
120
|
+
- 224f7fe: fix server route match
|
|
121
|
+
- 30ac27c: feat: add generator package description
|
|
122
|
+
- 204c626: feat: initial
|
|
123
|
+
- 63be0a5: fix: #118 #104
|
|
124
|
+
- Updated dependencies [224f7fe]
|
|
125
|
+
- Updated dependencies [30ac27c]
|
|
126
|
+
- Updated dependencies [204c626]
|
|
127
|
+
- Updated dependencies [63be0a5]
|
|
128
|
+
- @modern-js/core@1.0.0-rc.19
|
|
129
|
+
- @modern-js/babel-chain@1.0.0-rc.19
|
|
130
|
+
- @modern-js/utils@1.0.0-rc.19
|
|
131
|
+
|
|
132
|
+
## 1.0.0-rc.18
|
|
133
|
+
|
|
134
|
+
### Patch Changes
|
|
135
|
+
|
|
136
|
+
- 224f7fe: fix server route match
|
|
137
|
+
- 30ac27c: feat: add generator package description
|
|
138
|
+
- 204c626: feat: initial
|
|
139
|
+
- 63be0a5: fix: #118 #104
|
|
140
|
+
- Updated dependencies [224f7fe]
|
|
141
|
+
- Updated dependencies [30ac27c]
|
|
142
|
+
- Updated dependencies [204c626]
|
|
143
|
+
- Updated dependencies [63be0a5]
|
|
144
|
+
- @modern-js/core@1.0.0-rc.18
|
|
145
|
+
- @modern-js/babel-chain@1.0.0-rc.18
|
|
146
|
+
- @modern-js/utils@1.0.0-rc.18
|
|
147
|
+
|
|
148
|
+
## 1.0.0-rc.17
|
|
149
|
+
|
|
150
|
+
### Patch Changes
|
|
151
|
+
|
|
152
|
+
- 224f7fe: fix server route match
|
|
153
|
+
- 30ac27c: feat: add generator package description
|
|
154
|
+
- 204c626: feat: initial
|
|
155
|
+
- fix: #118 #104
|
|
156
|
+
- Updated dependencies [224f7fe]
|
|
157
|
+
- Updated dependencies [30ac27c]
|
|
158
|
+
- Updated dependencies [204c626]
|
|
159
|
+
- Updated dependencies [undefined]
|
|
160
|
+
- @modern-js/core@1.0.0-rc.17
|
|
161
|
+
- @modern-js/babel-chain@1.0.0-rc.17
|
|
162
|
+
- @modern-js/utils@1.0.0-rc.17
|
|
163
|
+
|
|
164
|
+
## 1.0.0-rc.16
|
|
165
|
+
|
|
166
|
+
### Patch Changes
|
|
167
|
+
|
|
168
|
+
- 224f7fe: fix server route match
|
|
169
|
+
- 30ac27c: feat: add generator package description
|
|
170
|
+
- 204c626: feat: initial
|
|
171
|
+
- Updated dependencies [224f7fe]
|
|
172
|
+
- Updated dependencies [30ac27c]
|
|
173
|
+
- Updated dependencies [204c626]
|
|
174
|
+
- @modern-js/core@1.0.0-rc.16
|
|
175
|
+
- @modern-js/babel-chain@1.0.0-rc.16
|
|
176
|
+
- @modern-js/utils@1.0.0-rc.16
|
|
177
|
+
|
|
178
|
+
## 1.0.0-rc.15
|
|
179
|
+
|
|
180
|
+
### Patch Changes
|
|
181
|
+
|
|
182
|
+
- 224f7fe: fix server route match
|
|
183
|
+
- 30ac27c: feat: add generator package description
|
|
184
|
+
- 204c626: feat: initial
|
|
185
|
+
- Updated dependencies [224f7fe]
|
|
186
|
+
- Updated dependencies [30ac27c]
|
|
187
|
+
- Updated dependencies [204c626]
|
|
188
|
+
- @modern-js/core@1.0.0-rc.15
|
|
189
|
+
- @modern-js/babel-chain@1.0.0-rc.15
|
|
190
|
+
- @modern-js/utils@1.0.0-rc.15
|
|
191
|
+
|
|
192
|
+
## 1.0.0-rc.14
|
|
193
|
+
|
|
194
|
+
### Patch Changes
|
|
195
|
+
|
|
196
|
+
- 224f7fe: fix server route match
|
|
197
|
+
- 204c626: feat: initial
|
|
198
|
+
- Updated dependencies [224f7fe]
|
|
199
|
+
- Updated dependencies [204c626]
|
|
200
|
+
- @modern-js/core@1.0.0-rc.14
|
|
201
|
+
- @modern-js/babel-chain@1.0.0-rc.14
|
|
202
|
+
- @modern-js/utils@1.0.0-rc.14
|
|
203
|
+
|
|
204
|
+
## 1.0.0-rc.13
|
|
205
|
+
|
|
206
|
+
### Patch Changes
|
|
207
|
+
|
|
208
|
+
- 224f7fe: fix server route match
|
|
209
|
+
- 204c626: feat: initial
|
|
210
|
+
- Updated dependencies [224f7fe]
|
|
211
|
+
- Updated dependencies [204c626]
|
|
212
|
+
- @modern-js/core@1.0.0-rc.13
|
|
213
|
+
- @modern-js/babel-chain@1.0.0-rc.13
|
|
214
|
+
- @modern-js/utils@1.0.0-rc.13
|
|
215
|
+
|
|
216
|
+
## 1.0.0-rc.12
|
|
217
|
+
|
|
218
|
+
### Patch Changes
|
|
219
|
+
|
|
220
|
+
- 224f7fe: fix server route match
|
|
221
|
+
- 204c626: feat: initial
|
|
222
|
+
- Updated dependencies [224f7fe]
|
|
223
|
+
- Updated dependencies [204c626]
|
|
224
|
+
- @modern-js/core@1.0.0-rc.12
|
|
225
|
+
- @modern-js/babel-chain@1.0.0-rc.12
|
|
226
|
+
- @modern-js/utils@1.0.0-rc.12
|
|
227
|
+
|
|
228
|
+
## 1.0.0-rc.11
|
|
229
|
+
|
|
230
|
+
### Patch Changes
|
|
231
|
+
|
|
232
|
+
- 224f7fe: fix server route match
|
|
233
|
+
- 204c626: feat: initial
|
|
234
|
+
- Updated dependencies [224f7fe]
|
|
235
|
+
- Updated dependencies [204c626]
|
|
236
|
+
- @modern-js/core@1.0.0-rc.11
|
|
237
|
+
- @modern-js/babel-chain@1.0.0-rc.11
|
|
238
|
+
- @modern-js/utils@1.0.0-rc.11
|
|
239
|
+
|
|
240
|
+
## 1.0.0-rc.10
|
|
241
|
+
|
|
242
|
+
### Patch Changes
|
|
243
|
+
|
|
244
|
+
- 224f7fe: fix server route match
|
|
245
|
+
- 204c626: feat: initial
|
|
246
|
+
- Updated dependencies [224f7fe]
|
|
247
|
+
- Updated dependencies [204c626]
|
|
248
|
+
- @modern-js/core@1.0.0-rc.10
|
|
249
|
+
- @modern-js/babel-chain@1.0.0-rc.10
|
|
250
|
+
- @modern-js/utils@1.0.0-rc.10
|
|
251
|
+
|
|
3
252
|
## 1.0.0-rc.9
|
|
4
253
|
|
|
5
254
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -2,31 +2,29 @@
|
|
|
2
2
|
<p align="center">
|
|
3
3
|
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
|
|
4
4
|
</p>
|
|
5
|
+
<p align="center">
|
|
6
|
+
现代 Web 工程体系
|
|
7
|
+
<br/>
|
|
8
|
+
<a href="https://modernjs.dev" target="blank">
|
|
9
|
+
modernjs.dev
|
|
10
|
+
</a>
|
|
11
|
+
</p>
|
|
12
|
+
<p align="center">
|
|
13
|
+
The meta-framework suite designed from scratch for frontend-focused modern web development
|
|
14
|
+
</p>
|
|
5
15
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
## 背景
|
|
9
|
-
- [迈入现代 Web 开发](https://zhuanlan.zhihu.com/p/386607009)
|
|
10
|
-
- [现代 Web 开发者问卷调查报告](https://zhuanlan.zhihu.com/p/403206195)
|
|
11
|
-
|
|
12
|
-
## 计划
|
|
13
|
-
|
|
14
|
-
Modern.js 的 1.0.0.rc 版已经发到 npm,目前在做测试改进,README 文档之后统一提供(现阶段加入测试和开发,可以发 [issue](https://github.com/modern-js-dev/modern.js/issues) 留微信联系),完整的文档站计划在10月14日上线
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
# Introduction
|
|
27
17
|
|
|
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.
|
|
28
19
|
|
|
20
|
+
- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)
|
|
29
21
|
|
|
22
|
+
## Getting Started
|
|
30
23
|
|
|
24
|
+
- [Quick Start](https://modernjs.dev/docs/start)
|
|
25
|
+
- [Guides](https://modernjs.dev/docs/guides)
|
|
26
|
+
- [API References](https://modernjs.dev/docs/apis)
|
|
31
27
|
|
|
28
|
+
## Contributing
|
|
32
29
|
|
|
30
|
+
- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1,38 +1,21 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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';
|
|
8
|
+
import { logger, PLUGIN_SCHEMAS } from '@modern-js/utils';
|
|
2
9
|
import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { formatOutput, getOutput, getSSGRenderLevel, getUrlPrefix, parsedSSGConfig, readJSONSpec, replaceWithAlias, writeJSONSpec } from "./libs/util";
|
|
6
|
-
import { invoker } from "./libs/invoker";
|
|
10
|
+
import { generatePath } from 'react-router-dom';
|
|
11
|
+
import { formatOutput, isDynamicUrl, readJSONSpec, standardOptions, writeJSONSpec } from "./libs/util";
|
|
7
12
|
import { createServer } from "./server";
|
|
8
13
|
import { writeHtmlFile } from "./libs/output";
|
|
9
14
|
import { replaceRoute } from "./libs/replace";
|
|
10
|
-
|
|
11
|
-
const listStaticFiles = (pwd, entriesDir, useSSG) => {
|
|
12
|
-
const absEntriesDir = path.join(pwd, entriesDir);
|
|
13
|
-
const staticRenderLevel = getSSGRenderLevel(useSSG);
|
|
14
|
-
const staticFiles = new LoaderManifest().get(absEntriesDir, staticRenderLevel); // 将绝对路径转换成 alias,因为获取到的约定路由也是使用别名的
|
|
15
|
-
|
|
16
|
-
const staticAlias = staticFiles.map(filepath => replaceWithAlias(path.join(pwd, 'src'), filepath, INTERNAL_SRC_ALIAS));
|
|
17
|
-
return staticAlias;
|
|
18
|
-
};
|
|
19
|
-
|
|
15
|
+
import { makeRoute } from "./libs/make";
|
|
20
16
|
export default createPlugin(() => {
|
|
21
17
|
const agreedRouteMap = {};
|
|
22
18
|
return {
|
|
23
|
-
config() {
|
|
24
|
-
return {
|
|
25
|
-
tools: {
|
|
26
|
-
babel(config, {
|
|
27
|
-
chain
|
|
28
|
-
}) {
|
|
29
|
-
chain.plugin('./loader').use(require.resolve("./loader"));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
|
|
36
19
|
validateSchema() {
|
|
37
20
|
return PLUGIN_SCHEMAS['@modern-js/plugin-ssg'];
|
|
38
21
|
},
|
|
@@ -58,16 +41,11 @@ export default createPlugin(() => {
|
|
|
58
41
|
|
|
59
42
|
const appContext = useAppContext();
|
|
60
43
|
const {
|
|
61
|
-
appDirectory
|
|
44
|
+
appDirectory,
|
|
45
|
+
entrypoints
|
|
62
46
|
} = appContext;
|
|
63
47
|
const {
|
|
64
|
-
output
|
|
65
|
-
server: {
|
|
66
|
-
baseUrl
|
|
67
|
-
},
|
|
68
|
-
source: {
|
|
69
|
-
entriesDir
|
|
70
|
-
}
|
|
48
|
+
output
|
|
71
49
|
} = resolvedConfig;
|
|
72
50
|
const {
|
|
73
51
|
ssg,
|
|
@@ -79,13 +57,8 @@ export default createPlugin(() => {
|
|
|
79
57
|
return;
|
|
80
58
|
}
|
|
81
59
|
|
|
82
|
-
const {
|
|
83
|
-
useSSG,
|
|
84
|
-
userHook
|
|
85
|
-
} = parsedSSGConfig(ssgOptions);
|
|
86
60
|
const buildDir = path.join(appDirectory, outputPath);
|
|
87
|
-
const routes = readJSONSpec(buildDir);
|
|
88
|
-
const staticAlias = listStaticFiles(appDirectory, entriesDir, useSSG); // filter all routes not web
|
|
61
|
+
const routes = readJSONSpec(buildDir); // filter all routes not web
|
|
89
62
|
|
|
90
63
|
const pageRoutes = routes.filter(route => !route.isApi);
|
|
91
64
|
const apiRoutes = routes.filter(route => route.isApi); // if no web page route, skip ssg render
|
|
@@ -94,27 +67,91 @@ export default createPlugin(() => {
|
|
|
94
67
|
return;
|
|
95
68
|
}
|
|
96
69
|
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
const listener = (route, agreed) => {
|
|
100
|
-
const urlPrefix = getUrlPrefix(route, baseUrl);
|
|
101
|
-
const ssgOutput = getOutput(route, urlPrefix, agreed);
|
|
102
|
-
route.output = formatOutput(route.entryPath, ssgOutput);
|
|
103
|
-
ssgRoutes.push(route);
|
|
104
|
-
}; // check if every allowed agreed route was collected
|
|
105
|
-
|
|
70
|
+
const intermediateOptions = standardOptions(ssgOptions, entrypoints);
|
|
106
71
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return false;
|
|
111
|
-
} // if allowed, return collection state
|
|
72
|
+
if (!intermediateOptions) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
112
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
|
+
}
|
|
113
116
|
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
if (!entryOptions || entryOptions === true) {
|
|
118
|
+
entryOptions = {
|
|
119
|
+
preventDefault: [],
|
|
120
|
+
routes: [],
|
|
121
|
+
headers: {}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
116
124
|
|
|
117
|
-
|
|
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
|
+
});
|
|
118
155
|
|
|
119
156
|
if (ssgRoutes.length === 0) {
|
|
120
157
|
return;
|
|
@@ -133,6 +170,7 @@ export default createPlugin(() => {
|
|
|
133
170
|
}
|
|
134
171
|
|
|
135
172
|
ssgRoute.isSSR = false;
|
|
173
|
+
ssgRoute.output = formatOutput(ssgRoute.output);
|
|
136
174
|
});
|
|
137
175
|
const htmlAry = await createServer(ssgRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
|
|
138
176
|
|
|
@@ -4,6 +4,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
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
|
+
import path from 'path';
|
|
8
|
+
import normalize from 'normalize-path';
|
|
7
9
|
export function makeRender(ssgRoutes, render, port) {
|
|
8
10
|
return ssgRoutes.map(ssgRoute => render({
|
|
9
11
|
url: ssgRoute.urlPath,
|
|
@@ -12,4 +14,24 @@ export function makeRender(ssgRoutes, render, port) {
|
|
|
12
14
|
}, ssgRoute.headers),
|
|
13
15
|
connection: {}
|
|
14
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
|
+
}
|
|
15
37
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const _excluded = ["output"];
|
|
1
|
+
const _excluded = ["output", "headers"];
|
|
2
2
|
|
|
3
3
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
4
4
|
|
|
@@ -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,10 +1,8 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { ROUTE_SPEC_FILE, fs } from '@modern-js/utils';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const dirname = path.dirname(base);
|
|
7
|
-
return path.join(dirname, file);
|
|
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;
|
|
8
6
|
}
|
|
9
7
|
export function formatPath(str) {
|
|
10
8
|
let addr = str;
|
|
@@ -90,22 +88,40 @@ export const writeJSONSpec = (dir, routes) => {
|
|
|
90
88
|
spaces: 2
|
|
91
89
|
});
|
|
92
90
|
};
|
|
93
|
-
export const
|
|
94
|
-
|
|
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
|
|
95
119
|
|
|
96
|
-
|
|
97
|
-
|
|
120
|
+
intermediateOptions[entryName] = ssgOptions(entryName);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return intermediateOptions;
|
|
98
124
|
}
|
|
99
125
|
|
|
100
|
-
return
|
|
101
|
-
};
|
|
102
|
-
export const parsedSSGConfig = ssg => {
|
|
103
|
-
const useSSG = typeof ssg === 'string' ? ssg : true; // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
104
|
-
|
|
105
|
-
const userHook = typeof ssg === 'function' ? ssg : () => {};
|
|
106
|
-
return {
|
|
107
|
-
useSSG,
|
|
108
|
-
userHook
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
export const replaceWithAlias = (base, filePath, alias) => path.join(alias, path.relative(base, filePath));
|
|
126
|
+
return false;
|
|
127
|
+
};
|
|
@@ -6,8 +6,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
6
6
|
|
|
7
7
|
import childProcess from 'child_process';
|
|
8
8
|
import path from 'path';
|
|
9
|
-
import { useAppContext } from '@modern-js/core';
|
|
10
9
|
import { logger, SERVER_BUNDLE_DIRECTORY } from '@modern-js/utils';
|
|
10
|
+
import { useAppContext } from '@modern-js/core';
|
|
11
11
|
import { CLOSE_SIGN } from "./consts";
|
|
12
12
|
export const createServer = (ssgRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
13
13
|
// this side of the shallow copy of a route for subsequent render processing, to prevent the modification of the current field
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Server from '@modern-js/server';
|
|
2
2
|
import portfinder from 'portfinder';
|
|
3
3
|
import { compatRequire } from '@modern-js/utils';
|
|
4
|
-
import { makeRender } from "../libs/
|
|
4
|
+
import { makeRender } from "../libs/make";
|
|
5
5
|
import { compile as createRender } from "./prerender";
|
|
6
6
|
import { CLOSE_SIGN } from "./consts";
|
|
7
7
|
|
|
@@ -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);
|
package/dist/js/modern/types.js
CHANGED