@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
@@ -7,7 +7,7 @@ title: crossProject
7
7
  - **Type:** `boolean`
8
8
  - **Default:** `false`
9
9
 
10
- import EnableBFFCaution from "@site-docs-en/components/enable-bff-caution";
10
+ import EnableBFFCaution from '@site-docs-en/components/enable-bff-caution';
11
11
 
12
12
  <EnableBFFCaution />
13
13
 
@@ -21,4 +21,4 @@ export default defineConfig({
21
21
  });
22
22
  ```
23
23
 
24
- For detailed configuration and usage of BFF cross-project invocation, please refer to the [BFF Cross-Project Invocation Guide](/guides/advanced-features/bff/cross-project.html).
24
+ For detailed configuration and usage of BFF cross-project invocation, please refer to the [BFF Cross-Project Invocation Guide](/guides/advanced-features/bff/cross-project.html).
@@ -7,7 +7,7 @@ title: prefix
7
7
  - **Type:** `string`
8
8
  - **Default:** `/api`
9
9
 
10
- import EnableBFFCaution from "@site-docs-en/components/enable-bff-caution";
10
+ import EnableBFFCaution from '@site-docs-en/components/enable-bff-caution';
11
11
 
12
12
  <EnableBFFCaution />
13
13
 
@@ -33,10 +33,26 @@ type LazyCompilationOptions =
33
33
  };
34
34
  ```
35
35
 
36
- - **Default:** `false`
36
+ - **Default:** depends on how the application renders:
37
+ - Pure CSR and streaming SSR applications: `{ imports: true, entries: false }`, which compiles dynamic imports on demand;
38
+ - Applications using string SSR (including any entry in `server.ssrByEntries` using string SSR), RSC or SSG: `false`.
37
39
 
38
40
  Enable lazy compilation (compilation on demand), implemented based on Rspack's [lazy compilation](https://rspack.rs/guide/features/lazy-compilation) feature.
39
41
 
42
+ This option only takes effect in the dev server and does not affect production build output. When enabled for streaming SSR applications, route components are still compiled eagerly so that first-screen JS/CSS injection stays correct.
43
+
44
+ An explicitly configured `dev.lazyCompilation` always takes precedence over the default. To disable it:
45
+
46
+ ```ts
47
+ import { defineConfig } from '@modern-js/app-tools';
48
+
49
+ export default defineConfig({
50
+ dev: {
51
+ lazyCompilation: false,
52
+ },
53
+ });
54
+ ```
55
+
40
56
  import RsbuildLink from '@site/src/components/RsbuildLink';
41
57
 
42
58
  :::info
@@ -50,4 +50,3 @@ On MacOS, you can open the specified browser when Dev Server starts, by set envi
50
50
  - Brave Browser
51
51
  - Vivaldi
52
52
  - Chromium
53
-
@@ -17,11 +17,7 @@ type CssModules = {
17
17
  resourceFragment: string,
18
18
  ) => boolean);
19
19
  exportLocalsConvention?:
20
- | 'asIs'
21
- | 'camelCase'
22
- | 'camelCaseOnly'
23
- | 'dashes'
24
- | 'dashesOnly';
20
+ 'asIs' | 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly';
25
21
  exportGlobals?: boolean;
26
22
  localIdentName?: string;
27
23
  mode?:
@@ -7,6 +7,10 @@ title: disableSvgr
7
7
  - **Type:** `boolean`
8
8
  - **Default:** `false`
9
9
 
10
+ :::warning Deprecated
11
+ `output.disableSvgr` is deprecated and will be removed in the next major version. Replace `output.disableSvgr: true` with [tools.svgr](/configure/app/tools/svgr) set to `false`; `output.disableSvgr: false` is the default behavior and can simply be removed. When both are set, `tools.svgr` wins.
12
+ :::
13
+
10
14
  Whether to transform SVGs into React components. If true, will treat all .svg files as assets.
11
15
 
12
16
  By default, when an SVG resource is referenced in a JS file, Modern.js will call SVGR to convert the SVG into a React component. If you are sure that all SVG resources in your project are not being used as React components, you can turn off this conversion by setting `disableSvgr` to true to improve build performance.
