@modern-js/main-doc 3.9.3 → 3.10.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.
Files changed (197) hide show
  1. package/docs/en/apis/app/hooks/api/lambda.mdx +2 -1
  2. package/docs/en/apis/app/hooks/config/html.mdx +1 -0
  3. package/docs/en/apis/app/hooks/config/mock.mdx +1 -0
  4. package/docs/en/apis/app/hooks/config/public.mdx +1 -0
  5. package/docs/en/apis/app/hooks/config/upload.mdx +2 -3
  6. package/docs/en/apis/app/hooks/modern-config.mdx +1 -0
  7. package/docs/en/apis/app/hooks/shared.mdx +1 -0
  8. package/docs/en/apis/app/hooks/src/modern.runtime.mdx +1 -0
  9. package/docs/en/apis/app/hooks/src/routes.mdx +1 -0
  10. package/docs/en/apis/app/hooks/src/server.mdx +2 -1
  11. package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +1 -0
  12. package/docs/en/apis/app/runtime/core/create-root.mdx +4 -1
  13. package/docs/en/apis/app/runtime/core/render.mdx +6 -2
  14. package/docs/en/apis/app/runtime/core/runtime-context.mdx +17 -17
  15. package/docs/en/apis/app/runtime/router/router.mdx +9 -6
  16. package/docs/en/apis/app/runtime/ssr/no-ssr.mdx +1 -0
  17. package/docs/en/apis/app/runtime/utility/head.mdx +1 -0
  18. package/docs/en/apis/app/runtime/utility/loadable.mdx +1 -0
  19. package/docs/en/community/blog/v3-release-note.mdx +36 -27
  20. package/docs/en/community/contributing-guide.mdx +15 -33
  21. package/docs/en/components/default-browserslist.mdx +0 -1
  22. package/docs/en/components/deploy-command.mdx +1 -1
  23. package/docs/en/components/deploy.mdx +1 -1
  24. package/docs/en/components/entry-scan-logic.mdx +1 -1
  25. package/docs/en/components/init-app.mdx +9 -3
  26. package/docs/en/components/international/custom-instance-code.mdx +0 -1
  27. package/docs/en/components/micro-runtime-config.mdx +12 -9
  28. package/docs/en/components/nodeVersion.mdx +2 -2
  29. package/docs/en/components/rsc-deploy-tip.mdx +0 -1
  30. package/docs/en/components/ssr-monitor.mdx +1 -1
  31. package/docs/en/configure/app/bff/cross-project.mdx +2 -2
  32. package/docs/en/configure/app/bff/prefix.mdx +1 -1
  33. package/docs/en/configure/app/dev/lazy-compilation.mdx +17 -1
  34. package/docs/en/configure/app/dev/start-url.mdx +0 -1
  35. package/docs/en/configure/app/output/css-modules.mdx +1 -5
  36. package/docs/en/configure/app/output/dist-path.mdx +0 -1
  37. package/docs/en/configure/app/output/inline-scripts.mdx +1 -2
  38. package/docs/en/configure/app/output/inline-styles.mdx +1 -2
  39. package/docs/en/configure/app/output/split-route-chunks.mdx +1 -1
  40. package/docs/en/configure/app/output/ssg.mdx +1 -1
  41. package/docs/en/configure/app/output/ssgByEntries.mdx +1 -0
  42. package/docs/en/configure/app/performance/chunk-split.mdx +1 -4
  43. package/docs/en/configure/app/runtime/plugins.mdx +6 -4
  44. package/docs/en/configure/app/server/rsc.mdx +1 -1
  45. package/docs/en/configure/app/server/ssr.mdx +7 -8
  46. package/docs/en/configure/app/server/tsconfig-path.mdx +2 -2
  47. package/docs/en/configure/app/tools/less.mdx +5 -6
  48. package/docs/en/configure/app/tools/sass.mdx +5 -6
  49. package/docs/en/configure/app/tools/svgr.mdx +7 -7
  50. package/docs/en/configure/app/usage.mdx +1 -5
  51. package/docs/en/guides/advanced-features/bff/cross-project.mdx +5 -4
  52. package/docs/en/guides/advanced-features/compatibility.mdx +0 -1
  53. package/docs/en/guides/advanced-features/international/advanced.mdx +1 -1
  54. package/docs/en/guides/advanced-features/international/api.mdx +34 -28
  55. package/docs/en/guides/advanced-features/international/best-practices.mdx +15 -15
  56. package/docs/en/guides/advanced-features/international/configuration.mdx +37 -37
  57. package/docs/en/guides/advanced-features/international/locale-detection.mdx +37 -28
  58. package/docs/en/guides/advanced-features/international/resource-loading.mdx +19 -17
  59. package/docs/en/guides/advanced-features/international/routing.mdx +8 -6
  60. package/docs/en/guides/advanced-features/international.mdx +8 -8
  61. package/docs/en/guides/advanced-features/server-monitor/logger.mdx +5 -5
  62. package/docs/en/guides/advanced-features/server-monitor/metrics.mdx +8 -8
  63. package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +1 -3
  64. package/docs/en/guides/advanced-features/source-build.mdx +1 -1
  65. package/docs/en/guides/advanced-features/web-server.mdx +3 -3
  66. package/docs/en/guides/basic-features/data/data-fetch.mdx +1 -3
  67. package/docs/en/guides/basic-features/data/data-write.mdx +24 -28
  68. package/docs/en/guides/basic-features/debug/mock.mdx +2 -2
  69. package/docs/en/guides/basic-features/debug/using-storybook.mdx +5 -6
  70. package/docs/en/guides/basic-features/html.mdx +2 -3
  71. package/docs/en/guides/basic-features/output-files.mdx +1 -1
  72. package/docs/en/guides/basic-features/render/overview.mdx +12 -12
  73. package/docs/en/guides/basic-features/render/rsc.mdx +16 -9
  74. package/docs/en/guides/basic-features/render/ssr-cache.mdx +5 -5
  75. package/docs/en/guides/basic-features/render/ssr.mdx +8 -12
  76. package/docs/en/guides/basic-features/render/streaming-ssr.mdx +2 -1
  77. package/docs/en/guides/basic-features/routes/config-routes.mdx +60 -59
  78. package/docs/en/guides/basic-features/testing/playwright.mdx +14 -8
  79. package/docs/en/guides/basic-features/testing/rstest.mdx +6 -4
  80. package/docs/en/guides/get-started/ai-coding-agents.mdx +6 -6
  81. package/docs/en/guides/get-started/introduction.mdx +0 -1
  82. package/docs/en/guides/topic-detail/module-federation/deploy.mdx +2 -2
  83. package/docs/en/guides/topic-detail/module-federation/introduce.mdx +0 -1
  84. package/docs/en/guides/upgrade/config.mdx +12 -0
  85. package/docs/en/guides/upgrade/other.mdx +4 -4
  86. package/docs/en/guides/upgrade/tailwindcss.mdx +0 -1
  87. package/docs/en/guides/upgrade/web-server.md +34 -17
  88. package/docs/en/index.md +1 -0
  89. package/docs/en/plugin/cli-plugins/api.mdx +23 -23
  90. package/docs/en/plugin/cli-plugins/life-cycle.mdx +2 -0
  91. package/docs/en/plugin/introduction.mdx +6 -6
  92. package/docs/en/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
  93. package/docs/en/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
  94. package/docs/en/plugin/plugin-system.mdx +19 -26
  95. package/docs/en/plugin/runtime-plugins/life-cycle.mdx +2 -0
  96. package/docs/en/plugin/server-plugins/api.mdx +11 -14
  97. package/docs/en/plugin/server-plugins/life-cycle.mdx +2 -0
  98. package/docs/zh/apis/app/hooks/api/lambda.mdx +1 -1
  99. package/docs/zh/apis/app/hooks/config/html.mdx +1 -0
  100. package/docs/zh/apis/app/hooks/config/mock.mdx +1 -0
  101. package/docs/zh/apis/app/hooks/config/public.mdx +1 -0
  102. package/docs/zh/apis/app/hooks/config/upload.mdx +2 -3
  103. package/docs/zh/apis/app/hooks/modern-config.mdx +1 -0
  104. package/docs/zh/apis/app/hooks/shared.mdx +1 -0
  105. package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +1 -0
  106. package/docs/zh/apis/app/hooks/src/routes.mdx +1 -0
  107. package/docs/zh/apis/app/hooks/src/server.mdx +2 -1
  108. package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +1 -1
  109. package/docs/zh/apis/app/runtime/core/create-root.mdx +4 -1
  110. package/docs/zh/apis/app/runtime/core/render.mdx +6 -3
  111. package/docs/zh/apis/app/runtime/core/runtime-context.mdx +17 -17
  112. package/docs/zh/apis/app/runtime/router/router.mdx +10 -6
  113. package/docs/zh/apis/app/runtime/ssr/no-ssr.mdx +1 -0
  114. package/docs/zh/apis/app/runtime/utility/head.mdx +1 -0
  115. package/docs/zh/apis/app/runtime/utility/loadable.mdx +1 -0
  116. package/docs/zh/community/blog/v3-release-note.mdx +38 -29
  117. package/docs/zh/community/contributing-guide.mdx +16 -34
  118. package/docs/zh/components/default-browserslist.mdx +0 -1
  119. package/docs/zh/components/deploy-command.mdx +1 -1
  120. package/docs/zh/components/deploy.mdx +1 -1
  121. package/docs/zh/components/entry-scan-logic.mdx +1 -1
  122. package/docs/zh/components/init-app.mdx +9 -3
  123. package/docs/zh/components/international/custom-instance-code.mdx +0 -1
  124. package/docs/zh/components/international/install-command.mdx +0 -1
  125. package/docs/zh/components/micro-runtime-config.mdx +12 -9
  126. package/docs/zh/components/nodeVersion.mdx +2 -2
  127. package/docs/zh/components/rsc-deploy-tip.mdx +0 -1
  128. package/docs/zh/components/ssr-monitor.mdx +1 -1
  129. package/docs/zh/configure/app/bff/cross-project.mdx +2 -2
  130. package/docs/zh/configure/app/bff/prefix.mdx +1 -1
  131. package/docs/zh/configure/app/dev/lazy-compilation.mdx +17 -1
  132. package/docs/zh/configure/app/html/crossorigin.mdx +0 -1
  133. package/docs/zh/configure/app/html/favicon.mdx +0 -1
  134. package/docs/zh/configure/app/output/convert-to-rem.mdx +0 -1
  135. package/docs/zh/configure/app/output/css-modules.mdx +1 -5
  136. package/docs/zh/configure/app/output/inline-scripts.mdx +1 -2
  137. package/docs/zh/configure/app/output/inline-styles.mdx +1 -2
  138. package/docs/zh/configure/app/output/source-map.mdx +0 -2
  139. package/docs/zh/configure/app/output/split-route-chunks.mdx +1 -1
  140. package/docs/zh/configure/app/output/ssg.mdx +1 -0
  141. package/docs/zh/configure/app/output/ssgByEntries.mdx +1 -1
  142. package/docs/zh/configure/app/performance/chunk-split.mdx +1 -4
  143. package/docs/zh/configure/app/resolve/dedupe.mdx +0 -1
  144. package/docs/zh/configure/app/runtime/plugins.mdx +6 -4
  145. package/docs/zh/configure/app/server/rsc.mdx +1 -1
  146. package/docs/zh/configure/app/server/ssr.mdx +6 -7
  147. package/docs/zh/configure/app/server/tsconfig-path.mdx +2 -2
  148. package/docs/zh/configure/app/tools/less.mdx +6 -7
  149. package/docs/zh/configure/app/tools/sass.mdx +6 -7
  150. package/docs/zh/configure/app/tools/svgr.mdx +11 -11
  151. package/docs/zh/configure/app/usage.mdx +1 -5
  152. package/docs/zh/guides/advanced-features/bff.mdx +1 -0
  153. package/docs/zh/guides/advanced-features/international/advanced.mdx +1 -1
  154. package/docs/zh/guides/advanced-features/international/api.mdx +28 -27
  155. package/docs/zh/guides/advanced-features/international/best-practices.mdx +15 -15
  156. package/docs/zh/guides/advanced-features/international/configuration.mdx +38 -36
  157. package/docs/zh/guides/advanced-features/international/locale-detection.mdx +37 -28
  158. package/docs/zh/guides/advanced-features/international/resource-loading.mdx +20 -16
  159. package/docs/zh/guides/advanced-features/international/routing.mdx +6 -4
  160. package/docs/zh/guides/advanced-features/international.mdx +9 -9
  161. package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +4 -6
  162. package/docs/zh/guides/advanced-features/server-monitor/metrics.mdx +9 -10
  163. package/docs/zh/guides/advanced-features/source-build.mdx +1 -1
  164. package/docs/zh/guides/advanced-features/web-server.mdx +3 -3
  165. package/docs/zh/guides/basic-features/data/data-fetch.mdx +1 -3
  166. package/docs/zh/guides/basic-features/data/data-write.mdx +25 -31
  167. package/docs/zh/guides/basic-features/debug/mock.mdx +2 -2
  168. package/docs/zh/guides/basic-features/debug/using-storybook.mdx +5 -5
  169. package/docs/zh/guides/basic-features/env-vars.mdx +0 -1
  170. package/docs/zh/guides/basic-features/html.mdx +2 -3
  171. package/docs/zh/guides/basic-features/render/overview.mdx +12 -13
  172. package/docs/zh/guides/basic-features/render/rsc.mdx +16 -9
  173. package/docs/zh/guides/basic-features/render/ssr.mdx +8 -17
  174. package/docs/zh/guides/basic-features/routes/config-routes.mdx +61 -59
  175. package/docs/zh/guides/basic-features/testing/playwright.mdx +15 -10
  176. package/docs/zh/guides/basic-features/testing/rstest.mdx +6 -4
  177. package/docs/zh/guides/get-started/ai-coding-agents.mdx +7 -7
  178. package/docs/zh/guides/topic-detail/module-federation/deploy.mdx +2 -2
  179. package/docs/zh/guides/upgrade/config.mdx +12 -0
  180. package/docs/zh/guides/upgrade/other.md +4 -11
  181. package/docs/zh/guides/upgrade/overview.mdx +1 -4
  182. package/docs/zh/guides/upgrade/tailwindcss.mdx +0 -1
  183. package/docs/zh/guides/upgrade/web-server.md +34 -19
  184. package/docs/zh/index.md +1 -0
  185. package/docs/zh/plugin/cli-plugins/api.mdx +24 -24
  186. package/docs/zh/plugin/cli-plugins/life-cycle.mdx +2 -0
  187. package/docs/zh/plugin/introduction.mdx +6 -6
  188. package/docs/zh/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
  189. package/docs/zh/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
  190. package/docs/zh/plugin/plugin-system.mdx +19 -26
  191. package/docs/zh/plugin/runtime-plugins/life-cycle.mdx +2 -0
  192. package/docs/zh/plugin/server-plugins/api.mdx +11 -14
  193. package/docs/zh/plugin/server-plugins/life-cycle.mdx +2 -0
  194. package/package.json +11 -13
  195. package/{rspress.config.ts → rstack.config.mts} +7 -10
  196. package/src/components/Footer/styles.module.scss +1 -1
  197. package/src/components/SolutionCards/index.module.scss +3 -1
