@modern-js/main-doc 0.0.0-nightly-20240827170702 → 0.0.0-nightly-20240829170706

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 +98 -213
  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
@@ -52,7 +52,7 @@ function useLoader(loaderFn: LoaderFn, options: Options): ReturnData;
52
52
  - `initialData`: the initial data before the first execution,.
53
53
  - `skip`: when the value is `true`, the function does not execute.
54
54
  - `params`: when the result of the `params` serialization changes, the function is re-executed. `params` is also passed in as the second argument of the function.
55
- - `static`: when the value is `true`, `useLoader` is used for [SSG](/guides/advanced-features/ssg).
55
+ - `static`: when the value is `true`, `useLoader` is used for [SSG](/guides/basic-features/render/ssg).
56
56
 
57
57
  ### Return Value
58
58
 
@@ -0,0 +1,3 @@
1
+ :::note
2
+ Coming soon
3
+ :::
@@ -4,46 +4,24 @@ title: ssg
4
4
 
5
5
  # output.ssg
6
6
 
7
- - **Type:** `boolean` | `object` | `function`
8
- - **Default:** `undefined`
7
+ - **Type:** `boolean` | `object`
8
+ - **Default Value:** `undefined`
9
9
 
10
- Enable the SSG for **Self-controlled Routing** or **Conventional Routing**.
10
+ Configuration to enable the application’s SSG (Static Site Generation) feature.
11
11
 
12
- :::info Enable SSG
13
- This configuration will only be available when the SSG feature is enabled. Please read the [Static Site Generation](/guides/advanced-features/ssg) documentation to learn how to enable the SSG feature.
12
+ :::tip Enabling SSG
13
+ This configuration takes effect only when SSG is enabled. Please read the [Static Site Generation](/guides/basic-features/render/ssg) documentation to understand how to enable SSG and its use cases.
14
14
  :::
15
15
 
16
- :::info
17
- For more routes detail, see [Routing](/guides/basic-features/routes).
18
-
16
+ :::info Recommended Reading
17
+ The SSG feature is closely related to routing. It is recommended to understand the [routing solution](/guides/basic-features/routes) before using SSG.
19
18
  :::
20
19
 
21
- ## Example
22
-
23
- ### Single Entry
24
-
25
- When the configuration is set to `true`, the SSG of all entries will be enabled by default.
26
-
27
- For **self-controlled routing**, the root route of the entry will be rendered. For **convention routing**, every route in the entry will be rendered.
28
-
29
- For example, the `src/` directory has the following file structure that satisfies **conventional routing**:
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 Type
43
21
 
44
- Make the following config in `modern.config.[tj]s`:
22
+ When this configuration is set to `true`, the SSG feature will be enabled for all entries by default. For **manual routing**, the root route of the entry will be rendered. For **conventional routing**, each route in the entry will be rendered.
45
23
 