@@ -4,7 +4,6 @@ title: distPath
4
4
 
5
5
  # output.distPath
6
6
 
7
-
8
7
  import CommentTips from '@site-docs/components/output-distpath-warning';
9
8
 
10
9
  <CommentTips />
@@ -8,8 +8,7 @@ title: inlineScripts
8
8
 
9
9
  ```ts
10
10
  type InlineScriptsTest =
11
- | RegExp
12
- | ((params: { size: number; name: string }) => boolean);
11
+ RegExp | ((params: { size: number; name: string }) => boolean);
13
12
 
14
13
  type InlineScripts =
15
14
  | boolean
@@ -8,8 +8,7 @@ title: inlineStyles
8
8
 
9
9
  ```ts
10
10
  type InlineStylesTest =
11
- | RegExp
12
- | ((params: { size: number; name: string }) => boolean);
11
+ RegExp | ((params: { size: number; name: string }) => boolean);
13
12
 
14
13
  type InlineStyles =
15
14
  | boolean
@@ -16,5 +16,5 @@ export default {
16
16
  output: {
17
17
  splitRouteChunks: false,
18
18
  },
19
- }
19
+ };
20
20
  ```
@@ -20,6 +20,7 @@ The SSG feature is closely related to routing. It is recommended to understand t
20
20
  :::
21
21
 
22
22
  :::info
23
+
23
24
  - Use `output.ssg` for single-entry apps.
24
25
  - For multi-entry apps, prefer `output.ssgByEntries`.
25
26
  - If `output.ssg` is `true` and `output.ssgByEntries` is not set, all routes under all entries are treated as SSG routes.
@@ -82,4 +83,3 @@ export default defineConfig({
82
83
  },
83
84
  });
84
85
  ```
85
-
@@ -10,6 +10,7 @@ title: ssgByEntries
10
10
  Configure SSG per entry for multi-entry applications.
11
11
 
12
12
  :::info
13
+
13
14
  - Use `output.ssg` for single-entry apps.
14
15
  - For multi-entry apps, prefer `output.ssgByEntries`.
15
16
  - If `output.ssg` is `true` and `output.ssgByEntries` is not set, all routes under all entries are treated as SSG routes.
@@ -7,6 +7,10 @@ title: svgDefaultExport
7
7
  - **Type:** `'url' | 'component'`
8
8
  - **Default:** `'url'`
9
9
 
10
+ :::warning Deprecated
11
+ `output.svgDefaultExport` is deprecated and will be removed in the next major version. Use `svgrOptions.exportType` of [tools.svgr](/configure/app/tools/svgr) instead: `'component'` maps to `exportType: 'default'`, `'url'` maps to `exportType: 'named'`. When both are set, `tools.svgr` wins.
12
+ :::
13
+
10
14
  `output.svgDefaultExport` is used to configure the default export type of SVG files.
11
15
 
12
16
  When `output.svgDefaultExport` is set to `url` , the default export of SVG files is the URL of the file. For example:
@@ -14,10 +14,7 @@ type ForceSplitting = RegExp[] | Record<string, RegExp>;
14
14
 
15
15
  interface BaseChunkSplit {
16
16
  strategy?:
17
- | 'split-by-module'
18
- | 'split-by-experience'
19
- | 'all-in-one'
20
- | 'single-vendor';
17
+ 'split-by-module' | 'split-by-experience' | 'all-in-one' | 'single-vendor';
21
18
  override?: SplitChunks;
22
19
  forceSplitting?: ForceSplitting;
23
20
  }
@@ -50,9 +50,11 @@ import { defineRuntimeConfig } from '@modern-js/runtime';
50
50
  import { myPlugin } from './config/plugin/myPlugin';
51
51
 
52
52
  export default defineRuntimeConfig({
53
- plugins: [myPlugin({
54
- foo: 1,
55
- bar: 2,
56
- })],
53
+ plugins: [
54
+ myPlugin({
55
+ foo: 1,
56
+ bar: 2,
57
+ }),
58
+ ],
57
59
  });
