@modern-js/main-doc 0.0.0-nightly-20240828170710 → 0.0.0-nightly-20240830170740

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/docs/en/apis/app/runtime/core/use-loader.mdx +1 -1
  2. package/docs/en/components/ssr-monitor.mdx +3 -0
  3. package/docs/en/configure/app/output/ssg.mdx +52 -141
  4. package/docs/en/guides/advanced-features/_meta.json +0 -7
  5. package/docs/en/guides/basic-features/_meta.json +7 -1
  6. package/docs/en/guides/basic-features/data/data-fetch.mdx +134 -235
  7. package/docs/en/guides/basic-features/data/data-write.mdx +66 -77
  8. package/docs/en/guides/basic-features/render/_meta.json +1 -0
  9. package/docs/en/guides/basic-features/render/ssg.mdx +208 -0
  10. package/docs/en/guides/{advanced-features/ssr/cache.mdx → basic-features/render/ssr-cache.mdx} +38 -50
  11. package/docs/en/guides/basic-features/render/ssr.mdx +301 -0
  12. package/docs/en/guides/basic-features/render/streaming-ssr.mdx +230 -0
  13. package/docs/en/guides/basic-features/routes.mdx +275 -263
  14. package/docs/en/guides/concept/entries.mdx +9 -2
  15. package/docs/zh/apis/app/runtime/core/use-loader.mdx +1 -1
  16. package/docs/zh/components/ssr-monitor.mdx +3 -0
  17. package/docs/zh/configure/app/output/ssg.mdx +49 -139
  18. package/docs/zh/guides/advanced-features/_meta.json +0 -7
  19. package/docs/zh/guides/basic-features/_meta.json +7 -1
  20. package/docs/zh/guides/basic-features/data/data-fetch.mdx +96 -211
  21. package/docs/zh/guides/basic-features/data/data-write.mdx +54 -55
  22. package/docs/zh/guides/basic-features/render/_meta.json +1 -0
  23. package/docs/zh/guides/basic-features/render/ssg.mdx +210 -0
  24. package/docs/zh/guides/{advanced-features/ssr/cache.mdx → basic-features/render/ssr-cache.mdx} +16 -26
  25. package/docs/zh/guides/basic-features/render/ssr.mdx +309 -0
  26. package/docs/zh/guides/{advanced-features/ssr/stream.mdx → basic-features/render/streaming-ssr.mdx} +22 -37
  27. package/docs/zh/guides/basic-features/routes.mdx +252 -237
  28. package/docs/zh/guides/concept/entries.mdx +6 -3
  29. package/package.json +6 -6
  30. package/docs/en/guides/advanced-features/ssg.mdx +0 -116
  31. package/docs/en/guides/advanced-features/ssr/_meta.json +0 -1
  32. package/docs/en/guides/advanced-features/ssr/index.mdx +0 -23
  33. package/docs/en/guides/advanced-features/ssr/stream.mdx +0 -248
  34. package/docs/en/guides/advanced-features/ssr/usage.mdx +0 -341
  35. package/docs/en/guides/advanced-features/ssr.mdx +0 -555
  36. package/docs/zh/guides/advanced-features/ssg.mdx +0 -116
  37. package/docs/zh/guides/advanced-features/ssr/_meta.json +0 -1
  38. package/docs/zh/guides/advanced-features/ssr/index.mdx +0 -23
  39. package/docs/zh/guides/advanced-features/ssr/usage.mdx +0 -329