46
- ```ts
24
+ ```js
47
25
  export default defineConfig({
48
26
  output: {
49
27
  ssg: true,
@@ -51,39 +29,20 @@ export default defineConfig({
51
29
  });
52
30
  ```
53
31
 
54
- After executing `pnpm build` to build the application. The `dist/` directory will generate three HTML for each of the three routes (only one HTML if SSG not enabled), and all HTML has been rendered.
55
-
56
- For example the following **self-controlled routing**:
57
-
58
- import SelfRouteExample from "@site-docs/components/self-route-example";
59
-
60
- <SelfRouteExample />
61
-
62
- Also using the above configuration, after executing `pnpm run build`, only the entry route `/` will generate the rendered HTML.
32
+ `output.ssg` can also be configured per entry, with the rules for effective configurations determined by the entry's routing method.
63
33
 
64
- ### Multi Entries
65
-
66
- `output.ssg` can also be configured according to the entries, and the rules that the configuration takes effect are also determined by the entries routing method.
67
-
68
- For example the following directory structure:
34
+ For example, given the following directory structure, there are conventional routing entry `entryA` and manual routing entry `entryB`:
69
35
 
70
36
  ```bash
71
37
  .
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
38
+ └── src
39
+ ├── entryA
40
+ │ └── routes
41
+ └── entryB
42
+ └── App.tsx
84
43
  ```
85
44
 
86
- By default, all entryA entrances are rendered at build time after setting `output.ssg` to `true`. You can configure `false` to cancel the default behavior of the specified entries. For example, to cancel the rendering of the `entryA` at build time:
45
+ You can specify different SSG configurations for `entryA` and `entryB`:
87
46
 
88
47
  ```js
89
48
  export default defineConfig({
@@ -96,107 +55,59 @@ export default defineConfig({
96
55
  });
97
56
  ```
98
57
 
99
- ### Configure Route
100
-
101
- As mentioned above, **Self-Controlled Routing** only enables SSG configuration for entries route by default.
102
-
103
- Set specific routes in `output.ssg` can tell Modern.js to enable the SSG of these client side routes. For example, the content of the above `src/App.tsx` file is:
104
-
105
- <SelfRouteExample />
106
-
107
-
108
- When set like this in `modern.config.[jt]s`, the `/about` route will also enable SSG:
109
-
110
- ```js
111
- export default defineConfig({
112
- output: {
113
- ssg: {
114
- routes: ['/', '/about'],
115
- },
116
- },
117
- });
118
- ```
119
-
120
- Modern.js will automatically concat the complete URL according to the entry and hand it over to the SSG plugin to complete the rendering.
121
-
122
- Request headers can also be configured for specific entries or routes, for example:
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
- The `headers` set in the route override the `headers` set in the entry.
143
-
59
+ For more information on the default behavior of **conventional routing** and **manual routing** after enabling SSG, please read [Static Site Generation](/guides/basic-features/render/ssg).
144
60
  :::
145
61
 
146
- ### Prevent Default
62
+ ## Object Type
147
63
 
148
- By default, **Conventional Routing** all turn on SSG. Modern.js provides another field to prevent the default SSG behavior.
64
+ When the value type is `Object`, the following attributes can be configured.
149
65
 
150
- For example, the following directory structure , `/`、`/user` and `/user/profle` all have SSG enabled:
66
+ ### Configuration Type
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
- You can set this to disable the default behavior of a client-side route:
166
68
 
167
- ```js
168
- export default defineConfig({
169
- output: {
170
- ssg: {
171
- preventDefault: ['/user'],
172
- },
173
- },
174
- });
69
+ ```ts
70
+ type SSGRouteOptions = string | {
71
+ url: string;
72
+ params?: Record<string, any>[];
73
+ headers?: Record<string, any>;
74
+ };
75
+
76
+ type SSGOptions = {
77
+ preventDefault?: string[];
78
+ headers?: Record<string, any>;
79
+ routes?: SSGRouteOptions[];
80
+ };
175
81
  ```
176
82
 
177
- ### Dynamic Params
83
+ ### Example
178
84
 
179
- Some routes may be dynamic, such as the `/user/:id` in a self-controlled route or the route generated by the `user/[id]/page.tsx` file in a conventional route.
85
+ In the example configuration below, SSG will render the pages corresponding to the `/`, `/about`, and `/user/:id` routes.
180
86
 
181
- configure specific parameters in `output.ssg` to render the route of the specified parameters, for example:
87
+ For the `/user/:id` route, `cookies` will be added to the request headers, and the `id` in `params` will be replaced with `modernjs`.
182
88
 
183
- ```js
89
+ ```ts title="modern.config.ts"
184
90
  export default defineConfig({
185
91
  output: {
186
92
  ssg: {
187
93
  routes: [
94
+ '/',
95
+ '/about',
188
96
  {
189
97
  url: '/user/:id',
190
- params: [
191
- {
192
- id: 'modernjs',
193
- },
194
- ],
195
- },
98
+ headers: {
99
+ cookies: "name=modernjs"
100
+ },
101
+ params: [{
102
+ id: 'modernjs',
103
+ }],
104
+ }
196
105
  ],
197
- },
198
- },
106
+ }
107
+ }
199
108
  });
200
109
  ```
201
110
 
202
- The features of dynamic routing and SSG is useful when generating static pages in real time based on CMS system.
111
+ :::note
112
+ The configuration method for multiple entries is the same as for a single entry, so it will not be explained further here.
113
+ :::
@@ -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",