58
60
  ```
@@ -21,10 +21,10 @@ export default defineConfig({
21
21
 
22
22
  :::tip Prerequisites
23
23
  Before enabling RSC, ensure:
24
+
24
25
  1. React and React DOM are upgraded to version 19 (recommended 19.2.4 or above)
25
26
  2. Install the `react-server-dom-rspack@0.0.2` dependency
26
27
 
27
28
  :::
28
29
 
29
30
  For more information about using RSC, see the [React Server Components guide](/guides/basic-features/render/rsc).
30
-
@@ -25,13 +25,12 @@ export default defineConfig({
25
25
 
26
26
  When the value type is `Object`, the following properties can be configured:
27
27
 
28
- | Name | Type | Default | Description |
29
- | ---------------- | ------------------------------------------------------------- | -------------------------------------- | ---------------------------------------------------------------------------- |
30
- | mode | `string` | `stream` | which defaults to using streaming rendering. Configure `string` to use `renderToString` for rendering |
31
- | forceCSR | `boolean` | `false` | which is off by default for forcing CSR rendering. Configure `true` to force CSR by adding `?csr=true` or adding `x-modern-ssr-fallback` header when accessing the page |
32
- | unsafeHeaders | `string[]` | `[]` | For safety reasons, Modern.js does not add excessive content to SSR_DATA. Developers can use this configuration to specify the headers that need to be injected |
33
- | loaderFailureMode| `clientRender \| errorBoundary` | `errorBoundary` | The default configuration is `'errorBoundary'`, when an error occurs in [data loader](/en/guides/basic-features/data/data-fetch.html#data-loader-recommended), it will default to rendering the [`Error`](/guides/basic-features/routes/routes#error-handling) component of the route. When configured as `'clientRender'`, if a loader throws an error, it switch to client-side rendering,you can use it with [Client Loader](/en/guides/basic-features/data/data-fetch.html#client-loader) |
34
-
28
+ | Name | Type | Default | Description |
29
+ | ----------------- | ------------------------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
30
+ | mode | `string` | `stream` | which defaults to using streaming rendering. Configure `string` to use `renderToString` for rendering |
31
+ | forceCSR | `boolean` | `false` | which is off by default for forcing CSR rendering. Configure `true` to force CSR by adding `?csr=true` or adding `x-modern-ssr-fallback` header when accessing the page |
32
+ | unsafeHeaders | `string[]` | `[]` | For safety reasons, Modern.js does not add excessive content to SSR_DATA. Developers can use this configuration to specify the headers that need to be injected |
33
+ | loaderFailureMode | `clientRender \| errorBoundary` | `errorBoundary` | The default configuration is `'errorBoundary'`, when an error occurs in [data loader](/en/guides/basic-features/data/data-fetch.html#data-loader-recommended), it will default to rendering the [`Error`](/guides/basic-features/routes/routes#error-handling) component of the route. When configured as `'clientRender'`, if a loader throws an error, it switch to client-side rendering,you can use it with [Client Loader](/en/guides/basic-features/data/data-fetch.html#client-loader) |
35
34
 
36
35
  ```ts title="modern.config.ts"
37
36
  export default defineConfig({
@@ -39,7 +38,7 @@ export default defineConfig({
39
38
  ssr: {
40
39
  forceCSR: true,
41
40
  mode: 'stream',
42
- unsafeHeaders: ['User-Agent']
41
+ unsafeHeaders: ['User-Agent'],
43
42
  },
44
43
  },
45
44
  });
@@ -40,9 +40,9 @@ Add `<appDirectory>/tsconfig.server.json`:
40
40
  "types": ["node"],
41
41
  "esModuleInterop": true,
42
42
  "experimentalDecorators": true,
43
- "emitDecoratorMetadata": true
43
+ "emitDecoratorMetadata": true,
44
44
  },
45
- "include": ["api", "shared", "server", "config", "modern.config.ts"]
45
+ "include": ["api", "shared", "server", "config", "modern.config.ts"],
46
46
  }
47
47
  ```
48
48
 
@@ -9,49 +9,78 @@ title: less
9
9
 
10
10
  ```js