@@ -116,6 +116,8 @@ For more information, please refer to [Conventional Routing](/guides/basic-featu
116
116
 
117
117
  #### Self-controlled Routing
118
118
 
119
+ ## Manual Routing
120
+
119
121
  If there is an `App.[jt]sx?` file within the entry, we refer to this entry as a self-controlled route. For example:
120
122
 
121
123
  ```bash
@@ -124,7 +126,9 @@ If there is an `App.[jt]sx?` file within the entry, we refer to this entry as a
124
126
  │ └── App.tsx
125
127
  ```
126
128
 
127
- In this file, you can define client-side routes or not to set any client-side routes.
129
+ For entry points defined as `src/App.tsx`, Modern.js does not perform any additional routing operations. Developers can use the [React Router 6](https://reactrouter.com/en/main) API for development, define client-side routes or not to set any client-side routes.
130
+
131
+ for example, define client-side routes in application:
128
132
 
129
133
  ```tsx
130
134
  import { BrowserRouter, Route, Routes } from '@modern-js/runtime/router';
@@ -141,7 +145,10 @@ export default () => {
141
145
  };
142
146
  ```
143
147
 
144
- For more information, please refer to [Self-controlled Routing](/guides/basic-features/routes.html#self-controlled-routing).
148
+ :::note
149
+ We recommend that developers use conventional routing. Modern.js provides a series of optimizations in resource loading and rendering for conventional routing by default and offers built-in SSR capabilities. When using manual routing, these capabilities need to be encapsulated by developers themselves.
150
+ :::
151
+
145
152
 
146
153
  #### Custom Entry
147
154
 
@@ -52,7 +52,7 @@ function useLoader(loaderFn: LoaderFn, options: Options): ReturnData;
52
52
  - `initialData`:首次执行前的初始数据,对应返回值中的 `data` 字段。
53
53
  - `skip`:当值为 `true` 时,函数不执行。
54
54
  - `params`:当 `params` 序列化结果发生改变时,函数会重新执行。同时,`params` 也会作为函数的第二个参数被传入。
55
- - `static`:当值为 `true` 时,`useLoader` 用于 [SSG](/guides/advanced-features/ssg) 编译阶段数据的获取。
55
+ - `static`:当值为 `true` 时,`useLoader` 用于 [SSG](/guides/basic-features/render/ssg) 编译阶段数据的获取。
56
56
 
57
57
  ### 返回值
58
58
 
@@ -0,0 +1,3 @@
1
+ :::note
2
+ 敬请期待
3
+ :::
@@ -4,44 +4,22 @@ title: ssg
4
4
 
5
5
  # output.ssg
6
6
 
7
- - **类型:** `boolean` | `object` | `function`
7
+ - **类型:** `boolean` | `object`
8
8
  - **默认值:** `undefined`
9
9
 
10
- 开启**自控式路由**或**约定式路由** SSG 功能的配置。
10
+ 开启应用 SSG 功能的配置
11
11
 
12
- :::info 开启 SSG 功能
13
- 此配置需要在开启 SSG 功能情况下才会生效。请阅读 [静态站点生成](/guides/advanced-features/ssg) 文档了解如何开启 SSG 功能。
12
+ :::tip 开启 SSG 功能
13
+ 此配置需要在开启 SSG 功能情况下才会生效。请阅读 [静态站点生成](/guides/basic-features/render/ssg) 文档了解如何开启 SSG 功能及使用场景。
14
14
  :::
15
15
 
16
- :::info 客户端路由
17
- 相关内容可以查看[路由方案](/guides/basic-features/routes)。
18
-
16
+ :::info 前置阅读
17
+ SSG 功能使用与路由关联性较大,建议使用前先了解[路由方案](/guides/basic-features/routes)。
19
18
  :::
20
19
 
21
- ## 示例
22
-
23
- ### 单入口
24
-
25
- 当该配置设置为 `true` 时,将会默认开启所有入口的 SSG 功能。
26
-
27
- 对**自控式路由**而言,将会渲染入口的根路由。对**约定式路由**而言,将会渲染入口中每一条路由。
28
-
29
- 例如 `src/` 目录下有以下满足**约定式路由**的文件结构:
30
-
31
- ```bash
32
- .
33
- ├── src
34
- │ └── routes
35
- │ ├── layout.tsx
36
- │ ├── page.tsx
37
- │ └── user
38
- │ ├── layout.tsx
39
- │ ├── page.tsx
40
- │ └── profile
41
- │ └── page.tsx
42
- ```
20
+ ## Boolean 类型
43
21
 
44
- `modern.config.js` 中做以下设置:
22
+ 当该配置设置为 `true` 时,将会默认开启所有入口的 SSG 功能。对**自控式路由**而言,将会渲染入口的根路由。对**约定式路由**而言,将会渲染入口中每一条路由。
45
23
 
46
24
  ```js
47
25
  export default defineConfig({
@@ -51,39 +29,20 @@ export default defineConfig({
51
29
  });
52
30
  ```
53
31
 
54
- 执行 `pnpm build` 构建应用后。`dist/` 目录将会生成三张 HTML 分别对应三条路由(不开启 SSG 时只有一张 HTML),并且所有 HTML 都已经渲染。
55
-
56
- 而例如下面的**自控式路由**:
57
-
58
- import SelfRouteExample from "@site-docs/components/self-route-example";
59
-
60
- <SelfRouteExample />
61
-
62
- 同样使用上面的配置,在执行 `pnpm run build` 后,只有入口路由 `/` 会生成渲染后的 HTML。
63
-
64
- ### 多入口
65
-
66
32
  `output.ssg` 也可以按照入口配置,配置生效的规则同样由入口路由方式决定。
67
33
 
68
- 例如以下目录结构:
34
+ 例如以下目录结构,分别存在约定式路由入口 `entryA` 和自控式路由入口 `entryB`:
69
35
 
70
36
  ```bash
71
-
72
- ├── src
73
- ├── entryA
74
- └── routes
75
- │ │ ├── layout.tsx
76
- │ │ ├── page.tsx
77
- │ │ └── user
78
- │ │ ├── layout.tsx
79
- │ │ ├── page.tsx
80
- │ │ └── profile
81
- │ │ └── page.tsx
82
- │ └── entryB
83
- │ └── App.tsx
37
+ .
38
+ └── src
39
+ ├── entryA
40
+ │ └── routes
41
+ └── entryB
42
+ └── App.tsx
84
43
  ```
85
44
 
86
- 默认情况下,所有约定式路由的入口,在设置 `output.ssg` 配置为 `true` 后都会在构建阶段渲染。可以配置 `false` 来取消指定入口的的默认行为,例如取消上述 entryA 入口在构建时的渲染:
45
+ 你可以指定 `entryA` `entryB` 的不同 SSG 配置:
87
46
 
88
47
  ```js
89
48
  export default defineConfig({
@@ -96,107 +55,58 @@ export default defineConfig({
96
55
  });
97
56
  ```
98
57
 
99
- ### 配置路由
100
-
101
- 上述内容中提到,**自控式路由**默认只会开启入口路由的 SSG 配置。
102
-
103
- 可以在 `output.ssg` 中设置具体的路由,告知 Modern.js 开启这些客户端路由的 SSG 功能。例如上述 `src/App.tsx` 的文件内容为:
104
-
105
-
106
- <SelfRouteExample />
107
-
108
- 在 `modern.config.js` 中这样设置后,`/about` 路由也会开启 SSG 功能:
109
-
110
- ```js
111
- export default defineConfig({
112
- output: {
113
- ssg: {
114
- routes: ['/', '/about'],
115
- },
116
- },
117
- });
118
- ```
119
-
120
- Modern.js 将会自动根据入口拼接完整的 URL 并交给 SSG 插件完成渲染。
121
-
122
- 也可以为具体入口或路由配置请求头,例如:
123
-
124
- ```js
125
- export default defineConfig({
126
- output: {
127
- ssg: {
128
- headers: {},
129
- routes: [
130
- '/',
131
- {
132
- url: '/about',
133
- headers: {},
134
- },
135
- ],
136
- },
137
- },
138
- });
139
- ```
140
-
141
58
  :::info
142
- 路由中设置的 `headers` 会覆盖入口中设置的 `headers`。
143
-
59
+ 更多关于**约定式路由**和**自控式路由**在开启 SSG 后的默认行为,请阅读 [静态站点生成](/guides/basic-features/render/ssg) 。
144
60
  :::
145
61
 
146
- ### 阻止默认行为
62
+ ## Object 类型
147
63
 
148
- 默认情况下,**约定式路由**的路由会全部开启 SSG。Modern.js 提供了另一个字段,用来阻止默认的 SSG 行为。
64
+ 当值类型为 `Object` 时,可以配置如下属性。
149
65
 
150
- 例如以下目录结构,`/`、`/user`、`/user/profle` 三条路由都开启 SSG:
66
+ ### 配置类型
151
67
 
152
- ```bash
153
- .
154
- ├── src
155
- │ └── routes
156
- │ ├── layout.tsx
157
- │ ├── page.tsx
158
- │ └── user
159
- │ ├── layout.tsx
160
- │ ├── page.tsx
161
- │ └── profile
162
- │ └── page.tsx
163
- ```
164
-
165
- 可以这样设置,禁用某一条客户端路由的默认行为:
68
+ ```ts
69
+ type SSGRouteOptions = string | {
70
+ url: string;
71
+ params?: Record<string, any>[];
72
+ headers?: Record<string, any>;
73
+ };
166
74
 
167
- ```js
168
- export default defineConfig({
169
- output: {
170
- ssg: {
171
- preventDefault: ['/user'],
172
- },
173
- },
174
- });
75
+ type SSGOptions = {
76
+ preventDefault?: string[];
77
+ headers?: Record<string, any>;
78
+ routes?: SSGRouteOptions[];
79
+ };
175
80
  ```
176
81
 
177
- ### 添加动态路由参数
82
+ ### 示例
178
83
 
179
- 部分路由可能是动态的,例如自控式路由中的 `/user/:id` 或是约定式路由中 `user/[id]/page.tsx` 文件生成的路由。
84
+ 下面的示例配置中,SSG 会渲染 `/`、`/about` `/user/:id` 三条路由对应的页面。
180
85
 
181
- 可以在 `output.ssg` 中配置具体的参数,渲染指定参数的路由,例如:
86
+ 对于 `/user/:id` 路由,`cookies` 添加到请求头中,同时会将 `params` 中的 `id` 替换为 `modernjs`。
182
87
 
183
- ```js
88
+ ```ts title="modern.config.ts"
184
89
  export default defineConfig({
185
90
  output: {
186
91
  ssg: {
187
92
  routes: [
93
+ '/',
94
+ '/about',
188
95
  {
189
96
  url: '/user/:id',
190
- params: [
191
- {
192
- id: 'modernjs',
193
- },
194
- ],
195
- },
97
+ headers: {
98
+ cookies: "name=modernjs"
99
+ },
100
+ params: [{
101
+ id: 'modernjs',
102
+ }],
103
+ }
196
104
  ],
197
- },
198
- },
105
+ }
106
+ }
199
107
  });
200
108
  ```
201
109
 
202
- 动态路由和 SSG 的组合,在根据 CMS 系统数据变更,实时生成静态页面时非常有用。
110
+ :::note
111
+ 多入口的情况和单入口的配置方式一致,这里不再额外介绍。
112
+ :::
@@ -7,13 +7,6 @@
7
7
  "collapsed": true
8
8
  },
9
9
  "code-split",
10
- {
11
- "type": "dir",
12
- "name": "ssr",
13
- "label": "use-ssr",
14
- "collapsed": true
15
- },
16
- "ssg",
17
10
  "compatibility",
18
11
  "eslint",
19
12
  "low-level",
@@ -1,5 +1,4 @@
1
1
  [
2
- "css",
3
2
  "routes",
4
3
  {
5
4
  "type": "dir",
@@ -7,6 +6,13 @@
7
6
  "label": "data-solution",
8
7
  "collapsed": true
9
8
  },
9
+ {
10
+ "type": "dir",
11
+ "name": "render",
12
+ "label": "rendering",
13
+ "collapsed": true
14
+ },
15
+ "css",
10
16
  "alias",
11
17
  "mock",
12
18
  "proxy",