@modern-js/main-doc 3.9.2 → 3.10.0

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 (203) 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/disable-svgr.mdx +4 -0
  37. package/docs/en/configure/app/output/dist-path.mdx +0 -1
  38. package/docs/en/configure/app/output/inline-scripts.mdx +1 -2
  39. package/docs/en/configure/app/output/inline-styles.mdx +1 -2
  40. package/docs/en/configure/app/output/split-route-chunks.mdx +1 -1
  41. package/docs/en/configure/app/output/ssg.mdx +1 -1
  42. package/docs/en/configure/app/output/ssgByEntries.mdx +1 -0
  43. package/docs/en/configure/app/output/svg-default-export.mdx +4 -0
  44. package/docs/en/configure/app/performance/chunk-split.mdx +1 -4
  45. package/docs/en/configure/app/runtime/plugins.mdx +6 -4
  46. package/docs/en/configure/app/server/rsc.mdx +1 -1
  47. package/docs/en/configure/app/server/ssr.mdx +7 -8
  48. package/docs/en/configure/app/server/tsconfig-path.mdx +2 -2
  49. package/docs/en/configure/app/tools/less.mdx +94 -19
  50. package/docs/en/configure/app/tools/sass.mdx +87 -18
  51. package/docs/en/configure/app/tools/svgr.mdx +93 -0
  52. package/docs/en/configure/app/usage.mdx +1 -5
  53. package/docs/en/guides/advanced-features/bff/cross-project.mdx +5 -4
  54. package/docs/en/guides/advanced-features/compatibility.mdx +0 -1
  55. package/docs/en/guides/advanced-features/international/advanced.mdx +1 -1
  56. package/docs/en/guides/advanced-features/international/api.mdx +34 -28
  57. package/docs/en/guides/advanced-features/international/best-practices.mdx +15 -15
  58. package/docs/en/guides/advanced-features/international/configuration.mdx +37 -37
  59. package/docs/en/guides/advanced-features/international/locale-detection.mdx +37 -28
  60. package/docs/en/guides/advanced-features/international/resource-loading.mdx +19 -17
  61. package/docs/en/guides/advanced-features/international/routing.mdx +8 -6
  62. package/docs/en/guides/advanced-features/international.mdx +8 -8
  63. package/docs/en/guides/advanced-features/server-monitor/logger.mdx +5 -5
  64. package/docs/en/guides/advanced-features/server-monitor/metrics.mdx +8 -8
  65. package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +1 -3
  66. package/docs/en/guides/advanced-features/source-build.mdx +1 -1
  67. package/docs/en/guides/advanced-features/web-server.mdx +3 -3
  68. package/docs/en/guides/basic-features/data/data-fetch.mdx +1 -3
  69. package/docs/en/guides/basic-features/data/data-write.mdx +24 -28
  70. package/docs/en/guides/basic-features/debug/mock.mdx +2 -2
  71. package/docs/en/guides/basic-features/debug/using-storybook.mdx +5 -6
  72. package/docs/en/guides/basic-features/html.mdx +2 -3
  73. package/docs/en/guides/basic-features/output-files.mdx +1 -1
  74. package/docs/en/guides/basic-features/render/overview.mdx +12 -12
  75. package/docs/en/guides/basic-features/render/rsc.mdx +16 -9
  76. package/docs/en/guides/basic-features/render/ssr-cache.mdx +5 -5
  77. package/docs/en/guides/basic-features/render/ssr.mdx +8 -12
  78. package/docs/en/guides/basic-features/render/streaming-ssr.mdx +2 -1
  79. package/docs/en/guides/basic-features/routes/config-routes.mdx +60 -59
  80. package/docs/en/guides/basic-features/static-assets/svg-assets.mdx +29 -17
  81. package/docs/en/guides/basic-features/testing/playwright.mdx +14 -8
  82. package/docs/en/guides/basic-features/testing/rstest.mdx +6 -4
  83. package/docs/en/guides/get-started/ai-coding-agents.mdx +6 -6
  84. package/docs/en/guides/get-started/introduction.mdx +0 -1
  85. package/docs/en/guides/topic-detail/module-federation/deploy.mdx +2 -2
  86. package/docs/en/guides/topic-detail/module-federation/introduce.mdx +0 -1
  87. package/docs/en/guides/upgrade/config.mdx +12 -0
  88. package/docs/en/guides/upgrade/other.mdx +4 -4
  89. package/docs/en/guides/upgrade/tailwindcss.mdx +0 -1
  90. package/docs/en/guides/upgrade/web-server.md +34 -17
  91. package/docs/en/index.md +1 -0
  92. package/docs/en/plugin/cli-plugins/api.mdx +23 -23
  93. package/docs/en/plugin/cli-plugins/life-cycle.mdx +2 -0
  94. package/docs/en/plugin/introduction.mdx +6 -6
  95. package/docs/en/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
  96. package/docs/en/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
  97. package/docs/en/plugin/plugin-system.mdx +19 -26
  98. package/docs/en/plugin/runtime-plugins/life-cycle.mdx +2 -0
  99. package/docs/en/plugin/server-plugins/api.mdx +11 -14
  100. package/docs/en/plugin/server-plugins/life-cycle.mdx +2 -0
  101. package/docs/zh/apis/app/hooks/api/lambda.mdx +1 -1
  102. package/docs/zh/apis/app/hooks/config/html.mdx +1 -0
  103. package/docs/zh/apis/app/hooks/config/mock.mdx +1 -0
  104. package/docs/zh/apis/app/hooks/config/public.mdx +1 -0
  105. package/docs/zh/apis/app/hooks/config/upload.mdx +2 -3
  106. package/docs/zh/apis/app/hooks/modern-config.mdx +1 -0
  107. package/docs/zh/apis/app/hooks/shared.mdx +1 -0
  108. package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +1 -0
  109. package/docs/zh/apis/app/hooks/src/routes.mdx +1 -0
  110. package/docs/zh/apis/app/hooks/src/server.mdx +2 -1
  111. package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +1 -1
  112. package/docs/zh/apis/app/runtime/core/create-root.mdx +4 -1
  113. package/docs/zh/apis/app/runtime/core/render.mdx +6 -3
  114. package/docs/zh/apis/app/runtime/core/runtime-context.mdx +17 -17
  115. package/docs/zh/apis/app/runtime/router/router.mdx +10 -6
  116. package/docs/zh/apis/app/runtime/ssr/no-ssr.mdx +1 -0
  117. package/docs/zh/apis/app/runtime/utility/head.mdx +1 -0
  118. package/docs/zh/apis/app/runtime/utility/loadable.mdx +1 -0
  119. package/docs/zh/community/blog/v3-release-note.mdx +38 -29
  120. package/docs/zh/community/contributing-guide.mdx +16 -34
  121. package/docs/zh/components/default-browserslist.mdx +0 -1
  122. package/docs/zh/components/deploy-command.mdx +1 -1
  123. package/docs/zh/components/deploy.mdx +1 -1
  124. package/docs/zh/components/entry-scan-logic.mdx +1 -1
  125. package/docs/zh/components/init-app.mdx +9 -3
  126. package/docs/zh/components/international/custom-instance-code.mdx +0 -1
  127. package/docs/zh/components/international/install-command.mdx +0 -1
  128. package/docs/zh/components/micro-runtime-config.mdx +12 -9
  129. package/docs/zh/components/nodeVersion.mdx +2 -2
  130. package/docs/zh/components/rsc-deploy-tip.mdx +0 -1
  131. package/docs/zh/components/ssr-monitor.mdx +1 -1
  132. package/docs/zh/configure/app/bff/cross-project.mdx +2 -2
  133. package/docs/zh/configure/app/bff/prefix.mdx +1 -1
  134. package/docs/zh/configure/app/dev/lazy-compilation.mdx +17 -1
  135. package/docs/zh/configure/app/html/crossorigin.mdx +0 -1
  136. package/docs/zh/configure/app/html/favicon.mdx +0 -1
  137. package/docs/zh/configure/app/output/convert-to-rem.mdx +0 -1
  138. package/docs/zh/configure/app/output/css-modules.mdx +1 -5
  139. package/docs/zh/configure/app/output/disable-svgr.mdx +4 -0
  140. package/docs/zh/configure/app/output/inline-scripts.mdx +1 -2
  141. package/docs/zh/configure/app/output/inline-styles.mdx +1 -2
  142. package/docs/zh/configure/app/output/source-map.mdx +0 -2
  143. package/docs/zh/configure/app/output/split-route-chunks.mdx +1 -1
  144. package/docs/zh/configure/app/output/ssg.mdx +1 -0
  145. package/docs/zh/configure/app/output/ssgByEntries.mdx +1 -1
  146. package/docs/zh/configure/app/output/svg-default-export.mdx +4 -0
  147. package/docs/zh/configure/app/performance/chunk-split.mdx +1 -4
  148. package/docs/zh/configure/app/resolve/dedupe.mdx +0 -1
  149. package/docs/zh/configure/app/runtime/plugins.mdx +6 -4
  150. package/docs/zh/configure/app/server/rsc.mdx +1 -1
  151. package/docs/zh/configure/app/server/ssr.mdx +6 -7
  152. package/docs/zh/configure/app/server/tsconfig-path.mdx +2 -2
  153. package/docs/zh/configure/app/tools/less.mdx +93 -19
  154. package/docs/zh/configure/app/tools/sass.mdx +87 -16
  155. package/docs/zh/configure/app/tools/svgr.mdx +93 -0
  156. package/docs/zh/configure/app/usage.mdx +1 -5
  157. package/docs/zh/guides/advanced-features/bff.mdx +1 -0
  158. package/docs/zh/guides/advanced-features/international/advanced.mdx +1 -1
  159. package/docs/zh/guides/advanced-features/international/api.mdx +28 -27
  160. package/docs/zh/guides/advanced-features/international/best-practices.mdx +15 -15
  161. package/docs/zh/guides/advanced-features/international/configuration.mdx +38 -36
  162. package/docs/zh/guides/advanced-features/international/locale-detection.mdx +37 -28
  163. package/docs/zh/guides/advanced-features/international/resource-loading.mdx +20 -16
  164. package/docs/zh/guides/advanced-features/international/routing.mdx +6 -4
  165. package/docs/zh/guides/advanced-features/international.mdx +9 -9
  166. package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +4 -6
  167. package/docs/zh/guides/advanced-features/server-monitor/metrics.mdx +9 -10
  168. package/docs/zh/guides/advanced-features/source-build.mdx +1 -1
  169. package/docs/zh/guides/advanced-features/web-server.mdx +3 -3
  170. package/docs/zh/guides/basic-features/data/data-fetch.mdx +1 -3
  171. package/docs/zh/guides/basic-features/data/data-write.mdx +25 -31
  172. package/docs/zh/guides/basic-features/debug/mock.mdx +2 -2
  173. package/docs/zh/guides/basic-features/debug/using-storybook.mdx +5 -5
  174. package/docs/zh/guides/basic-features/env-vars.mdx +0 -1
  175. package/docs/zh/guides/basic-features/html.mdx +2 -3
  176. package/docs/zh/guides/basic-features/render/overview.mdx +12 -13
  177. package/docs/zh/guides/basic-features/render/rsc.mdx +16 -9
  178. package/docs/zh/guides/basic-features/render/ssr.mdx +8 -17
  179. package/docs/zh/guides/basic-features/routes/config-routes.mdx +61 -59
  180. package/docs/zh/guides/basic-features/static-assets/svg-assets.mdx +29 -17
  181. package/docs/zh/guides/basic-features/testing/playwright.mdx +15 -10
  182. package/docs/zh/guides/basic-features/testing/rstest.mdx +6 -4
  183. package/docs/zh/guides/get-started/ai-coding-agents.mdx +7 -7
  184. package/docs/zh/guides/topic-detail/module-federation/deploy.mdx +2 -2
  185. package/docs/zh/guides/upgrade/config.mdx +12 -0
  186. package/docs/zh/guides/upgrade/other.md +4 -11
  187. package/docs/zh/guides/upgrade/overview.mdx +1 -4
  188. package/docs/zh/guides/upgrade/tailwindcss.mdx +0 -1
  189. package/docs/zh/guides/upgrade/web-server.md +34 -19
  190. package/docs/zh/index.md +1 -0
  191. package/docs/zh/plugin/cli-plugins/api.mdx +24 -24
  192. package/docs/zh/plugin/cli-plugins/life-cycle.mdx +2 -0
  193. package/docs/zh/plugin/introduction.mdx +6 -6
  194. package/docs/zh/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
  195. package/docs/zh/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
  196. package/docs/zh/plugin/plugin-system.mdx +19 -26
  197. package/docs/zh/plugin/runtime-plugins/life-cycle.mdx +2 -0
  198. package/docs/zh/plugin/server-plugins/api.mdx +11 -14
  199. package/docs/zh/plugin/server-plugins/life-cycle.mdx +2 -0
  200. package/package.json +11 -13
  201. package/{rspress.config.ts → rstack.config.mts} +7 -10
  202. package/src/components/Footer/styles.module.scss +1 -1
  203. package/src/components/SolutionCards/index.module.scss +3 -1