11
11
  const defaultOptions = {
12
- lessOptions: {
13
- javascriptEnabled: true,
12
+ lessLoaderOptions: {
13
+ lessOptions: {
14
+ javascriptEnabled: true,
15
+ },
16
+ // CSS Source Map enabled by default in development environment
17
+ sourceMap: isDev,
14
18
  },
15
- // CSS Source Map enabled by default in development environment
16
- sourceMap: isDev,
17
19
  };
18
20
  ```
19
21
 
20
- You can modify the config of [less-loader](https://github.com/webpack-contrib/less-loader) via `tools.less`.
22
+ `tools.less` modifies the options of [@rsbuild/plugin-less](https://rsbuild.rs/plugins/list/plugin-less). It accepts the full plugin options:
23
+
24
+ | Option | Description |
25
+ | ------------------- | --------------------------------------------------------------------------------------------------- |
26
+ | `lessLoaderOptions` | Options passed to [less-loader](https://github.com/webpack-contrib/less-loader), object or function |
27
+ | `include` | Files handled by less-loader, defaults to `/\.less$/` |
28
+ | `exclude` | Files that less-loader should skip |
29
+ | `parallel` | Whether to compile Less modules in worker threads, defaults to `false` |
30
+
31
+ ### Modifying less-loader options
21
32
 
22
- ### Object Type
33
+ When `lessLoaderOptions` is an `Object`, it is merged with the default config through Object.assign in a shallow way. It should be noted that `lessOptions` is merged through deepMerge in a deep way. For example:
34
+
35
+ ```js
36
+ export default {
37
+ tools: {
38
+ less: {
39
+ lessLoaderOptions: {
40
+ lessOptions: {
41
+ javascriptEnabled: false,
42
+ },
43
+ },
44
+ },
45
+ },
46
+ };
47
+ ```
23
48
 
24
- When `tools.less` is configured as `Object` type, it is merged with the default config through Object.assign in a shallow way. It should be noted that `lessOptions` is merged through deepMerge in a deep way. For example:
49
+ When `lessLoaderOptions` is a `Function`, the default config is passed as the first parameter, which can be directly modified or returned as the final result. The second parameter provides some utility functions that can be called directly. For example:
25
50
 
26
51
  ```js
27
52
  export default {
28
53
  tools: {
29
54
  less: {
30
- lessOptions: {
31
- javascriptEnabled: false,
55
+ lessLoaderOptions(config) {
56
+ // Modify the config of lessOptions
57
+ config.lessOptions = {
58
+ javascriptEnabled: false,
59
+ };
32
60
  },
33
61
  },
34
62
  },
35
63
  };
36
64
  ```
37
65
 
38
- ### Function Type
66
+ ### Parallel compilation
39
67
 
40
- When `tools.less` is a Function, the default config is passed as the first parameter, which can be directly modified or returned as the final result. The second parameter provides some utility functions that can be called directly. For example:
68
+ Less compilation is pure JavaScript and runs on the Node.js main thread by default. With `parallel` enabled, Less modules are compiled in a pool of worker threads, which shortens the build when a project has many Less files.
41
69
 
42
70
  ```js
43
71
  export default {
44
72
  tools: {
45
- less(config) {
46
- // Modify the config of lessOptions
47
- config.lessOptions = {
48
- javascriptEnabled: false,
49
- };
73
+ less: {
74
+ parallel: true,
50
75
  },
51
76
  },
52
77
  };
53
78
  ```
54
79
 
80
+ :::tip
81
+ Options sent to worker threads must satisfy the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm). With `parallel` enabled, `lessLoaderOptions` therefore cannot contain functions, such as an `additionalData` function or a custom `implementation`.
82
+ :::
83
+
55
84
  ### Modifying Less Version
56
85
 
57
86
  In some scenarios, if you need to use a specific version of Less instead of the built-in Less v4 in Modern.js, you can install the desired Less version in your project and set it up using the `implementation` option of the `less-loader`.
@@ -60,7 +89,9 @@ In some scenarios, if you need to use a specific version of Less instead of the
60
89
  export default {
61
90
  tools: {
62
91
  less: {
63
- implementation: require('less'),
92
+ lessLoaderOptions: {
93
+ implementation: require('less'),
94
+ },
64
95
  },
65
96
  },
66
97
  };
@@ -77,8 +108,52 @@ Used to specify which files `less-loader` does not compile, You can pass in one
77
108
  ```js
78
109
  export default {
79
110
  tools: {
80
- less(config, { addExcludes }) {
81
- addExcludes(/node_modules/);
111
+ less: {
112
+ lessLoaderOptions(config, { addExcludes }) {
113
+ addExcludes(/node_modules/);
114
+ },
115
+ },
116
+ },
117
+ };
118
+ ```
119
+
120
+ The plugin's `exclude` option is the recommended equivalent:
121
+
122
+ ```js
123
+ export default {
124
+ tools: {
125
+ less: {
126
+ exclude: /node_modules/,
127
+ },
128
+ },
129
+ };
130
+ ```
131
+
132
+ ### Legacy form
133
+
134
+ :::warning Do not mix the two layers
135
+ As soon as an object contains a plugin-level key (`lessLoaderOptions`, `include`, `exclude`, ...), the whole object is parsed as plugin options and any loader option in it has no effect. For example, `lessOptions` in `tools.less: { parallel: true, lessOptions: { ... } }` is ignored and must be moved under `lessLoaderOptions`; a hint is printed in development.
136
+ :::
137
+
138
+ In earlier versions, `tools.less` took the less-loader options directly, e.g. `tools.less: { lessOptions: {} }` or `tools.less(config, { addExcludes }) {}`. This form still works: Modern.js wraps it into `lessLoaderOptions` and produces exactly the same config as before. A migration hint is printed in development, and the legacy form will be removed in the next major version.
139
+
140
+ ```js
141
+ // legacy
142
+ export default {
143
+ tools: {
144
+ less: {
145
+ lessOptions: { javascriptEnabled: false },
146
+ },
147
+ },
148
+ };
149
+
150
+ // current
151
+ export default {
152
+ tools: {
153
+ less: {
154
+ lessLoaderOptions: {
155
+ lessOptions: { javascriptEnabled: false },
156
+ },
82
157
  },
83
158
  },
84
159
  };
@@ -9,41 +9,64 @@ title: sass
9
9
 
10
10
  ```js
11
11
  const defaultOptions = {
12
- // CSS Source Map enabled by default in development environment
13
- sourceMap: isDev,
12
+ sassLoaderOptions: {
13
+ // CSS Source Map enabled by default in development environment
14
+ sourceMap: isDev,
15
+ },
14
16
  };
15
17
  ```
16
18
 
17
- You can modify the config of [sass-loader](https://github.com/webpack-contrib/sass-loader) via `tools.sass`.
19
+ `tools.sass` modifies the options of [@rsbuild/plugin-sass](https://rsbuild.rs/plugins/list/plugin-sass). It accepts the full plugin options:
18
20
 
19
- ### Object Type
21
+ | Option | Description |
22
+ | ------------------- | --------------------------------------------------------------------------------------------------- |
23
+ | `sassLoaderOptions` | Options passed to [sass-loader](https://github.com/webpack-contrib/sass-loader), object or function |
24
+ | `include` | Files handled by sass-loader, defaults to `/\.s(?:a\|c)ss$/` |
25
+ | `exclude` | Files that sass-loader should skip |
26
+ | `rewriteUrls` | Whether to rewrite relative URLs in Sass files with resolve-url-loader, defaults to `true` |
20
27
 
21
- When `tools.sass` is `Object` type, it is merged with the default config through Object.assign. It should be noted that `sassOptions` is merged through deepMerge in a deep way.
28
+ ### Modifying sass-loader options
22
29
 
23
- For example:
30
+ When `sassLoaderOptions` is an `Object`, it is merged with the default config through Object.assign in a shallow way. It should be noted that `sassOptions` is merged through deepMerge in a deep way. For example:
24
31
 
25
32
  ```js
26
33
  export default {
27
34
  tools: {
28
35
  sass: {
29
- sourceMap: true,
36
+ sassLoaderOptions: {
37
+ sourceMap: true,
38
+ },
39
+ },
40
+ },
41
+ };
42
+ ```
43
+
44
+ When `sassLoaderOptions` is a `Function`, the default config is passed as the first parameter, which can be directly modified or returned as the final result. The second parameter provides some utility functions that can be called directly. For example:
45
+
46
+ ```js
47
+ export default {
48
+ tools: {
49
+ sass: {
50
+ sassLoaderOptions(config) {
51
+ // Modify the additionalData config
52
+ config.additionalData = async (content, loaderContext) => {
53
+ // ...
54
+ };
55
+ },
30
56
  },
31
57
  },
32
58
  };
33
59
  ```
34
60
 
35
- ### Function Type
61
+ ### Disabling URL rewriting
36
62
 
37
- When `tools.sass` is a Function, the default config is passed as the first parameter, which can be directly modified or returned as the final result. The second parameter provides some utility functions that can be called directly. For Example:
63
+ By default, relative URLs in Sass files are rewritten by resolve-url-loader so that they resolve relative to the source file. If your project does not rely on this, turn it off to drop one loader from the chain:
38
64
 
39
65
  ```js
40
66
  export default {
41
67
  tools: {
42
- sass(config) {
43
- // Modify sourceMap config
44
- config.additionalData = async (content, loaderContext) => {
45
- // ...
46
- };
68
+ sass: {
69
+ rewriteUrls: false,
47
70
  },
48
71
  },
49
72
  };
@@ -57,13 +80,15 @@ In some scenarios, if you need to use a specific version of Sass instead of the
57
80
  export default {
58
81
  tools: {
59
82
  sass: {
60
- implementation: require('sass'),
83
+ sassLoaderOptions: {
84
+ implementation: require('sass'),
85
+ },
61
86
  },
62
87
  },
63
88
  };
64
89
  ```
65
90
 
66
- ### Utility Function
91
+ ### Util Function
67
92
 
68
93
  #### addExcludes
69
94
 
@@ -74,8 +99,52 @@ Used to specify which files `sass-loader` does not compile, You can pass in one
74
99
  ```js
75
100
  export default {
76
101
  tools: {
77
- sass(config, { addExcludes }) {
78
- addExcludes(/node_modules/);
102
+ sass: {
103
+ sassLoaderOptions(config, { addExcludes }) {
104
+ addExcludes(/node_modules/);
105
+ },
106
+ },
107
+ },
108
+ };
109
+ ```
110
+
111
+ The plugin's `exclude` option is the recommended equivalent:
112
+
113
+ ```js
114
+ export default {
115
+ tools: {
116
+ sass: {
117
+ exclude: /node_modules/,
118
+ },
119
+ },
120
+ };
121
+ ```
122
+
123
+ ### Legacy form
124
+
125
+ :::warning Do not mix the two layers
126
+ As soon as an object contains a plugin-level key (`sassLoaderOptions`, `include`, `exclude`, ...), the whole object is parsed as plugin options and any loader option in it has no effect. For example, `sassOptions` in `tools.sass: { rewriteUrls: false, sassOptions: { ... } }` is ignored and must be moved under `sassLoaderOptions`; a hint is printed in development.
127
+ :::
128
+
129
+ In earlier versions, `tools.sass` took the sass-loader options directly, e.g. `tools.sass: { sassOptions: {} }` or `tools.sass(config, { addExcludes }) {}`. This form still works: Modern.js wraps it into `sassLoaderOptions` and produces exactly the same config as before. A migration hint is printed in development, and the legacy form will be removed in the next major version.
130
+
131
+ ```js
132
+ // legacy
133
+ export default {
134
+ tools: {
135
+ sass: {
136
+ sourceMap: true,
137
+ },
138
+ },
139
+ };
140
+
141
+ // current
142
+ export default {
143
+ tools: {
144
+ sass: {
145
+ sassLoaderOptions: {
146
+ sourceMap: true,
147
+ },
79
148
  },
80
149
  },
81
150
  };
@@ -0,0 +1,93 @@
1
+ ---
2
+ title: svgr
3
+ ---
4
+
5
+ # tools.svgr
6
+
7
+ - **Type:** `Object | Function | false`
8
+ - **Default:**
9
+
10
+ ```js
11
+ const defaultOptions = {
12
+ mixedImport: true,
13
+ svgrOptions: {
14
+ exportType: 'named',
15
+ },
16
+ };
17
+ ```
18
+
19
+ `tools.svgr` modifies the options of [@rsbuild/plugin-svgr](https://rsbuild.rs/plugins/list/plugin-svgr). It accepts the full plugin options. Set it to `false` to skip registering the SVGR plugin; all `.svg` files are then treated as static assets.
20
+
21
+ | Option | Description |
22
+ | ----------------- | ---------------------------------------------------------------------------------------------------------- |
23
+ | `svgrOptions` | Options passed to [SVGR](https://react-svgr.com/docs/options/), such as `exportType`, `icon`, `svgoConfig` |
24
+ | `parallel` | Whether to transform SVG files in worker threads, defaults to `false` |
25
+ | `exclude` | SVG files that SVGR should skip |
26
+ | `excludeImporter` | Importer files whose SVG imports should skip SVGR |
27
+ | `query` | Query that triggers the SVGR transform, defaults to `/react/` |
28
+ | `mixedImport` | Whether a module may import both the URL and the React component, defaults to `true` |
29
+
30
+ ### Merge rules
31
+
32
+ When `tools.svgr` is an `Object`, its top-level fields are merged with the defaults through Object.assign in a shallow way, and `svgrOptions` is merged one level deeper, so setting only `svgrOptions.icon` keeps the default `exportType`.
33
+
34
+ When `tools.svgr` is a `Function`, the default config is passed as the first parameter, which can be directly modified or returned as the final result. An array of objects and functions is also accepted and applied in order.
35
+
36
+ ### Parallel transform
37
+
38
+ The SVGR transform is pure JavaScript and runs on the Node.js main thread by default. With many SVG files, enable `parallel` to move the transform into a pool of worker threads:
39
+
40
+ ```js
41
+ export default {
42
+ tools: {
43
+ svgr: {
44
+ parallel: true,
45
+ },
46
+ },
47
+ };
48
+ ```
49
+
50
+ :::tip
51
+ Options sent to worker threads must satisfy the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm). With `parallel` enabled, `svgrOptions` therefore cannot contain functions.
52
+ :::
53
+
54
+ ### Changing the default export
55
+
56
+ `svgrOptions.exportType` controls what an SVG file exports by default: `'named'` exports the file URL by default and the React component as the named export `ReactComponent`; `'default'` exports the React component by default.
57
+
58
+ ```js
59
+ export default {
60
+ tools: {
61
+ svgr: {
62
+ svgrOptions: {
63
+ exportType: 'default',
64
+ },
65
+ },
66
+ },
67
+ };
68
+ ```
69
+
70
+ ### Disabling SVGR
71
+
72
+ If you are sure that no SVG asset in your project is used as a React component, disable SVGR to improve build performance:
73
+
74
+ ```js
75
+ export default {
76
+ tools: {
77
+ svgr: false,
78
+ },
79
+ };
80
+ ```
81
+
82
+ ### Relation to the legacy options
83
+
84
+ `tools.svgr` replaces the two deprecated options below. They still work today and will be removed in the next major version:
85
+
86
+ | Legacy option | Replacement |
87
+ | -------------------------------------- | -------------------------------------------------------- |
88
+ | `output.svgDefaultExport: 'component'` | `tools.svgr: { svgrOptions: { exportType: 'default' } }` |
89
+ | `output.svgDefaultExport: 'url'` | `tools.svgr: { svgrOptions: { exportType: 'named' } }` |
90
+ | `output.disableSvgr: true` | `tools.svgr: false` |
91
+ | `output.disableSvgr: false` | Default behavior, just remove it |
92
+
93
+ When both are set, `tools.svgr` wins: once `tools.svgr` is set explicitly, `output.disableSvgr` no longer applies, and `tools.svgr.svgrOptions.exportType` overrides the value derived from `output.svgDefaultExport`.