@@ -21,7 +21,10 @@ These two approaches are mutually exclusive in the legacy version. When migratin
21
21
 
22
22
  ```typescript
23
23
  // Legacy - server/index.ts
24
- export const unstableMiddleware: UnstableMiddleware[] = [middleware1, middleware2];
24
+ export const unstableMiddleware: UnstableMiddleware[] = [
25
+ middleware1,
26
+ middleware2,
27
+ ];
25
28
 
26
29
  // New - server/modern.server.ts
27
30
  import { defineServerConfig } from '@modern-js/server-runtime';
@@ -38,13 +41,22 @@ export default defineServerConfig({
38
41
 
39
42
  ```typescript
40
43
  // Legacy
41
- import type { UnstableMiddleware, UnstableMiddlewareContext } from '@modern-js/server-runtime';
42
- const middleware: UnstableMiddleware = async (c: UnstableMiddlewareContext, next) => {
44
+ import type {
45
+ UnstableMiddleware,
46
+ UnstableMiddlewareContext,
47
+ } from '@modern-js/server-runtime';
48
+ const middleware: UnstableMiddleware = async (
49
+ c: UnstableMiddlewareContext,
50
+ next,
51
+ ) => {
43
52
  return c.response.raw('response'); // Will continue rendering even without calling next
44
53
  };
45
54
 
46
55
  // New
47
- import { defineServerConfig, type MiddlewareHandler } from '@modern-js/server-runtime';
56
+ import {
57
+ defineServerConfig,
58
+ type MiddlewareHandler,
59
+ } from '@modern-js/server-runtime';
48
60
  const middleware: MiddlewareHandler = async (c, next) => {
49
61
  await next(); // Must call
50
62
  return c.text('response');
@@ -53,17 +65,17 @@ const middleware: MiddlewareHandler = async (c, next) => {
53
65
 
54
66
  ### Context API Comparison
55
67
 
56
- | Legacy API | New API | Description |
57
- | -------------------- | ---------------------- | ------------- |
58
- | `c.request.cookie` | `getCookie(c, 'key')` | Cookie reading |
59
- | `c.req.cookie()` | `getCookie(c, 'key')` | Hono v4 deprecated |
60
- | `c.request.pathname` | `c.req.path` | Request path |
61
- | `c.request.host` | `c.req.header('Host')` | Request host |
62
- | `c.request.query` | `c.req.query()` | Query parameters |
63
- | `c.request.headers` | `c.req.header()` | Request headers |
64
- | `c.response.status` | `c.status()` | Response status code |
65
- | `c.response.set` | `c.res.headers.set` | Set response headers |
66
- | `c.response.raw` | `c.text` / `c.json` | Response body |
68
+ | Legacy API | New API | Description |
69
+ | -------------------- | ---------------------- | -------------------- |
70
+ | `c.request.cookie` | `getCookie(c, 'key')` | Cookie reading |
71
+ | `c.req.cookie()` | `getCookie(c, 'key')` | Hono v4 deprecated |
72
+ | `c.request.pathname` | `c.req.path` | Request path |
73
+ | `c.request.host` | `c.req.header('Host')` | Request host |
74
+ | `c.request.query` | `c.req.query()` | Query parameters |
75
+ | `c.request.headers` | `c.req.header()` | Request headers |
76
+ | `c.response.status` | `c.status()` | Response status code |
77
+ | `c.response.set` | `c.res.headers.set` | Set response headers |
78
+ | `c.response.raw` | `c.text` / `c.json` | Response body |
67
79
 
68
80
  ## afterRender Hook
69
81
 
@@ -88,7 +100,10 @@ export const afterRender = (ctx, next) => {
88
100
  };
89
101
 
90
102
  // New - server/modern.server.ts
91
- import { defineServerConfig, type MiddlewareHandler } from '@modern-js/server-runtime';
103
+ import {
104
+ defineServerConfig,
105
+ type MiddlewareHandler,
106
+ } from '@modern-js/server-runtime';
92
107
 
93
108
  const renderMiddleware: MiddlewareHandler = async (c, next) => {
94
109
  await next(); // Wait for page rendering first
@@ -104,6 +119,8 @@ const renderMiddleware: MiddlewareHandler = async (c, next) => {
104
119
  };
105
120
 
106
121
  export default defineServerConfig({
107
- renderMiddlewares: [{ name: 'custom-content-injection', handler: renderMiddleware }],
122
+ renderMiddlewares: [
123
+ { name: 'custom-content-injection', handler: renderMiddleware },
124
+ ],
108
125
  });
109
126
  ```
package/docs/en/index.md CHANGED
@@ -1,4 +1,5 @@
1
1
  ---
2
2
  pageType: home
3
3
  ---
4
+
4
5
  # Modern.js - A Progressive React Framework for modern web development
@@ -39,29 +39,29 @@ Gets the context information of the Modern.js application.
39
39
 
40
40
  - **Returns:** An `AppContext` object containing the following fields:
41
41
 
42
- | Field Name | Type | Description | When Available |
43
- | ---------------------- | ------------------- | ---------------------------------------------------------------- | ---------------------------- |
44
- | `command` | `string` | The currently executing command (e.g., `dev`, `build`, `deploy`) | - |
45
- | `port` | `number` | The development server port number | After `onPrepare` |
46
- | `configFile` | `string` | The absolute path to the configuration file | - |
47
- | `isProd` | `boolean` | Whether it is in production mode | - |
48
- | `appDirectory` | `string` | The absolute path to the project root directory | - |
49
- | `srcDirectory` | `string` | The absolute path to the project source code directory | - |
50
- | `distDirectory` | `string` | The absolute path to the project output directory | In `onPrepare` (and later) |
51
- | `sharedDirectory` | `string` | The absolute path to the shared modules directory | - |
52
- | `nodeModulesDirectory` | `string` | The absolute path to the `node_modules` directory | - |
53
- | `ip` | `string` | The IPv4 address of the current machine | - |
54
- | `packageName` | `string` | The `name` field in the project's `package.json` | - |
55
- | `plugins` | `object[]` | The list of currently registered plugins | - |
56
- | `entrypoints` | `object[]` | Information about page entry points | - |
57
- | `serverRoutes` | `object[]` | Server-side routing information | - |
58
- | `bundlerType` | `webpack \| rspack` | The type of bundler currently in use (`webpack` or `rspack`) | After `onPrepare` |
59
- | `metaName` | `string` | The internal name of the framework | - |
60
- | `apiDirectory` | `string` | The absolute path to the API module directory (used by BFF) | - |
61
- | `lambdaDirectory` | `string` | The absolute path to the Lambda module directory (used by BFF) | - |
62
- | `runtimeConfigFile` | `string` | The name of the runtime configuration file | - |
63
- | `checkedEntries` | `string[]` | Specified entry information | - |
64
- | `apiOnly` | `boolean` | Whether it is in `apiOnly` mode | - |
42
+ | Field Name | Type | Description | When Available |
43
+ | ---------------------- | ------------------- | ---------------------------------------------------------------- | -------------------------- |
44
+ | `command` | `string` | The currently executing command (e.g., `dev`, `build`, `deploy`) | - |
45
+ | `port` | `number` | The development server port number | After `onPrepare` |
46
+ | `configFile` | `string` | The absolute path to the configuration file | - |
47
+ | `isProd` | `boolean` | Whether it is in production mode | - |
48
+ | `appDirectory` | `string` | The absolute path to the project root directory | - |
49
+ | `srcDirectory` | `string` | The absolute path to the project source code directory | - |
50
+ | `distDirectory` | `string` | The absolute path to the project output directory | In `onPrepare` (and later) |
51
+ | `sharedDirectory` | `string` | The absolute path to the shared modules directory | - |
52
+ | `nodeModulesDirectory` | `string` | The absolute path to the `node_modules` directory | - |
53
+ | `ip` | `string` | The IPv4 address of the current machine | - |
54
+ | `packageName` | `string` | The `name` field in the project's `package.json` | - |
55
+ | `plugins` | `object[]` | The list of currently registered plugins | - |
56
+ | `entrypoints` | `object[]` | Information about page entry points | - |
57
+ | `serverRoutes` | `object[]` | Server-side routing information | - |
58
+ | `bundlerType` | `webpack \| rspack` | The type of bundler currently in use (`webpack` or `rspack`) | After `onPrepare` |
59
+ | `metaName` | `string` | The internal name of the framework | - |
60
+ | `apiDirectory` | `string` | The absolute path to the API module directory (used by BFF) | - |
61
+ | `lambdaDirectory` | `string` | The absolute path to the Lambda module directory (used by BFF) | - |
62
+ | `runtimeConfigFile` | `string` | The name of the runtime configuration file | - |
63
+ | `checkedEntries` | `string[]` | Specified entry information | - |
64
+ | `apiOnly` | `boolean` | Whether it is in `apiOnly` mode | - |
65
65
 
66
66
  - **Example:**
67
67
 
@@ -131,5 +131,7 @@ flowchart TD
131
131
  style spacer7 fill:none,stroke:none,height:0px;
132
132
  style spacer8 fill:none,stroke:none,height:0px;
133
133
  style spacer9 fill:none,stroke:none,height:0px;
134
+
134
135
  `}
136
+
135
137
  </Mermaid>
@@ -126,12 +126,12 @@ You can read [Rsbuild Official Website - Plugins](https://v2.rsbuild.rs/plugins/
126
126
 
127
127
  The following are official Rsbuild plugins that are already built into Modern.js. They can be enabled without installation:
128
128
 
129
- | Plugin | Description | Modern.js Link |
130
- | -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
131
- | [React Plugin](https://v2.rsbuild.rs/plugins/list/plugin-react) | Provides support for React | - |
132
- | [SVGR Plugin](https://v2.rsbuild.rs/plugins/list/plugin-svgr) | Supports converting SVG images into React components | [tools.svgr](/configure/app/tools/svgr) |
133
- | [Assets Retry Plugin](https://github.com/rstackjs/rsbuild-plugin-assets-retry) | Automatically retries requests when static asset loading fails | [output.assetsRetry](/configure/app/output/assets-retry.html) |
134
- | [Type Check Plugin](https://github.com/rstackjs/rsbuild-plugin-type-check) | Runs TypeScript type checking in a separate process | [output.disableTsChecker](/configure/app/output/disable-ts-checker.html)<br />[tools.tsChecker](/configure/app/tools/ts-checker.html) |
129
+ | Plugin | Description | Modern.js Link |
130
+ | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
131
+ | [React Plugin](https://v2.rsbuild.rs/plugins/list/plugin-react) | Provides support for React | - |
132
+ | [SVGR Plugin](https://v2.rsbuild.rs/plugins/list/plugin-svgr) | Supports converting SVG images into React components | [tools.svgr](/configure/app/tools/svgr) |
133
+ | [Assets Retry Plugin](https://github.com/rstackjs/rsbuild-plugin-assets-retry) | Automatically retries requests when static asset loading fails | [output.assetsRetry](/configure/app/output/assets-retry.html) |
134
+ | [Type Check Plugin](https://github.com/rstackjs/rsbuild-plugin-type-check) | Runs TypeScript type checking in a separate process | [output.disableTsChecker](/configure/app/output/disable-ts-checker.html)<br />[tools.tsChecker](/configure/app/tools/ts-checker.html) |
135
135
  | [Source Build Plugin](https://github.com/rstackjs/rsbuild-plugin-source-build) | For monorepo scenarios, supports referencing source code from other subdirectories and completing builds and hot updates | [experiments.sourceBuild](/configure/app/experiments/source-build.html) |
136
136
  | [Check Syntax Plugin](https://github.com/rstackjs/rsbuild-plugin-check-syntax) | Analyzes the syntax compatibility of the build artifacts to determine if there are any advanced syntax features that cause compatibility issues | [security.checkSyntax](/configure/app/security/check-syntax.html) |
137
137
  | [CSS Minimizer Plugin](https://github.com/rstackjs/rsbuild-plugin-css-minimizer) | Used to customize the CSS compression tool, switch to [cssnano](https://cssnano.co/) or other tools for CSS compression | [tools.minifyCss](/configure/app/tools/minify-css.html) |
@@ -2,4 +2,4 @@
2
2
 
3
3
  In a Modern.js application, developers can define API files under the `api/lambda` directory and export API functions using the BFF plugin. In the frontend code, these API functions can be directly invoked by importing the file, which initiates the API requests.
4
4
 
5
- For more details, refer to [BFF - Basic Usage](/guides/advanced-features/bff/function).
5
+ For more details, refer to [BFF - Basic Usage](/guides/advanced-features/bff/function).
@@ -2,4 +2,4 @@
2
2
 
3
3
  SSG (Static Site Generation) is a technical solution that renders complete static web pages at build time based on data and templates. This means that in a production environment, pages are populated with content by default and can be cached by a CDN. For pages that do not require dynamic data, SSG can provide better performance and higher security.
4
4
 
5
- For more details, refer to [Static Site Generation (SSG)](/guides/basic-features/render/ssg).
5
+ For more details, refer to [Static Site Generation (SSG)](/guides/basic-features/render/ssg).
@@ -16,31 +16,26 @@ Modern.js adheres to the design philosophy of "everything is a plugin," modulari
16
16
  Modern.js provides three main plugin types, corresponding to different stages of application development:
17
17
 
18
18
  **CLI Plugins:**
19
- - **Active Stage:** Build time (when executing the `modern` command).
20
- - **Typical Scenarios:**
21
- - Extending command-line tools.
22
- - Modifying build configurations.
23
- - Listening for file changes.
24
- - Controlling the build process.
25
- - **Configuration Method:** The `plugins` field in `modern.config.ts`.
19
+
20
+ - **Active Stage:** Build time (when executing the `modern` command).
21
+ - **Typical Scenarios:**
22
+ - Extending command-line tools.
23
+ - Modifying build configurations.
24
+ - Listening for file changes.
25
+ - Controlling the build process.
26
+ - **Configuration Method:** The `plugins` field in `modern.config.ts`.
26
27
 
27
28
  **Runtime Plugins:**
28
- - **Active Stage:** Application runtime (browser/Node.js environment).
29
- - **Typical Scenarios:**
30
- - Initializing global state or services.
31
- - Encapsulating React Higher-Order Components (HOCs).
32
- - Intercepting or modifying routing behavior.
33
- - Controlling the rendering process.
34
- - **Configuration Method:** The `plugins` field in `src/modern.runtime.ts`.
35
-
36
- {/* **Server Plugins:**
37
- - **Active Stage:** Server request processing stage.
38
- - **Typical Scenarios:**
39
- - Adding custom middleware.
40
- - Extending server-side APIs.
41
- - Customizing SSR logic.
42
- - Integrating with backend frameworks.
43
- - **Configuration Method:** The `plugins` field in `server/modern.server.ts`. */}
29
+
30
+ - **Active Stage:** Application runtime (browser/Node.js environment).
31
+ - **Typical Scenarios:**
32
+ - Initializing global state or services.
33
+ - Encapsulating React Higher-Order Components (HOCs).
34
+ - Intercepting or modifying routing behavior.
35
+ - Controlling the rendering process.
36
+ - **Configuration Method:** The `plugins` field in `src/modern.runtime.ts`.
37
+
38
+ {/* **Server Plugins:** - **Active Stage:** Server request processing stage. - **Typical Scenarios:** - Adding custom middleware. - Extending server-side APIs. - Customizing SSR logic. - Integrating with backend frameworks. - **Configuration Method:** The `plugins` field in `server/modern.server.ts`. */}
44
39
 
45
40
  ## Plugin Structure
46
41
 
@@ -196,9 +191,7 @@ Example:
196
191
  // Define Hooks
197
192
  import { createSyncHook } from '@modern-js/plugin';
198
193
 
199
- type RouteObject = {
200
- /** TODO **/
201
- };
194
+ type RouteObject = {/** TODO **/};
202
195
  const modifyRoutes = createSyncHook<(routes: RouteObject[]) => RouteObject[]>();
203
196
 
204
197
  // Register Hooks in the plugin
@@ -25,5 +25,7 @@ flowchart TD
25
25
  style registry_hooks stroke-dasharray:5 5,fill:#9CA3AF,font-size:10px;
26
26
  style wrapRoot font-size:10px;
27
27
  style onBeforeRender font-size:10px;
28
+
28
29
  `}
30
+
29
31
  </Mermaid>
@@ -46,17 +46,17 @@ Gets the context information of the Modern.js server.
46
46
 
47
47
  - **Returns:** A `ServerContext` object containing the following fields:
48
48
 
49
- | Field Name | Type | Description |
50
- | ------------------- | ----------------- | ------------------------------------- |
51
- | `middlewares` | `MiddlewareObj[]` | Middleware list |
52
- | `renderMiddlewares` | `MiddlewareObj[]` | Render middleware list |
53
- | `routes` | `ServerRoute[]` | Server routing information |
54
- | `appDirectory` | `string` | Absolute path to the project root |
55
- | `apiDirectory` | `string` | Absolute path to the API module dir |
56
- | `lambdaDirectory` | `string` | Absolute path to the Lambda module dir|
57
- | `sharedDirectory` | `string` | Absolute path to the shared module dir|
58
- | `distDirectory` | `string` | Absolute path to the output directory|
59
- | `plugins` | `ServerPlugin[]` | List of currently registered plugins |
49
+ | Field Name | Type | Description |
50
+ | ------------------- | ----------------- | -------------------------------------- |
51
+ | `middlewares` | `MiddlewareObj[]` | Middleware list |
52
+ | `renderMiddlewares` | `MiddlewareObj[]` | Render middleware list |
53
+ | `routes` | `ServerRoute[]` | Server routing information |
54
+ | `appDirectory` | `string` | Absolute path to the project root |
55
+ | `apiDirectory` | `string` | Absolute path to the API module dir |
56
+ | `lambdaDirectory` | `string` | Absolute path to the Lambda module dir |
57
+ | `sharedDirectory` | `string` | Absolute path to the shared module dir |
58
+ | `distDirectory` | `string` | Absolute path to the output directory |
59
+ | `plugins` | `ServerPlugin[]` | List of currently registered plugins |
60
60
 
61
61
  - **Example:**
62
62
 
@@ -111,7 +111,6 @@ In custom plugins, you can only manually call the hooks registered by the corres
111
111
 
112
112
  ---
113
113
 
114
-
115
114
  ## Context Modification
116
115
 
117
116
  #### `api.updateServerContext`
@@ -143,7 +142,6 @@ api.onPrepare(() => {
143
142
 
144
143
  ---
145
144
 
146
-
147
145
  ## Lifecycle Hooks
148
146
 
149
147
  #### `api.onPrepare`
@@ -205,7 +203,6 @@ api.onReset(async ({ event }) => {
205
203
 
206
204
  ---
207
205
 
208
-
209
206
  ## Other Notes
210
207
 
211
208
  - Refer to [Server Plugin Lifecycle](./life-cycle.mdx) to understand the execution order of plugin hooks.
@@ -28,7 +28,9 @@ flowchart TD
28
28
  style modifyConfig font-size:10px;
29
29
  style onPrepare font-size:10px;
30
30
  style apply_middlewares font-size:10px;
31
+
31
32
  `}
33
+
32
34
  </Mermaid>
33
35
 
34
36
  :::info
@@ -3,7 +3,7 @@ title: lambda/*.ts
3
3
  sidebar_position: 3
4
4
  ---
5
5
 
6
- # lambda/*.ts
6
+ # lambda/\*.ts
7
7
 
8
8
  开启 BFF 后,`lambda/` 目录下的文件会按照约定被注册为 BFF 的路由。
9
9
 
@@ -2,6 +2,7 @@
2
2
  title: html/
3
3
  sidebar_position: 1
4
4
  ---
5
+
5
6
  # html/
6
7
 
7
8
  通过 `config/html` 目录可以在内部默认 html 模板的不同位置注入自定义的 html 片段。
@@ -2,6 +2,7 @@
2
2
  title: mock/
3
3
  sidebar_position: 5
4
4
  ---
5
+
5
6
  # mock/
6
7
 
7
8
  当项目目录下存在 `config/mock/index.ts` 或 `config/mock/index.js` 时,Modern.js
@@ -2,6 +2,7 @@
2
2
  title: public/
3
3
  sidebar_position: 3
4
4
  ---
5
+
5
6
  # public/
6
7
 
7
8
  `public/` 目录中可以放置任意格式的静态资源文件,文件会被服务端部署到对应的应用域名下。
@@ -2,6 +2,7 @@
2
2
  title: upload/
3
3
  sidebar_position: 4
4
4
  ---
5
+
5
6
  # upload/
6
7
 
7
8
  `upload/` 目录中可以放置任意格式的静态资源文件。
@@ -30,9 +31,7 @@ sidebar_position: 4
30
31
 
31
32
  ```tsx
32
33
  export default () => {
33
- return (
34
- <img src={`${process.env.ASSET_PREFIX}/upload/banner.png`}></img>
35
- );
34
+ return <img src={`${process.env.ASSET_PREFIX}/upload/banner.png`}></img>;
36
35
  };
37
36
  ```
38
37
 
@@ -2,6 +2,7 @@
2
2
  title: modern.config.ts
3
3
  sidebar_position: 8
4
4
  ---
5
+
5
6
  # modern.config.ts
6
7
 
7
8
  Modern.js 配置文件, 通过该文件可以对当前项目的各个方面进行个性化配置。
@@ -2,6 +2,7 @@
2
2
  title: shared/
3
3
  sidebar_position: 5
4
4
  ---
5
+
5
6
  # shared/
6
7
 
7
8
  共享源码目录。当项目在 `api/`、`server/`、`src/` 下有公共代码时,可将这些代码放到 `shared` 目录下,而不是直接引用。
@@ -2,6 +2,7 @@
2
2
  title: modern.runtime.ts
3
3
  sidebar_position: 4
4
4
  ---
5
+
5
6
  # modern.runtime.ts
6
7
 
7
8
  Modern.js Runtime 配置文件, 通过该文件可以对当前项目的 Runtime 能力进行个性化配置。
@@ -2,6 +2,7 @@
2
2
  title: routes/
3
3
  sidebar_position: 2
4
4
  ---
5
+
5
6
  # routes/
6
7
 
7
8
  应用使用 [约定式路由](/guides/basic-features/routes/routes#约定式路由) 时的入口标识。
@@ -2,6 +2,7 @@
2
2
  title: '*.[server|node].tsx'
3
3
  sidebar_position: 8
4
4
  ---
5
- # *.[server|node].tsx
5
+
6
+ # \*.[server|node].tsx
6
7
 
7
8
  应用项目中使用,用于放置服务端代码,当 `*.tsx` 和 `*.[server|node].tsx` 共存时,SSR 在服务端执行渲染时,会优先使用 `*.[server|node].tsx` 文件,而不是 `*.tsx` 文件。
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  title: useHonoContext
3
3
  ---
4
+
4
5
  # useHonoContext
5
6
 
6
7
  用于在一体化 BFF 函数中获取 Hono 上下文。
7
8
 
8
-
9
9
  ## 使用姿势
10
10
 
11
11
  ```ts
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  title: createRoot
3
3
  ---
4
+
4
5
  # createRoot
5
6
 
6
7
  用于创建 Modern.js 提供的根组件,该根组件会自动注册 Runtime 插件,并完成 Runtime 插件初始化。
@@ -14,7 +15,9 @@ import { createRoot } from '@modern-js/runtime/react';
14
15
  ## 函数签名
15
16
 
16
17
  ```ts
17
- export function createRoot(UserApp?: React.ComponentType | null): React.ComponentType<any>;
18
+ export function createRoot(
19
+ UserApp?: React.ComponentType | null,
20
+ ): React.ComponentType<any>;
18
21
  ```
19
22
 
20
23
  ### 参数
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  title: render
3
3
  ---
4
+
4
5
  # render
5
6
 
6
7
  用于渲染项目组件。
@@ -16,7 +17,10 @@ render(<ModernRoot />);
16
17
  ## 函数签名
17
18
 
18
19
  ```ts
19
- export function render(App: React.ReactElement, id?: HTMLElement | string): Promise<any>;
20
+ export function render(
21
+ App: React.ReactElement,
22
+ id?: HTMLElement | string,
23
+ ): Promise<any>;
20
24
  ```
21
25
 
22
26
  ### 参数
@@ -33,11 +37,10 @@ import { render } from '@modern-js/runtime/browser';
33
37
  const ModernRoot = createRoot();
34
38
 
35
39
  async function beforeRender() {
36
- // todo
40
+ // todo
37
41
  }
38
42
 
39
43
  beforeRender().then(() => {
40
44
  render(<ModernRoot />);
41
45
  });
42
46
  ```
43
-
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  title: RuntimeContext
3
3
  ---
4
+
4
5
  # RuntimeContext
5
6
 
6
7
  `RuntimeContext` 是一个 React Context,用于在组件中获取 Runtime 上下文信息。该 Context 可以通过 React 的 `use` 或 `useContext` API 访问。
@@ -19,7 +20,7 @@ import { RuntimeContext } from '@modern-js/runtime';
19
20
 
20
21
  export function App() {
21
22
  const runtimeContext = use(RuntimeContext); // 也可以使用 useContext(RuntimeContext)
22
- return <div>Hello World</div>
23
+ return <div>Hello World</div>;
23
24
  }
24
25
  ```
25
26
 
@@ -53,21 +54,21 @@ type TRuntimeContext = {
53
54
  ```ts
54
55
  type RequestContext = {
55
56
  request: {
56
- params: Record<string, string>; // 路由参数
57
- pathname: string; // 路径名
58
- query: Record<string, string>; // 查询参数
59
- headers: IncomingHttpHeaders; // 请求头
60
- host: string; // 主机名
61
- url: string; // 完整 URL
62
- referer?: string; // 来源页面
63
- userAgent?: string; // 用户代理
64
- cookie?: string; // Cookie 字符串
65
- cookieMap?: Record<string, string>; // Cookie 映射对象
57
+ params: Record<string, string>; // 路由参数
58
+ pathname: string; // 路径名
59
+ query: Record<string, string>; // 查询参数
60
+ headers: IncomingHttpHeaders; // 请求头
61
+ host: string; // 主机名
62
+ url: string; // 完整 URL
63
+ referer?: string; // 来源页面
64
+ userAgent?: string; // 用户代理
65
+ cookie?: string; // Cookie 字符串
66
+ cookieMap?: Record<string, string>; // Cookie 映射对象
66
67
  };
67
68
  response: {
68
- setHeader: (key: string, value: string) => void; // 设置响应头(仅服务端)
69
- status: (code: number) => void; // 设置状态码(仅服务端)
70
- locals: Record<string, any>; // 本地数据
69
+ setHeader: (key: string, value: string) => void; // 设置响应头(仅服务端)
70
+ status: (code: number) => void; // 设置状态码(仅服务端)
71
+ locals: Record<string, any>; // 本地数据
71
72
  };
72
73
  };
73
74
  ```
@@ -91,11 +92,11 @@ function App() {
91
92
 
92
93
  if (isBrowser === true) {
93
94
  // 浏览器端执行逻辑
94
- console.log('browser render')
95
+ console.log('browser render');
95
96
  } else {
96
97
  // 服务器端执行逻辑
97
98
  // 注意:logger 等功能需要通过 Runtime 插件注入到 context 中
98
- console.log('server render')
99
+ console.log('server render');
99
100
  }
100
101
  }
101
102
  ```
@@ -157,4 +158,3 @@ export default function MyComponent() {
157
158
  return <div>{message}</div>;
158
159
  }
159
160
  ```
160
-
@@ -2,6 +2,7 @@
2
2
  title: router
3
3
  sidebar_position: 1
4
4
  ---
5
+
5
6
  # router
6
7
 
7
8
  :::info 补充信息
@@ -135,8 +136,10 @@ export default ErrorBoundary;
135
136
  ```ts
136
137
  declare function Link(props: LinkProps): React.ReactElement;
137
138
 
138
- interface LinkProps
139
- extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> {
139
+ interface LinkProps extends Omit<
140
+ React.AnchorHTMLAttributes<HTMLAnchorElement>,
141
+ 'href'
142
+ > {
140
143
  replace?: boolean;
141
144
  state?: any;
142
145
  to: To;
@@ -157,12 +160,13 @@ type To = string | Partial<Path>;
157
160
  ```ts
158
161
  declare function NavLink(props: NavLinkProps): React.ReactElement;
159
162
 
160
- interface NavLinkProps
161
- extends Omit<LinkProps, 'className' | 'style' | 'children'> {
163
+ interface NavLinkProps extends Omit<
164
+ LinkProps,
165
+ 'className' | 'style' | 'children'
166
+ > {
162
167
  caseSensitive?: boolean;
163
168
  children?:
164
- | React.ReactNode
165
- | ((props: { isActive: boolean }) => React.ReactNode);
169
+ React.ReactNode | ((props: { isActive: boolean }) => React.ReactNode);
166
170
  className?: string | ((props: { isActive: boolean }) => string | undefined);
167
171
  end?: boolean;
168
172
  style?:
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  title: NoSSR
3
3
  ---
4
+
4
5
  # NoSSR
5
6
 
6
7
  被 NoSSR 包裹的内容在服务端不会进行渲染,在客户端 hydrate 阶段也不会渲染,等到整个 App 渲染完成后便会立即渲染。
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  title: Head
3
3
  ---
4
+
4
5
  # Head
5
6
 
6
7
  用于给 `<head>` 元素内添加 html 元素(如 title、meta、script 等),支持 `SSR`。