@@ -1,13 +1,14 @@
1
1
  ---
2
2
  title: 配置说明
3
3
  ---
4
+
4
5
  # 配置说明
5
6
 
6
7
  插件配置分为两个文件,各有职责:
7
8
 
8
- | 文件 | 用途 |
9
- | --- | --- |
10
- | `modern.config.ts` | 插件基础设置,在构建/启动时读取 |
9
+ | 文件 | 用途 |
10
+ | ----------------------- | -------------------------------- |
11
+ | `modern.config.ts` | 插件基础设置,在构建/启动时读取 |
11
12
  | `src/modern.runtime.ts` | i18next 初始化选项,在运行时读取 |
12
13
 
13
14
  :::warning 函数类型只能在运行时配置中设置
@@ -16,13 +17,13 @@ title: 配置说明
16
17
 
17
18
  ## 配置归属一览
18
19
 
19
- | 配置项 | 放在哪里 |
20
- | --- | --- |
21
- | `localeDetection`(语言检测、路径重定向等) | `modern.config.ts` |
22
- | `backend`(资源路径、sdk 声明等) | `modern.config.ts` |
23
- | `i18nInstance` | `modern.runtime.ts` |
20
+ | 配置项 | 放在哪里 |
21
+ | ------------------------------------------------ | ------------------- |
22
+ | `localeDetection`(语言检测、路径重定向等) | `modern.config.ts` |
23
+ | `backend`(资源路径、sdk 声明等) | `modern.config.ts` |
24
+ | `i18nInstance` | `modern.runtime.ts` |
24
25
  | `initOptions`(fallbackLng、ns 等 i18next 选项) | `modern.runtime.ts` |
25
- | `backend.sdk` 的实际加载函数 | `modern.runtime.ts` |
26
+ | `backend.sdk` 的实际加载函数 | `modern.runtime.ts` |
26
27
 
27
28
  ## CLI 配置
28
29
 
@@ -43,15 +44,15 @@ export default defineConfig({
43
44
 
44
45
  ### localeDetection 选项
45
46
 
46
- | 字段 | 类型 | 默认值 | 说明 |
47
- | --- | --- | --- | --- |
48
- | `languages` | `string[]` | `[]` | 支持的语言列表 |
49
- | `fallbackLanguage` | `string` | `''` | 语言检测失败时的兜底语言 |
50
- | `localePathRedirect` | `boolean` | `false` | 接管 URL 语言前缀的识别、重定向和切换,详见[路由集成](./routing.md#启用语言路径前缀) |
51
- | `i18nextDetector` | `boolean` | `false` | 启用 i18next 检测器(Cookie / Header 等) |
52
- | `detection` | `LanguageDetectorOptions` | — | i18next 检测器详细配置,见[语言检测](./locale-detection.md) |
53
- | `ignoreRedirectRoutes` | `string[] \| Function` | — | 跳过重定向的路由,见[语言检测](./locale-detection.md#ignoreredirectroutes) |
54
- | `localeDetectionByEntry` | `Record<string, ...>` | — | 多入口按入口覆盖配置 |
47
+ | 字段 | 类型 | 默认值 | 说明 |
48
+ | ------------------------ | ------------------------- | ------- | ------------------------------------------------------------------------------------ |
49
+ | `languages` | `string[]` | `[]` | 支持的语言列表 |
50
+ | `fallbackLanguage` | `string` | `''` | 语言检测失败时的兜底语言 |
51
+ | `localePathRedirect` | `boolean` | `false` | 接管 URL 语言前缀的识别、重定向和切换,详见[路由集成](./routing.md#启用语言路径前缀) |
52
+ | `i18nextDetector` | `boolean` | `false` | 启用 i18next 检测器(Cookie / Header 等) |
53
+ | `detection` | `LanguageDetectorOptions` | — | i18next 检测器详细配置,见[语言检测](./locale-detection.md) |
54
+ | `ignoreRedirectRoutes` | `string[] \| Function` | — | 跳过重定向的路由,见[语言检测](./locale-detection.md#ignoreredirectroutes) |
55
+ | `localeDetectionByEntry` | `Record<string, ...>` | — | 多入口按入口覆盖配置 |
55
56
 
56
57
  **示例:**
57
58
 
@@ -104,23 +105,24 @@ interface BackendOptions {
104
105
 
105
106
  **backend 自动启用规则:**
106
107
 
107
- | 情况 | 结果 |
108
- | --- | --- |
109
- | 配置了 `loadPath` 或 `addPath` | 自动启用,无需写 `enabled: true` |
110
- | 未配置 backend,但 `locales` 目录存在且有 JSON 文件 | 自动启用,使用默认 `loadPath` |
111
- | 显式设置 `enabled: false` | 禁用,不做自动检测 |
108
+ | 情况 | 结果 |
109
+ | --------------------------------------------------- | -------------------------------- |
110
+ | 配置了 `loadPath` 或 `addPath` | 自动启用,无需写 `enabled: true` |
111
+ | 未配置 backend,但 `locales` 目录存在且有 JSON 文件 | 自动启用,使用默认 `loadPath` |
112
+ | 显式设置 `enabled: false` | 禁用,不做自动检测 |
112
113
 
113
114
  自动检测的目录位置(按优先级):
115
+
114
116
  1. `{项目根目录}/config/public/locales`
115
117
  2. `server.publicDir` 配置的目录下的 `locales` 子目录
116
118
 
117
119
  **选择哪种后端?**
118
120
 
119
- | 场景 | 推荐方式 |
120
- | --- | --- |
121
- | 翻译文件放在项目本地 | 静态文件后端(配置 `loadPath`,CSR/SSR 自动切换) |
122
- | 翻译来自远程 API 或翻译平台 | 自定义后端(配置 `sdk: true`) |
123
- | 本地兜底 + 远程实时更新 | 链式后端(同时配置 `loadPath` 和 `sdk`) |
121
+ | 场景 | 推荐方式 |
122
+ | --------------------------- | ------------------------------------------------- |
123
+ | 翻译文件放在项目本地 | 静态文件后端(配置 `loadPath`,CSR/SSR 自动切换) |
124
+ | 翻译来自远程 API 或翻译平台 | 自定义后端(配置 `sdk: true`) |
125
+ | 本地兜底 + 远程实时更新 | 链式后端(同时配置 `loadPath` 和 `sdk`) |
124
126
 
125
127
  详细用法见[资源加载](./resource-loading.md)。
126
128
 
@@ -134,7 +136,7 @@ const i18nInstance = i18next.createInstance();
134
136
 
135
137
  export default defineRuntimeConfig({
136
138
  i18n: {
137
- i18nInstance, // 可选,建议使用独立实例
139
+ i18nInstance, // 可选,建议使用独立实例
138
140
  initOptions: {
139
141
  fallbackLng: 'en',
140
142
  supportedLngs: ['zh', 'en'],
@@ -162,13 +164,13 @@ import Desc from '@site-docs/components/international/init-options-desc';
162
164
 
163
165
  <Desc />
164
166
 
165
- | 字段 | 说明 |
166
- | --- | --- |
167
- | `fallbackLng` | i18next 找不到翻译键时回退到哪个语言的资源,支持字符串、数组或映射(回退链) |
168
- | `supportedLngs` | i18next 支持的语言列表 |
169
- | `ns` | 命名空间列表,默认 `['translation']` |
170
- | `defaultNS` | 默认命名空间,默认 `'translation'` |
171
- | `lng` | 强制指定初始语言(通常不需要,由检测器决定) |
167
+ | 字段 | 说明 |
168
+ | --------------- | ---------------------------------------------------------------------------- |
169
+ | `fallbackLng` | i18next 找不到翻译键时回退到哪个语言的资源,支持字符串、数组或映射(回退链) |
170
+ | `supportedLngs` | i18next 支持的语言列表 |
171
+ | `ns` | 命名空间列表,默认 `['translation']` |
172
+ | `defaultNS` | 默认命名空间,默认 `'translation'` |
173
+ | `lng` | 强制指定初始语言(通常不需要,由检测器决定) |
172
174
 
173
175
  `fallbackLng` 支持回退链写法,适合区域语言降级的场景:
174
176
 
@@ -64,8 +64,8 @@ i18nPlugin({
64
64
  ```ts
65
65
  i18nPlugin({
66
66
  localeDetection: {
67
- localePathRedirect: true, // 路径前缀
68
- i18nextDetector: true, // Cookie / Header 等
67
+ localePathRedirect: true, // 路径前缀
68
+ i18nextDetector: true, // Cookie / Header 等
69
69
  languages: ['zh', 'en'],
70
70
  fallbackLanguage: 'en',
71
71
  detection: {
@@ -77,39 +77,48 @@ i18nPlugin({
77
77
 
78
78
  ## 检测选项(detection)
79
79
 
80
- | 选项 | 类型 | 默认值 | 说明 |
81
- | --- | --- | --- | --- |
82
- | `order` | `string[]` | 见下方 | i18next 检测器内部的检测顺序 |
83
- | `lookupQuerystring` | `string` | `'lng'` | 查询参数键名,例如 `?lng=en` |
84
- | `lookupCookie` | `string` | `'i18next'` | Cookie 键名 |
85
- | `lookupLocalStorage` | `string` | `'i18nextLng'` | LocalStorage 键名(仅浏览器) |
86
- | `lookupSession` | `string` | — | SessionStorage 键名(仅浏览器) |
87
- | `lookupHeader` | `string` | `'accept-language'` | HTTP 请求头键名 |
88
- | `lookupFromPathIndex` | `number` | `0` | 从 URL 路径的第几段开始识别语言 |
89
- | `caches` | `false \| string[]` | — | 检测到的语言缓存到哪里,如 `['cookie']` |
90
- | `cookieMinutes` | `number` | `525600`(1年) | Cookie 过期时间(分钟) |
91
- | `cookieExpirationDate` | `Date` | — | Cookie 过期日期,优先级高于 `cookieMinutes` |
92
- | `cookieDomain` | `string` | — | Cookie 域名 |
80
+ | 选项 | 类型 | 默认值 | 说明 |
81
+ | ---------------------- | ------------------- | ------------------- | ------------------------------------------- |
82
+ | `order` | `string[]` | 见下方 | i18next 检测器内部的检测顺序 |
83
+ | `lookupQuerystring` | `string` | `'lng'` | 查询参数键名,例如 `?lng=en` |
84
+ | `lookupCookie` | `string` | `'i18next'` | Cookie 键名 |
85
+ | `lookupLocalStorage` | `string` | `'i18nextLng'` | LocalStorage 键名(仅浏览器) |
86
+ | `lookupSession` | `string` | — | SessionStorage 键名(仅浏览器) |
87
+ | `lookupHeader` | `string` | `'accept-language'` | HTTP 请求头键名 |
88
+ | `lookupFromPathIndex` | `number` | `0` | 从 URL 路径的第几段开始识别语言 |
89
+ | `caches` | `false \| string[]` | — | 检测到的语言缓存到哪里,如 `['cookie']` |
90
+ | `cookieMinutes` | `number` | `525600`(1年) | Cookie 过期时间(分钟) |
91
+ | `cookieExpirationDate` | `Date` | — | Cookie 过期日期,优先级高于 `cookieMinutes` |
92
+ | `cookieDomain` | `string` | — | Cookie 域名 |
93
93
 
94
94
  **默认检测顺序(未配置 `order` 时):**
95
95
 
96
96
  ```ts
97
- ['querystring', 'cookie', 'localStorage', 'header', 'navigator', 'htmlTag', 'path', 'subdomain']
97
+ [
98
+ 'querystring',
99
+ 'cookie',
100
+ 'localStorage',
101
+ 'header',
102
+ 'navigator',
103
+ 'htmlTag',
104
+ 'path',
105
+ 'subdomain',
106
+ ];
98
107
  ```
99
108
 
100
109
  **`order` 可用值:**
101
110
 
102
- | 值 | 检测来源 | 限制 |
103
- | --- | --- | --- |
104
- | `querystring` | URL 查询参数(`?lng=en`) | — |
105
- | `cookie` | Cookie | — |
106
- | `localStorage` | LocalStorage | 仅浏览器 |
107
- | `sessionStorage` | SessionStorage | 仅浏览器 |
108
- | `navigator` | 浏览器语言设置 | 仅浏览器 |
109
- | `htmlTag` | `<html lang="...">` | 仅浏览器 |
110
- | `header` | `Accept-Language` 请求头 | — |
111
- | `path` | URL 路径(需同时启用 `localePathRedirect`) | — |
112
- | `subdomain` | 子域名(`en.example.com`) | — |
111
+ | 值 | 检测来源 | 限制 |
112
+ | ---------------- | ------------------------------------------- | -------- |
113
+ | `querystring` | URL 查询参数(`?lng=en`) | — |
114
+ | `cookie` | Cookie | — |
115
+ | `localStorage` | LocalStorage | 仅浏览器 |
116
+ | `sessionStorage` | SessionStorage | 仅浏览器 |
117
+ | `navigator` | 浏览器语言设置 | 仅浏览器 |
118
+ | `htmlTag` | `<html lang="...">` | 仅浏览器 |
119
+ | `header` | `Accept-Language` 请求头 | — |
120
+ | `path` | URL 路径(需同时启用 `localePathRedirect`) | — |
121
+ | `subdomain` | 子域名(`en.example.com`) | — |
113
122
 
114
123
  ## ignoreRedirectRoutes
115
124
 
@@ -118,7 +127,7 @@ i18nPlugin({
118
127
  **写法一:字符串数组**(支持精确匹配和前缀匹配)
119
128
 
120
129
  ```ts
121
- ignoreRedirectRoutes: ['/api', '/admin', '/static']
130
+ ignoreRedirectRoutes: ['/api', '/admin', '/static'];
122
131
  // '/api' 会匹配 /api 和 /api/users
123
132
  ```
124
133
 
@@ -1,21 +1,23 @@
1
1
  ---
2
2
  title: 资源加载
3
3
  ---
4
+
4
5
  # 资源加载
5
6
 
6
7
  翻译文件的加载方式取决于你的翻译资源放在哪里:
7
8
 
8
- | 场景 | 加载方式 |
9
- | --- | --- |
10
- | 翻译文件放在项目本地 | 静态文件后端(本篇默认方式) |
11
- | 翻译来自远程 API、翻译平台 | 自定义后端 |
12
- | 两者都要:本地兜底 + 远程实时更新 | 链式后端 |
9
+ | 场景 | 加载方式 |
10
+ | --------------------------------- | ---------------------------- |
11
+ | 翻译文件放在项目本地 | 静态文件后端(本篇默认方式) |
12
+ | 翻译来自远程 API、翻译平台 | 自定义后端 |
13
+ | 两者都要:本地兜底 + 远程实时更新 | 链式后端 |
13
14
 
14
15
  ## 静态文件后端
15
16
 
16
17
  把翻译文件放在项目里,插件直接加载。这是最常见的方式。
17
18
 
18
19
  **CSR 和 SSR 的加载机制不同,但配置完全一样:**
20
+
19
21
  - CSR:浏览器通过 HTTP 请求拉取翻译文件(如 `GET /locales/zh/translation.json`)
20
22
  - SSR:服务端直接从磁盘读取文件,不走 HTTP
21
23
 
@@ -100,11 +102,11 @@ export default defineRuntimeConfig({
100
102
 
101
103
  ```ts
102
104
  interface I18nSdkLoadOptions {
103
- lng?: string; // 单个语言代码
104
- ns?: string; // 单个命名空间
105
- lngs?: string[]; // 多个语言代码
106
- nss?: string[]; // 多个命名空间
107
- all?: boolean; // 加载所有资源
105
+ lng?: string; // 单个语言代码
106
+ ns?: string; // 单个命名空间
107
+ lngs?: string[]; // 多个语言代码
108
+ nss?: string[]; // 多个命名空间
109
+ all?: boolean; // 加载所有资源
108
110
  }
109
111
  ```
110
112
 
@@ -122,7 +124,7 @@ interface I18nSdkLoadOptions {
122
124
  i18nPlugin({
123
125
  backend: {
124
126
  loadPath: '/locales/{{lng}}/{{ns}}.json', // 本地文件,快速显示
125
- sdk: true, // 远程加载,异步更新
127
+ sdk: true, // 远程加载,异步更新
126
128
  },
127
129
  });
128
130
  ```
@@ -135,7 +137,9 @@ export default defineRuntimeConfig({
135
137
  backend: {
136
138
  sdk: async options => {
137
139
  if (options.lng && options.ns) {
138
- const res = await fetch(`https://api.example.com/i18n/${options.lng}/${options.ns}`);
140
+ const res = await fetch(
141
+ `https://api.example.com/i18n/${options.lng}/${options.ns}`,
142
+ );
139
143
  return { [options.lng]: { [options.ns]: await res.json() } };
140
144
  }
141
145
  return {};
@@ -148,8 +152,8 @@ export default defineRuntimeConfig({
148
152
 
149
153
  **`cacheHitMode` 选项**(控制两个后端之间的协作方式):
150
154
 
151
- | 值 | 行为 |
152
- | --- | --- |
153
- | `'none'` | 本地文件加载成功后直接使用,不再请求自定义后端 |
154
- | `'refresh'` | 继续请求自定义后端并更新缓存,但不更新当前页面 |
155
+ | 值 | 行为 |
156
+ | ------------------------- | ------------------------------------------------------ |
157
+ | `'none'` | 本地文件加载成功后直接使用,不再请求自定义后端 |
158
+ | `'refresh'` | 继续请求自定义后端并更新缓存,但不更新当前页面 |
155
159
  | `'refreshAndUpdateStore'` | 继续请求自定义后端,更新缓存并同步刷新页面文案(默认) |
@@ -26,9 +26,9 @@ i18nPlugin({
26
26
 
27
27
  **效果:**
28
28
 
29
- | 访问路径 | 结果 |
30
- | --- | --- |
31
- | `/about` | 重定向到 `/en/about` |
29
+ | 访问路径 | 结果 |
30
+ | ----------- | --------------------- |
31
+ | `/about` | 重定向到 `/en/about` |
32
32
  | `/en/about` | 正常访问,语言为 `en` |
33
33
  | `/zh/about` | 正常访问,语言为 `zh` |
34
34
 
@@ -108,7 +108,9 @@ function Navigation() {
108
108
  <nav>
109
109
  <I18nLink to="/">首页</I18nLink>
110
110
  <I18nLink to="/about">关于</I18nLink>
111
- <I18nLink to="/contact" replace>联系</I18nLink>
111
+ <I18nLink to="/contact" replace>
112
+ 联系
113
+ </I18nLink>
112
114
  </nav>
113
115
  );
114
116
  }
@@ -10,15 +10,15 @@ import I18nPluginIntroduce from '@site-docs/components/international/introduce';
10
10
 
11
11
  ## 从哪里开始?
12
12
 
13
- | 想做的事 | 文档 |
14
- | --- | --- |
15
- | 首次接入,跑通示例 | [快速开始](./international/quick-start.md) |
16
- | 了解完整的配置选项 | [配置说明](./international/configuration.md) |
17
- | 根据 URL / Cookie / Header 自动判断语言 | [语言检测](./international/locale-detection.md) |
18
- | 实现 `/en/about` 这类带语言前缀的路径 | [路由集成](./international/routing.md) |
19
- | 从远程服务或平台加载翻译资源 | [资源加载 → 自定义后端](./international/resource-loading.md#sdk-后端) |
20
- | SSR 场景、多入口、自定义实例 | [高级用法](./international/advanced.md) |
21
- | 查询 Hook / 组件 / 类型定义 | [API 参考](./international/api.md) |
13
+ | 想做的事 | 文档 |
14
+ | --------------------------------------- | --------------------------------------------------------------------- |
15
+ | 首次接入,跑通示例 | [快速开始](./international/quick-start.md) |
16
+ | 了解完整的配置选项 | [配置说明](./international/configuration.md) |
17
+ | 根据 URL / Cookie / Header 自动判断语言 | [语言检测](./international/locale-detection.md) |
18
+ | 实现 `/en/about` 这类带语言前缀的路径 | [路由集成](./international/routing.md) |
19
+ | 从远程服务或平台加载翻译资源 | [资源加载 → 自定义后端](./international/resource-loading.md#sdk-后端) |
20
+ | SSR 场景、多入口、自定义实例 | [高级用法](./international/advanced.md) |
21
+ | 查询 Hook / 组件 / 类型定义 | [API 参考](./international/api.md) |
22
22
 
23
23
  ## 核心能力
24
24
 
@@ -6,10 +6,10 @@
6
6
 
7
7
  基于服务端运行逻辑,Modern.js 在内部提供了以下日志事件:
8
8
 
9
- | 阶段 | 消息 | Level |
10
- | ------------- | -------------------------------------------- | ----- |
11
- | RENDER_HTML | App Render To HTML | error |
12
- | RENDER_STREAM | An error occurs during streaming SSR | error |
9
+ | 阶段 | 消息 | Level |
10
+ | ------------- | --------------------------------------------- | ----- |
11
+ | RENDER_HTML | App Render To HTML | error |
12
+ | RENDER_STREAM | An error occurs during streaming SSR | error |
13
13
  | RENDER_SHELL | An error occurs during streaming render shell | error |
14
14
 
15
15
  ## 内置 Monitor
@@ -17,5 +17,3 @@
17
17
  import InternalLogger from '@site-docs/components/internal-logger.mdx';
18
18
 
19
19
  <InternalLogger />
20
-
21
-
@@ -8,21 +8,20 @@
8
8
 
9
9
  基于服务端运行逻辑,Modern.js 在内部提供了以下指标事件:
10
10
 
11
- | Key | 描述 |
12
- | ------------------------ | --------------- |
13
- | server-handle-request | Modern.js Server 处理请求单次耗时 |
14
- | ssr-render-shell | [SSR]在使用 Streaming SSR 时, React 将渲染一个套壳(shell)优先传输。这里表明套壳渲染完成时间 |
15
- | ssr-render-html | [SSR] React 将组件树渲染成 html 所消耗的时间,通常不会超过 50ms |
16
- | server-middleware | Modern.js 自定义 Server `Middleware` 执行总时 |
17
- | server-loader | Server 端整体 Data Loader 耗时 |
18
- | server-loader-#id | Server 端各个 Data Loader 耗时 |
19
- | server-loader-navigation | 前端导航时,服务端 Data Loader 的整体耗时 |
11
+ | Key | 描述 |
12
+ | ------------------------ | -------------------------------------------------------------------------------------------- |
13
+ | server-handle-request | Modern.js Server 处理请求单次耗时 |
14
+ | ssr-render-shell | [SSR]在使用 Streaming SSR 时, React 将渲染一个套壳(shell)优先传输。这里表明套壳渲染完成时间 |
15
+ | ssr-render-html | [SSR] React 将组件树渲染成 html 所消耗的时间,通常不会超过 50ms |
16
+ | server-middleware | Modern.js 自定义 Server `Middleware` 执行总时 |
17
+ | server-loader | Server 端整体 Data Loader 耗时 |
18
+ | server-loader-#id | Server 端各个 Data Loader 耗时 |
19
+ | server-loader-navigation | 前端导航时,服务端 Data Loader 的整体耗时 |
20
20
 
21
21
  Modern.js 服务端流程如图所示:
22
22
 
23
23
  ![server](https://lf3-static.bytednsdoc.com/obj/eden-cn/eeeh7uhbepxlpe/edenx-website/e374def0-c179-40aa-9cfe-e82e181663b1.jpeg)
24
24
 
25
-
26
25
  ## 内置 Monitor
27
26
 
28
27
  import InternalMetrics from '@site-docs/components/internal-metrics.mdx';
@@ -142,7 +142,7 @@ Project reference 提供了以下能力:
142
142
  {
143
143
  "compilerOptions": {
144
144
  "composite": true
145
- },
145
+ }
146
146
  }
147
147
  ```
148
148
 
@@ -50,13 +50,13 @@ export default defineServerConfig({
50
50
 
51
51
  3. 你可以将 `server` 目录包含在 `tsconfig.json` 中
52
52
 
53
- ```json5
53
+ ```jsonc
54
54
  {
55
55
  // ...
56
56
  "include": [
57
57
  // ...
58
- "server"
59
- ]
58
+ "server",
59
+ ],
60
60
  }
61
61
  ```
62
62
 
@@ -25,9 +25,7 @@ Modern.js 推荐使用[约定式路由](/guides/basic-features/routes/routes)做
25
25
  在 `routes/user/page.data.ts` 文件中,可以导出一个 `loader` 函数:
26
26
 
27
27
  ```ts title="routes/user/page.data.ts"
28
- export type ProfileData = {
29
- /* some types */
30
- };
28
+ export type ProfileData = {/* some types */};
31
29
 
32
30
  export const loader = async (): Promise<ProfileData> => {
33
31
  const res = await fetch('https://api/user/profile');
@@ -33,7 +33,7 @@ export const action: ActionFunction = async ({ request }) => {
33
33
  const newUser = await request.json();
34
34
  const name = newUser.name;
35
35
  return updateUserProfile(name);
36
- }
36
+ };
37
37
  ```
38
38
 
39
39
  在路由组件中,你可以通过 `useFetcher` 获取对应 `submit` 函数,执行并触发 Data Action:
@@ -43,7 +43,7 @@ import {
43
43
  useFetcher,
44
44
  useLoaderData,
45
45
  useParams,
46
- Outlet
46
+ Outlet,
47
47
  } from '@modern-js/runtime/router';
48
48
 
49
49
  export default () => {
@@ -51,23 +51,21 @@ export default () => {
51
51
  const { submit } = useFetcher();
52
52
  const editUser = () => {
53
53
  const newUser = {
54
- name: 'Modern.js'
55
- }
54
+ name: 'Modern.js',
55
+ };
56
56
  return submit(newUser, {
57
57
  method: 'post',
58
58
  encType: 'application/json',
59
- })
60
- }
59
+ });
60
+ };
61
61
  return (
62
62
  <div>
63
63
  <button onClick={editUser}>edit user</button>
64
- <div className="user-profile">
65
- {userInfo}
66
- </div>
64
+ <div className="user-profile">{userInfo}</div>
67
65
  <Outlet context={userInfo}></Outlet>
68
66
  </div>
69
- )
70
- }
67
+ );
68
+ };
71
69
  ```
72
70
 
73
71
  当执行 `submit` 后,会触发定义的 `action` 函数。在 `action` 函数中,可以通过[入参](/guides/basic-features/data/data-write.html#入参)获取提交的数据,最终发送数据到服务端。
@@ -124,17 +122,18 @@ useSubmit:
124
122
 
125
123
  ```ts
126
124
  const submit = useSubmit();
127
- submit(null, { method: "post", action: "/logout" });
125
+ submit(null, { method: 'post', action: '/logout' });
128
126
  ```
129
127
 
130
128
  useFetcher:
131
129
 
132
130
  ```ts
133
131
  const { submit } = useFetcher();
134
- submit(null, { method: "post", action: "/logout" });
132
+ submit(null, { method: 'post', action: '/logout' });
135
133
  ```
136
134
 
137
135
  `submit` 函数有两个入参,第一个入参是传递到服务端的 `formData`。第二个入参是可选参数,其中
136
+
138
137
  - `method` 相当于表单提交时的 `method`,大部分写入数据的场景下,`method` 可以传入 `post`。
139
138
  - `action` 用来指定触发哪个路由组件的 Data Action,如果未传入 `action` 入参,默认会触发当前路由组件的 action,即 `user/page.tsx` 组件或子组件中执行 submit,会触发 `user/page.data.ts` 中定义的 action。
140
139
 
@@ -144,7 +143,6 @@ submit(null, { method: "post", action: "/logout" });
144
143
 
145
144
  :::
146
145
 
147
-
148
146
  ### 数据类型
149
147
 
150
148
  `submit` 函数的第一个入参,可以接受不同类型的值。
@@ -153,7 +151,7 @@ submit(null, { method: "post", action: "/logout" });
153
151
 
154
152
  ```ts
155
153
  let formData = new FormData();
156
- formData.append("cheese", "gouda");
154
+ formData.append('cheese', 'gouda');
157
155
  submit(formData);
158
156
  // In the action, you can get the data by request.json
159
157
  ```
@@ -162,7 +160,7 @@ submit(formData);
162
160
 
163
161
  ```ts
164
162
  let searchParams = new URLSearchParams();
165
- searchParams.append("cheese", "gouda");
163
+ searchParams.append('cheese', 'gouda');
166
164
  submit(searchParams);
167
165
  // In the action, you can get the data by request.json
168
166
  ```
@@ -170,10 +168,10 @@ submit(searchParams);
170
168
  或任意 `URLSearchParams` 构造函数可接受的值:
171
169
 
172
170
  ```ts
173
- submit("cheese=gouda&toasted=yes");
171
+ submit('cheese=gouda&toasted=yes');
174
172
  submit([
175
- ["cheese", "gouda"],
176
- ["toasted", "yes"],
173
+ ['cheese', 'gouda'],
174
+ ['toasted', 'yes'],
177
175
  ]);
178
176
  // In the action, you can get the data by request.json
179
177
  ```
@@ -182,11 +180,11 @@ submit([
182
180
 
183
181
  ```ts
184
182
  submit(
185
- { key: "value" },
183
+ { key: 'value' },
186
184
  {
187
- method: "post",
188
- encType: "application/x-www-form-urlencoded",
189
- }
185
+ method: 'post',
186
+ encType: 'application/x-www-form-urlencoded',
187
+ },
190
188
  );
191
189
 
192
190
  // In the action, you can get the data by request.formData
@@ -195,14 +193,11 @@ submit(
195
193
  你也可以通过第二个参数,指定为编码方式:
196
194
 
197
195
  ```tsx
198
- submit(
199
- { key: "value" },
200
- { method: "post", encType: "application/json" }
201
- );
196
+ submit({ key: 'value' }, { method: 'post', encType: 'application/json' });
202
197
 
203
198
  submit('{"key":"value"}', {
204
- method: "post",
205
- encType: "application/json",
199
+ method: 'post',
200
+ encType: 'application/json',
206
201
  });
207
202
 
208
203
  // In the action, you can get the data by request.json
@@ -211,7 +206,7 @@ submit('{"key":"value"}', {
211
206
  或提交纯文本:
212
207
 
213
208
  ```ts
214
- submit("value", { method: "post", encType: "text/plain" });
209
+ submit('value', { method: 'post', encType: 'text/plain' });
215
210
  // In the action, you can get the data by request.text
216
211
  ```
217
212
 
@@ -228,7 +223,6 @@ Modern.js 中提供 Data Action 主要是为了使 UI 和服务器的状态能
228
223
 
229
224
  如果项目中组件共享的数据主要来自于服务端的状态,则无需在项目引入浏览器端状态管理库。可以使用 Data Loader 请求数据,通过 [`useRouteLoaderData`](/guides/basic-features/data/data-fetch.md) 在子组件中共享数据,使用 Data Action 修改和同步服务端的状态。
230
225
 
231
-
232
226
  ## CSR 和 SSR
233
227
 
234
228
  与 Data Loader 一样,SSR 项目中,Data Action 是在服务端执行的(框架会自动发请求触发 Data Action),而在 CSR 项目中,Data Action 是在浏览器端执行的。
@@ -101,8 +101,8 @@ type MockConfig = {
101
101
  };
102
102
 
103
103
  export const config = {
104
- enable: false
105
- }
104
+ enable: false,
105
+ };
106
106
  ```
107
107
 
108
108
  目前仅支持 `enable` 配置,开发者可以通过该配置控制是否执行 Mock。