@modern-js/main-doc 2.67.6 → 2.67.8

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 (112) hide show
  1. package/docs/en/apis/app/commands.mdx +3 -3
  2. package/docs/en/apis/app/hooks/src/routes.mdx +0 -70
  3. package/docs/en/community/blog/v2-release-note.mdx +2 -2
  4. package/docs/en/community/contributing-guide.mdx +1 -1
  5. package/docs/en/components/builder.mdx +1 -1
  6. package/docs/en/components/bundler.mdx +1 -1
  7. package/docs/en/components/rsbuild.mdx +1 -1
  8. package/docs/en/components/rspack.mdx +1 -1
  9. package/docs/en/components/rspackPrecautions.mdx +2 -2
  10. package/docs/en/configure/app/builder-plugins.mdx +1 -1
  11. package/docs/en/configure/app/output/assets-retry.mdx +1 -1
  12. package/docs/en/configure/app/output/copy.mdx +1 -1
  13. package/docs/en/configure/app/performance/build-cache.mdx +1 -1
  14. package/docs/en/configure/app/performance/transform-lodash.mdx +4 -1
  15. package/docs/en/configure/app/security/sri.mdx +1 -1
  16. package/docs/en/configure/app/source/exclude.mdx +2 -2
  17. package/docs/en/configure/app/source/include.mdx +1 -1
  18. package/docs/en/configure/app/source/module-scopes.mdx +4 -1
  19. package/docs/en/configure/app/source/transform-import.mdx +2 -2
  20. package/docs/en/configure/app/tools/babel.mdx +5 -5
  21. package/docs/en/configure/app/tools/bundler-chain.mdx +2 -2
  22. package/docs/en/configure/app/tools/css-extract.mdx +1 -1
  23. package/docs/en/configure/app/tools/dev-server.mdx +1 -1
  24. package/docs/en/configure/app/tools/lightningcss-loader.mdx +1 -1
  25. package/docs/en/configure/app/tools/rspack.mdx +1 -1
  26. package/docs/en/configure/app/tools/swc.mdx +3 -3
  27. package/docs/en/configure/app/tools/terser.mdx +4 -2
  28. package/docs/en/configure/app/tools/ts-loader.mdx +4 -1
  29. package/docs/en/configure/app/tools/webpack-chain.mdx +22 -19
  30. package/docs/en/configure/app/tools/webpack.mdx +4 -1
  31. package/docs/en/guides/advanced-features/build-performance.mdx +1 -1
  32. package/docs/en/guides/advanced-features/compatibility.mdx +1 -1
  33. package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +3 -3
  34. package/docs/en/guides/advanced-features/rspack-start.mdx +2 -2
  35. package/docs/en/guides/advanced-features/web-server.mdx +16 -4
  36. package/docs/en/guides/basic-features/css/css.mdx +4 -4
  37. package/docs/en/guides/basic-features/data/data-cache.mdx +1 -1
  38. package/docs/en/guides/basic-features/debug/rsdoctor.mdx +1 -1
  39. package/docs/en/guides/basic-features/render/ssr.mdx +1 -1
  40. package/docs/en/guides/basic-features/render/streaming-ssr.mdx +2 -2
  41. package/docs/en/guides/basic-features/routes.mdx +75 -3
  42. package/docs/en/guides/basic-features/static-assets/wasm-assets.mdx +1 -1
  43. package/docs/en/guides/basic-features/static-assets.mdx +1 -1
  44. package/docs/en/guides/concept/builder.mdx +3 -3
  45. package/docs/en/guides/concept/entries.mdx +1 -1
  46. package/docs/en/guides/get-started/tech-stack.mdx +3 -3
  47. package/docs/en/guides/topic-detail/module-federation/deploy.mdx +83 -7
  48. package/docs/en/guides/topic-detail/module-federation/usage.mdx +2 -4
  49. package/docs/en/guides/troubleshooting/builder.mdx +4 -5
  50. package/docs/en/plugin/cli-plugins/api.mdx +141 -135
  51. package/docs/en/plugin/introduction.mdx +27 -24
  52. package/docs/en/tutorials/examples/csr-auth.mdx +15 -198
  53. package/docs/zh/apis/app/commands.mdx +3 -3
  54. package/docs/zh/community/blog/v2-release-note.mdx +2 -2
  55. package/docs/zh/community/contributing-guide.mdx +1 -1
  56. package/docs/zh/components/builder.mdx +1 -1
  57. package/docs/zh/components/bundler.mdx +1 -2
  58. package/docs/zh/components/rsbuild.mdx +1 -1
  59. package/docs/zh/components/rspack.mdx +1 -1
  60. package/docs/zh/components/rspackPrecautions.mdx +2 -2
  61. package/docs/zh/configure/app/builder-plugins.mdx +1 -1
  62. package/docs/zh/configure/app/output/assets-retry.mdx +1 -1
  63. package/docs/zh/configure/app/output/copy.mdx +1 -1
  64. package/docs/zh/configure/app/performance/build-cache.mdx +1 -1
  65. package/docs/zh/configure/app/performance/transform-lodash.mdx +4 -1
  66. package/docs/zh/configure/app/security/sri.mdx +1 -1
  67. package/docs/zh/configure/app/source/exclude.mdx +2 -2
  68. package/docs/zh/configure/app/source/include.mdx +1 -1
  69. package/docs/zh/configure/app/source/module-scopes.mdx +4 -1
  70. package/docs/zh/configure/app/source/transform-import.mdx +2 -2
  71. package/docs/zh/configure/app/tools/babel.mdx +5 -6
  72. package/docs/zh/configure/app/tools/bundler-chain.mdx +2 -2
  73. package/docs/zh/configure/app/tools/css-extract.mdx +1 -1
  74. package/docs/zh/configure/app/tools/dev-server.mdx +1 -1
  75. package/docs/zh/configure/app/tools/lightningcss-loader.mdx +1 -1
  76. package/docs/zh/configure/app/tools/rspack.mdx +1 -1
  77. package/docs/zh/configure/app/tools/swc.mdx +3 -3
  78. package/docs/zh/configure/app/tools/terser.mdx +4 -2
  79. package/docs/zh/configure/app/tools/ts-loader.mdx +4 -1
  80. package/docs/zh/configure/app/tools/webpack-chain.mdx +23 -20
  81. package/docs/zh/configure/app/tools/webpack.mdx +4 -1
  82. package/docs/zh/guides/advanced-features/compatibility.mdx +1 -1
  83. package/docs/zh/guides/advanced-features/page-performance/optimize-bundle.mdx +2 -2
  84. package/docs/zh/guides/advanced-features/rspack-start.mdx +2 -2
  85. package/docs/zh/guides/advanced-features/web-server.mdx +17 -4
  86. package/docs/zh/guides/basic-features/css/css.mdx +4 -4
  87. package/docs/zh/guides/basic-features/data/data-cache.mdx +1 -1
  88. package/docs/zh/guides/basic-features/debug/rsdoctor.mdx +1 -1
  89. package/docs/zh/guides/basic-features/render/ssr.mdx +1 -1
  90. package/docs/zh/guides/basic-features/render/streaming-ssr.mdx +1 -1
  91. package/docs/zh/guides/basic-features/static-assets/wasm-assets.mdx +1 -1
  92. package/docs/zh/guides/basic-features/static-assets.mdx +2 -2
  93. package/docs/zh/guides/concept/builder.mdx +3 -3
  94. package/docs/zh/guides/concept/entries.mdx +1 -1
  95. package/docs/zh/guides/get-started/tech-stack.mdx +3 -3
  96. package/docs/zh/guides/topic-detail/module-federation/deploy.mdx +83 -7
  97. package/docs/zh/guides/topic-detail/module-federation/usage.mdx +2 -4
  98. package/docs/zh/guides/troubleshooting/builder.mdx +4 -5
  99. package/docs/zh/plugin/cli-plugins/api.mdx +123 -121
  100. package/docs/zh/plugin/introduction.mdx +18 -15
  101. package/docs/zh/tutorials/examples/csr-auth.mdx +15 -198
  102. package/package.json +6 -6
  103. package/rspress.config.ts +12 -1
  104. package/src/components/RsbuildLink/index.tsx +1 -1
  105. package/src/components/Sandpack/index.tsx +1 -11
  106. package/src/components/ShowcaseList/useShowcases.ts +1 -1
  107. package/src/sandbox/csr-auth/src/routes/Auth-tsx.txt +74 -0
  108. package/src/sandbox/csr-auth/src/routes/fakeAuth-ts.txt +16 -0
  109. package/src/sandbox/csr-auth/src/routes/layout-tsx.txt +21 -0
  110. package/src/sandbox/csr-auth/src/routes/login/page-tsx.txt +40 -0
  111. package/src/sandbox/csr-auth/src/routes/page-tsx.txt +17 -0
  112. package/src/sandbox/csr-auth/src/routes/protected/page-tsx.txt +11 -0
@@ -17,7 +17,7 @@ import type { CliPluginFuture, AppTools } from '@modern-js/app-tools';
17
17
 
18
18
  const myCliPlugin = (): CliPluginFuture<AppTools<'shared'>> => ({
19
19
  name: '@my-org/my-plugin', // Plugin name, ensure uniqueness
20
- setup: (api) => {
20
+ setup: api => {
21
21
  // Use the API here to register hooks, add commands, etc.
22
22
  api.onBeforeBuild(() => {
23
23
  console.log('Build is about to start...');
@@ -36,39 +36,43 @@ The `setup` function receives an `api` object, which provides all available CLI
36
36
 
37
37
  Gets the context information of the Modern.js application.
38
38
 
39
- - **Returns:** An `AppContext` object containing the following fields:
40
-
41
- | Field Name | Type | Description | When Available |
42
- | ---------------------- | -------------------- | ----------------------------------------------------------------------------- | -------------------------------------- |
43
- | `command` | `string` | The currently executing command (e.g., `dev`, `build`, `deploy`) | - |
44
- | `port` | `number` | The development server port number | After `onPrepare` |
45
- | `configFile` | `string` | The absolute path to the configuration file | - |
46
- | `isProd` | `boolean` | Whether it is in production mode | - |
47
- | `appDirectory` | `string` | The absolute path to the project root directory | - |
48
- | `srcDirectory` | `string` | The absolute path to the project source code directory | - |
49
- | `distDirectory` | `string` | The absolute path to the project output directory | After `modifyResolvedConfig` |
50
- | `sharedDirectory` | `string` | The absolute path to the shared modules directory | - |
51
- | `nodeModulesDirectory` | `string` | The absolute path to the `node_modules` directory | - |
52
- | `ip` | `string` | The IPv4 address of the current machine | - |
53
- | `packageName` | `string` | The `name` field in the project's `package.json` | - |
54
- | `plugins` | `object[]` | The list of currently registered plugins | - |
55
- | `entrypoints` | `object[]` | Information about page entry points | - |
56
- | `serverRoutes` | `object[]` | Server-side routing information | - |
57
- | `bundlerType` | `webpack \| rspack` | The type of bundler currently in use (`webpack` or `rspack`) | After `onPrepare` |
58
- | `metaName` | `string` | The internal name of the framework | - |
59
- | `apiDirectory` | `string` | The absolute path to the API module directory (used by BFF) | - |
60
- | `lambdaDirectory` | `string` | The absolute path to the Lambda module directory (used by BFF) | - |
61
- | `runtimeConfigFile` | `string` | The name of the runtime configuration file | - |
62
- | `serverConfigFile` | `string` | The name of the server configuration file | - |
63
- | `checkedEntries` | `string[]` | Specified entry information | - |
64
- | `apiOnly` | `boolean` | Whether it is in `apiOnly` mode | - |
65
-
66
- - **Example:**
39
+ - **Returns:** An `AppContext` object containing the following fields:
40
+
41
+ | Field Name | Type | Description | When Available |
42
+ | ---------------------- | ------------------- | ---------------------------------------------------------------- | ---------------------------- |
43
+ | `command` | `string` | The currently executing command (e.g., `dev`, `build`, `deploy`) | - |
44
+ | `port` | `number` | The development server port number | After `onPrepare` |
45
+ | `configFile` | `string` | The absolute path to the configuration file | - |
46
+ | `isProd` | `boolean` | Whether it is in production mode | - |
47
+ | `appDirectory` | `string` | The absolute path to the project root directory | - |
48
+ | `srcDirectory` | `string` | The absolute path to the project source code directory | - |
49
+ | `distDirectory` | `string` | The absolute path to the project output directory | After `modifyResolvedConfig` |
50
+ | `sharedDirectory` | `string` | The absolute path to the shared modules directory | - |
51
+ | `nodeModulesDirectory` | `string` | The absolute path to the `node_modules` directory | - |
52
+ | `ip` | `string` | The IPv4 address of the current machine | - |
53
+ | `packageName` | `string` | The `name` field in the project's `package.json` | - |
54
+ | `plugins` | `object[]` | The list of currently registered plugins | - |
55
+ | `entrypoints` | `object[]` | Information about page entry points | - |
56
+ | `serverRoutes` | `object[]` | Server-side routing information | - |
57
+ | `bundlerType` | `webpack \| rspack` | The type of bundler currently in use (`webpack` or `rspack`) | After `onPrepare` |
58
+ | `metaName` | `string` | The internal name of the framework | - |
59
+ | `apiDirectory` | `string` | The absolute path to the API module directory (used by BFF) | - |
60
+ | `lambdaDirectory` | `string` | The absolute path to the Lambda module directory (used by BFF) | - |
61
+ | `runtimeConfigFile` | `string` | The name of the runtime configuration file | - |
62
+ | `serverConfigFile` | `string` | The name of the server configuration file | - |
63
+ | `checkedEntries` | `string[]` | Specified entry information | - |
64
+ | `apiOnly` | `boolean` | Whether it is in `apiOnly` mode | - |
65
+
66
+ - **Example:**
67
67
 
68
68
  ```typescript
69
69
  api.onPrepare(() => {
70
70
  const appContext = api.getAppContext();
71
- console.log(`The current project is running in ${appContext.isProd ? 'production' : 'development'} mode`);
71
+ console.log(
72
+ `The current project is running in ${
73
+ appContext.isProd ? 'production' : 'development'
74
+ } mode`,
75
+ );
72
76
  console.log(`Bundler: ${appContext.bundlerType}`);
73
77
  });
74
78
  ```
@@ -83,17 +87,16 @@ The context information returned by `getAppContext` is read-only and cannot be m
83
87
 
84
88
  Gets the user-defined configuration from the `modern.config.ts` file.
85
89
 
86
- - **Returns:** The user-defined configuration object.
87
- - **Example:**
90
+ - **Returns:** The user-defined configuration object.
91
+ - **Example:**
88
92
 
89
93
  ```typescript
90
94
  api.onPrepare(() => {
91
- const userConfig = api.getConfig();
92
- if (userConfig.output) {
93
- console.log('User has customized the output configuration');
94
- }
95
+ const userConfig = api.getConfig();
96
+ if (userConfig.output) {
97
+ console.log('User has customized the output configuration');
98
+ }
95
99
  });
96
-
97
100
  ```
98
101
 
99
102
  ---
@@ -102,9 +105,9 @@ api.onPrepare(() => {
102
105
 
103
106
  Gets the final configuration after internal processing by Modern.js and modifications by plugins (normalized configuration).
104
107
 
105
- - **Returns:** The normalized configuration object.
106
- - **When Available:** Must be used after the `modifyResolvedConfig` hook.
107
- - **Example:**
108
+ - **Returns:** The normalized configuration object.
109
+ - **When Available:** Must be used after the `modifyResolvedConfig` hook.
110
+ - **Example:**
108
111
 
109
112
  ```typescript
110
113
  api.modifyResolvedConfig(resolvedConfig => {
@@ -124,10 +127,10 @@ api.onBeforeBuild(() => {
124
127
 
125
128
  Checks if a specified plugin is registered.
126
129
 
127
- - **Parameters:**
128
- - `pluginName: string`: The name of the plugin to check.
129
- - **Returns:** A `boolean` value indicating whether the plugin exists.
130
- - **Example:**
130
+ - **Parameters:**
131
+ - `pluginName: string`: The name of the plugin to check.
132
+ - **Returns:** A `boolean` value indicating whether the plugin exists.
133
+ - **Example:**
131
134
 
132
135
  ```typescript
133
136
  if (api.isPluginExists('@modern-js/plugin-tailwind')) {
@@ -141,8 +144,8 @@ if (api.isPluginExists('@modern-js/plugin-tailwind')) {
141
144
 
142
145
  Gets all registered hook functions.
143
146
 
144
- - **Returns:** An object containing all hook functions.
145
- - **Example:**
147
+ - **Returns:** An object containing all hook functions.
148
+ - **Example:**
146
149
 
147
150
  ```typescript
148
151
  const hooks = api.getHooks();
@@ -162,7 +165,7 @@ In custom plugins, you can only manually call the hooks registered by the corres
162
165
 
163
166
  Modify the initial configuration of Modern.js.
164
167
 
165
- - **Type:** `api.config(configFn: () => UserConfig | Promise<UserConfig>)`
168
+ - **Type:** `api.config(configFn: () => UserConfig | Promise<UserConfig>)`
166
169
  - **Parameters:**
167
170
  - `configFn`: A function that returns a configuration object or a Promise.
168
171
  - **Execution Phase:** After parsing the configuration in `modern.config.ts`.
@@ -194,7 +197,7 @@ Modify Webpack or Rspack configuration using the chain API.
194
197
  - **Parameters:**
195
198
  - `modifyFn`: A modification function that receives a `webpack-chain` or `RspackChain` instance and utility functions as parameters.
196
199
  - **Execution Phase:** When generating the final Webpack or Rspack configuration.
197
- - **Corresponding Rsbuild Hook:** [modifyBundlerChain](https://rsbuild.dev/en/plugins/dev/hooks#modifybundlerchain)
200
+ - **Corresponding Rsbuild Hook:** [modifyBundlerChain](https://rsbuild.rs/en/plugins/dev/hooks#modifybundlerchain)
198
201
  - **Example:**
199
202
 
200
203
  ```typescript
@@ -210,39 +213,39 @@ api.modifyBundlerChain((chain, utils) => {
210
213
 
211
214
  Modify the Rsbuild configuration.
212
215
 
213
- - **Type:** `api.modifyRsbuildConfig(modifyFn: (config: RsbuildConfig, utils: RsbuildUtils) => RsbuildConfig | Promise<RsbuildConfig> | void)`
214
- - **Parameters:**
215
- - `modifyFn`: A modification function that receives the Rsbuild configuration object and utility functions as parameters. It can return the modified configuration object, a Promise, or nothing (modifying the original object directly).
216
- - **Execution Phase:** When generating the final Rsbuild configuration.
217
- - **Corresponding Rsbuild Hook:** [modifyRsbuildConfig](https://rsbuild.dev/en/plugins/dev/hooks#modifyrsbuildconfig)
218
- - **Example:**
216
+ - **Type:** `api.modifyRsbuildConfig(modifyFn: (config: RsbuildConfig, utils: RsbuildUtils) => RsbuildConfig | Promise<RsbuildConfig> | void)`
217
+ - **Parameters:**
218
+ - `modifyFn`: A modification function that receives the Rsbuild configuration object and utility functions as parameters. It can return the modified configuration object, a Promise, or nothing (modifying the original object directly).
219
+ - **Execution Phase:** When generating the final Rsbuild configuration.
220
+ - **Corresponding Rsbuild Hook:** [modifyRsbuildConfig](https://rsbuild.rs/en/plugins/dev/hooks#modifyrsbuildconfig)
221
+ - **Example:**
219
222
 
220
223
  ```typescript
221
224
  api.modifyRsbuildConfig((config, utils) => {
222
225
  // Add a custom Rsbuild plugin
223
226
  config.plugins.push(myCustomRsbuildPlugin());
224
227
  });
225
-
226
228
  ```
229
+
227
230
  ---
228
231
 
229
232
  #### `api.modifyRspackConfig`
230
233
 
231
234
  Modify the Rspack configuration (when using Rspack as the bundler).
232
235
 
233
- - **Type:** `api.modifyRspackConfig(modifyFn: (config: RspackConfig, utils: RspackUtils) => RspackConfig | Promise<RspackConfig> | void)`
234
- - **Parameters:**
235
- - `modifyFn`: A modification function that receives the Rspack configuration object and utility functions as parameters. It can return the modified configuration object, a Promise, or nothing (modifying the original object directly).
236
- - **Execution Phase:** When generating the final Rspack configuration.
237
- - **Corresponding Rsbuild Hook:** [modifyRspackConfig](https://rsbuild.dev/en/plugins/dev/hooks#modifyrspackconfig)
238
- - **Example:**
236
+ - **Type:** `api.modifyRspackConfig(modifyFn: (config: RspackConfig, utils: RspackUtils) => RspackConfig | Promise<RspackConfig> | void)`
237
+ - **Parameters:**
238
+ - `modifyFn`: A modification function that receives the Rspack configuration object and utility functions as parameters. It can return the modified configuration object, a Promise, or nothing (modifying the original object directly).
239
+ - **Execution Phase:** When generating the final Rspack configuration.
240
+ - **Corresponding Rsbuild Hook:** [modifyRspackConfig](https://rsbuild.rs/en/plugins/dev/hooks#modifyrspackconfig)
241
+ - **Example:**
239
242
 
240
243
  ```typescript
241
244
  api.modifyRspackConfig((config, utils) => {
242
245
  config.builtins.minify = {
243
246
  enable: true,
244
247
  implementation: utils.rspack.SwcJsMinimizerRspackPlugin,
245
- }
248
+ };
246
249
  });
247
250
  ```
248
251
 
@@ -252,7 +255,7 @@ api.modifyRspackConfig((config, utils) => {
252
255
 
253
256
  Modify the Webpack configuration using [webpack-chain](https://github.com/neutrinojs/webpack-chain) (when using Webpack as the bundler).
254
257
 
255
- - **Type:** `api.modifyWebpackChain(modifyFn: (chain: WebpackChain, utils: WebpackUtils) => void | Promise<void>)`
258
+ - **Type:** `api.modifyWebpackChain(modifyFn: (chain: WebpackChain, utils: WebpackUtils) => void | Promise<void>)`
256
259
  - **Parameters:**
257
260
  - `modifyFn`: A modification function that receives a `webpack-chain` instance and utility functions as parameters.
258
261
  - **Execution Phase:** When generating the final Webpack configuration.
@@ -275,39 +278,38 @@ api.modifyWebpackChain((chain, utils) => {
275
278
 
276
279
  Directly modify the Webpack configuration object (when using Webpack as the bundler).
277
280
 
278
- - **Type:** `api.modifyWebpackConfig(modifyFn: (config: WebpackConfig, utils: WebpackUtils) => WebpackConfig | Promise<WebpackConfig> | void)`
279
- - **Parameters:**
280
- - `modifyFn`: A modification function that receives the Webpack configuration object and utility functions as parameters. It can return the modified configuration object, a Promise, or nothing (modifying the original object directly).
281
- - **Execution Phase:** When generating the final Webpack configuration.
282
- - **Example:**
281
+ - **Type:** `api.modifyWebpackConfig(modifyFn: (config: WebpackConfig, utils: WebpackUtils) => WebpackConfig | Promise<WebpackConfig> | void)`
282
+ - **Parameters:**
283
+ - `modifyFn`: A modification function that receives the Webpack configuration object and utility functions as parameters. It can return the modified configuration object, a Promise, or nothing (modifying the original object directly).
284
+ - **Execution Phase:** When generating the final Webpack configuration.
285
+ - **Example:**
283
286
 
284
287
  ```typescript
285
288
  api.modifyWebpackConfig((config, utils) => {
286
289
  // Disable source map
287
290
  config.devtool = false;
288
291
  });
289
-
290
292
  ```
291
293
 
292
294
  **Build Configuration Modification Order**
293
295
 
294
- - **Building with Rspack:**
295
- ```
296
- modifyRsbuildConfig
297
- modifyBundlerChain
298
- tools.bundlerChain
299
- modifyRspackConfig
300
- tools.rspack
301
- ```
302
- - **Building with Webpack:**
303
- ```
304
- modifyBundlerChain
305
- tools.bundlerChain
306
- modifyWebpackChain
307
- tools.webpackChain
308
- modifyWebpackConfig
309
- tools.webpack
310
- ```
296
+ - **Building with Rspack:**
297
+ ```
298
+ modifyRsbuildConfig
299
+ modifyBundlerChain
300
+ tools.bundlerChain
301
+ modifyRspackConfig
302
+ tools.rspack
303
+ ```
304
+ - **Building with Webpack:**
305
+ ```
306
+ modifyBundlerChain
307
+ tools.bundlerChain
308
+ modifyWebpackChain
309
+ tools.webpackChain
310
+ modifyWebpackConfig
311
+ tools.webpack
312
+ ```
311
313
 
312
314
  ---
313
315
 
@@ -324,7 +326,7 @@ Modify the server routing configuration.
324
326
  ```typescript
325
327
  api.modifyServerRoutes(routes => {
326
328
  // Add a new API route
327
- routes.concat({
329
+ routes.push({
328
330
  urlPath: '/api',
329
331
  isApi: true,
330
332
  entryPath: '',
@@ -352,7 +354,7 @@ Modify HTML template partials.
352
354
  api.modifyHtmlPartials(({ entrypoint, partials }) => {
353
355
  // Add a meta tag to the <head> section of all pages
354
356
  if (partials.head && partials.head.append) {
355
- partials.head.append(`<meta name="my-custom-meta" content="value">`);
357
+ partials.head.append(`<meta name="my-custom-meta" content="value">`);
356
358
  }
357
359
  });
358
360
  ```
@@ -460,84 +462,88 @@ Add additional logic before the build starts.
460
462
  - **Parameters:**
461
463
  - `buildFn`: A function to be executed before the build, without parameters, can be asynchronous.
462
464
  - **Execution Phase:** Before executing the build process.
463
- - **Corresponding Rsbuild Hook:** [onBeforeBuild](https://rsbuild.dev/en/plugins/dev/hooks#onbeforebuild)
465
+ - **Corresponding Rsbuild Hook:** [onBeforeBuild](https://rsbuild.rs/en/plugins/dev/hooks#onbeforebuild)
464
466
  - **Example:**
465
467
 
466
468
  ```typescript
467
- api.onBeforeBuild(()=>{
468
- // Perform some environment checks before building
469
- })
469
+ api.onBeforeBuild(() => {
470
+ // Perform some environment checks before building
471
+ });
470
472
  ```
473
+
471
474
  ---
472
475
 
473
476
  #### `api.onAfterBuild`
474
477
 
475
478
  Add additional logic after the build is complete.
476
479
 
477
- - **Type:** `api.onAfterBuild(buildFn: () => void | Promise<void>)`
478
- - **Parameters:**
479
- - `buildFn`: A function to be executed after the build, without parameters, can be asynchronous.
480
- - **Execution Phase:** After executing the build process.
481
- - **Corresponding Rsbuild Hook:** [onAfterBuild](https://rsbuild.dev/en/plugins/dev/hooks#onafterbuild)
482
- - **Example:**
480
+ - **Type:** `api.onAfterBuild(buildFn: () => void | Promise<void>)`
481
+ - **Parameters:**
482
+ - `buildFn`: A function to be executed after the build, without parameters, can be asynchronous.
483
+ - **Execution Phase:** After executing the build process.
484
+ - **Corresponding Rsbuild Hook:** [onAfterBuild](https://rsbuild.rs/en/plugins/dev/hooks#onafterbuild)
485
+ - **Example:**
483
486
 
484
487
  ```typescript
485
- api.onAfterBuild(()=>{
486
- // Upload sourceMap after building
487
- })
488
+ api.onAfterBuild(() => {
489
+ // Upload sourceMap after building
490
+ });
488
491
  ```
489
492
 
490
493
  ---
491
494
 
492
495
  #### `api.onDevCompileDone`
496
+
493
497
  Add additional logic after the development server compilation is complete.
494
498
 
495
- - **Type:** `api.onDevCompileDone(compileFn: () => void | Promise<void>)`
496
- - **Parameters:**
497
- - `compileFn`: A function to be executed after compilation is complete.
498
- - **Execution Phase:** After the development server starts and the initial compilation is complete.
499
- - **Corresponding Rsbuild Hook:** [onDevCompileDone](https://rsbuild.dev/en/plugins/dev/hooks#ondevcompiledone)
500
- - **Example:**
499
+ - **Type:** `api.onDevCompileDone(compileFn: () => void | Promise<void>)`
500
+ - **Parameters:**
501
+ - `compileFn`: A function to be executed after compilation is complete.
502
+ - **Execution Phase:** After the development server starts and the initial compilation is complete.
503
+ - **Corresponding Rsbuild Hook:** [onDevCompileDone](https://rsbuild.rs/en/plugins/dev/hooks#ondevcompiledone)
504
+ - **Example:**
501
505
 
502
506
  ```typescript
503
507
  api.onDevCompileDone(() => {
504
- // Open the browser after the initial compilation is complete
508
+ // Open the browser after the initial compilation is complete
505
509
  });
506
510
  ```
511
+
507
512
  ---
508
513
 
509
514
  #### `api.onBeforeCreateCompiler`
510
515
 
511
516
  Add additional logic before creating the compiler instance.
512
517
 
513
- - **Type:** `api.onBeforeCreateCompiler(createFn: () => void | Promise<void>)`
514
- - **Parameters:**
515
- - `createFn`: A function to be executed before creation, without parameters, can be asynchronous.
516
- - **Execution Phase:** Before creating the Webpack or Rspack compiler instance.
517
- - **Corresponding Rsbuild Hook:** [onBeforeCreateCompiler](https://rsbuild.dev/en/plugins/dev/hooks#onbeforecreatecompiler)
518
- - **Example:**
518
+ - **Type:** `api.onBeforeCreateCompiler(createFn: () => void | Promise<void>)`
519
+ - **Parameters:**
520
+ - `createFn`: A function to be executed before creation, without parameters, can be asynchronous.
521
+ - **Execution Phase:** Before creating the Webpack or Rspack compiler instance.
522
+ - **Corresponding Rsbuild Hook:** [onBeforeCreateCompiler](https://rsbuild.rs/en/plugins/dev/hooks#onbeforecreatecompiler)
523
+ - **Example:**
519
524
 
520
525
  ```typescript
521
526
  api.onBeforeCreateCompiler(() => {
522
- // Can get compiler related configuration
527
+ // Can get compiler related configuration
523
528
  });
524
529
  ```
525
530
 
526
531
  ---
527
532
 
528
533
  #### `api.onAfterCreateCompiler`
534
+
529
535
  Add additional logic after creating the compiler instance.
530
536
 
531
- - **Type:** `api.onAfterCreateCompiler(createFn: () => void | Promise<void>)`
532
- - **Parameters:**
533
- - `createFn`: A function to be executed after creation, without parameters, can be asynchronous.
534
- - **Execution Phase:** After creating the Webpack or Rspack compiler instance.
535
- - **Corresponding Rsbuild Hook:** [onAfterCreateCompiler](https://rsbuild.dev/en/plugins/dev/hooks#onaftercreatecompiler)
536
- - **Example:**
537
+ - **Type:** `api.onAfterCreateCompiler(createFn: () => void | Promise<void>)`
538
+ - **Parameters:**
539
+ - `createFn`: A function to be executed after creation, without parameters, can be asynchronous.
540
+ - **Execution Phase:** After creating the Webpack or Rspack compiler instance.
541
+ - **Corresponding Rsbuild Hook:** [onAfterCreateCompiler](https://rsbuild.rs/en/plugins/dev/hooks#onaftercreatecompiler)
542
+ - **Example:**
537
543
 
538
544
  ```typescript
539
545
  api.onAfterCreateCompiler(() => {
540
- // Can get the compiler instance
546
+ // Can get the compiler instance
541
547
  });
542
548
  ```
543
549
 
@@ -568,15 +574,15 @@ Add additional logic after starting the development server.
568
574
 
569
575
  - **Type:** `api.onAfterDev(devFn: () => void | Promise<void>)`
570
576
  - **Parameters:**
571
- - `devFn`: A function to be executed after the development server starts.
577
+ - `devFn`: A function to be executed after the development server starts.
572
578
  - **Execution Phase:** After the development server has successfully started.
573
- - **Corresponding Rsbuild Hook:** [onAfterStartDevServer](https://rsbuild.dev/en/plugins/dev/hooks#onafterstartdevserver)
579
+ - **Corresponding Rsbuild Hook:** [onAfterStartDevServer](https://rsbuild.rs/en/plugins/dev/hooks#onafterstartdevserver)
574
580
  - **Example:**
575
581
 
576
582
  ```typescript
577
- api.onAfterDev(()=>{
578
- // Report dev related information
579
- })
583
+ api.onAfterDev(() => {
584
+ // Report dev related information
585
+ });
580
586
  ```
581
587
 
582
588
  ---
@@ -604,20 +610,20 @@ api.onBeforeExit(async () => {
604
610
 
605
611
  Add additional logic before printing success information.
606
612
 
607
- - **Type:** `api.onBeforePrintInstructions(printFn: ({instructions: string}) => {instructions: string} | Promise<{instructions: string}>)`
608
- - **Parameters:**
609
- - `printFn`: Function to modify the printed information, returns the modified information.
610
- - **Execution Phase:** Before printing success information.
611
- - **Example:**
613
+ - **Type:** `api.onBeforePrintInstructions(printFn: ({instructions: string}) => {instructions: string} | Promise<{instructions: string}>)`
614
+ - **Parameters:**
615
+ - `printFn`: Function to modify the printed information, returns the modified information.
616
+ - **Execution Phase:** Before printing success information.
617
+ - **Example:**
612
618
 
613
619
  ```typescript
614
620
  api.onBeforePrintInstructions(({ instructions }) => {
615
621
  // do something
616
- return { instructions }
622
+ return { instructions };
617
623
  });
618
624
  ```
619
625
 
620
626
  ## Other Notes
621
627
 
622
- - Refer to [CLI Plugin Lifecycle](./life-cycle.mdx) to understand the execution order of plugin hooks.
623
- - Refer to [CLI Plugin Migration Guide](./migration.mdx) to learn how to migrate from the old version of plugins to the new version.
628
+ - Refer to [CLI Plugin Lifecycle](./life-cycle.mdx) to understand the execution order of plugin hooks.
629
+ - Refer to [CLI Plugin Migration Guide](./migration.mdx) to learn how to migrate from the old version of plugins to the new version.
@@ -6,29 +6,30 @@ Modern.js provides a powerful plugin system that allows developers to extend the
6
6
 
7
7
  In web application development, we often encounter needs that the framework itself cannot directly satisfy, such as:
8
8
 
9
- - **I want to add a custom command-line tool to help me automate some tasks.**
10
- - **I want to be able to handle a new file format, such as `.xyz`.**
11
- - **I need to perform some initialization operations before the application starts.**
12
- - **I want to perform special processing on the generated CSS files.**
13
- - **I need to customize the application's routing logic or add some server-side middleware.**
9
+ - **I want to add a custom command-line tool to help me automate some tasks.**
10
+ - **I want to be able to handle a new file format, such as `.xyz`.**
11
+ - **I need to perform some initialization operations before the application starts.**
12
+ - **I want to perform special processing on the generated CSS files.**
13
+ - **I need to customize the application's routing logic or add some server-side middleware.**
14
14
 
15
- Without a plugin system, these requirements might require modifying the framework's source code or resorting to cumbersome hacks. Modern.js's plugin system offers an elegant, flexible, and maintainable solution.
15
+ Without a plugin system, these requirements might require modifying the framework's source code or resorting to cumbersome hacks. Modern.js's plugin system offers an elegant, flexible, and maintainable solution.
16
16
 
17
17
  ## When to Use Which Plugin?
18
18
 
19
- Modern.js offers two main types of plugins: Modern.js framework plugins and Rsbuild build plugins. The choice of which plugin to use depends on your specific needs:
19
+ Modern.js offers two main types of plugins: Modern.js framework plugins and Rsbuild build plugins. The choice of which plugin to use depends on your specific needs:
20
20
 
21
- - **Rsbuild Build Plugins:** If your needs are closely related to the build process, especially involving modifications to Webpack or Rspack configuration, then you should choose an Rsbuild plugin. For example:
22
- - Modifying Webpack/Rspack `loader` or `plugin` configurations.
23
- - Handling new file types.
24
- - Modifying or compiling file contents.
25
- - Optimizing or processing build artifacts.
21
+ - **Rsbuild Build Plugins:** If your needs are closely related to the build process, especially involving modifications to Webpack or Rspack configuration, then you should choose an Rsbuild plugin. For example:
26
22
 
27
- - **Modern.js Framework Plugins:** If your needs relate to the extension of Modern.js framework itself, runtime behavior, or server-side logic, then you should choose a Modern.js plugin. For example:
28
- - Adding custom command-line commands.
29
- - Modifying the application's routing configuration.
30
- - Customizing the application's rendering process (e.g., SSR).
31
- - Adding server-side middleware or handler functions.
23
+ - Modifying Webpack/Rspack `loader` or `plugin` configurations.
24
+ - Handling new file types.
25
+ - Modifying or compiling file contents.
26
+ - Optimizing or processing build artifacts.
27
+
28
+ - **Modern.js Framework Plugins:** If your needs relate to the extension of Modern.js framework itself, runtime behavior, or server-side logic, then you should choose a Modern.js plugin. For example:
29
+ - Adding custom command-line commands.
30
+ - Modifying the application's routing configuration.
31
+ - Customizing the application's rendering process (e.g., SSR).
32
+ - Adding server-side middleware or handler functions.
32
33
 
33
34
  In short, use Rsbuild plugins when you need to modify Webpack/Rspack configurations; use Modern.js plugins for other framework-related extensions.
34
35
 
@@ -69,13 +70,14 @@ export default defineRuntimeConfig({
69
70
  });
70
71
  ```
71
72
 
73
+ {/* prettier-ignore */}
72
74
  {/* #### Server Plugins
73
75
 
74
76
  Server plugins are used to provide additional functionality when the application receives requests, such as adding middleware and modifying request responses.
75
77
 
76
78
  Server plugins are configured via the `plugins` field in `server/modern.server.ts`.
77
79
 
78
- ```ts title="src/modern.server.ts"
80
+ ````ts title="src/modern.server.ts"
79
81
  import { defineConfig } from '@modern-js/app-tools/server';
80
82
  import bffPlugin from '@modern-js/plugin-bff/server';
81
83
 
@@ -106,13 +108,13 @@ Rsbuild is the underlying build tool for Modern.js. By adding Rsbuild plugins, y
106
108
  You can register Rsbuild plugins in `modern.config.ts` via the `builderPlugins` option. See [builderPlugins](/configure/app/builder-plugins.html) for details.
107
109
 
108
110
  :::tip
109
- Starting from `MAJOR_VERSION.46.0`, Modern.js upgraded its underlying build tool to [Rsbuild](https://rsbuild.dev/).
111
+ Starting from `MAJOR_VERSION.46.0`, Modern.js upgraded its underlying build tool to [Rsbuild](https://rsbuild.rs/).
110
112
 
111
113
  If your current version is lower than MAJOR_VERSION.46.0, you can upgrade by running `npx modern upgrade`.
112
114
  :::
113
115
 
114
116
  :::info
115
- You can read [Rsbuild Official Website - Plugins](https://rsbuild.dev/plugins/list/index) to learn more about the Rsbuild plugin system.
117
+ You can read [Rsbuild Official Website - Plugins](https://rsbuild.rs/plugins/list/index) to learn more about the Rsbuild plugin system.
116
118
  :::
117
119
 
118
120
  ### Official Plugins
@@ -123,10 +125,10 @@ The following are official Rsbuild plugins that are already built into Modern.js
123
125
 
124
126
  | Plugin | Description | Modern.js Link |
125
127
  | -------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
126
- | [React Plugin](https://rsbuild.dev/zh/plugins/list/plugin-react) | Provides support for React | - |
127
- | [SVGR Plugin](https://rsbuild.dev/zh/plugins/list/plugin-svgr) | Supports converting SVG images into React components | [output.disableSvgr](/configure/app/output/disable-svgr)<br />[output.svgDefaultExport](/configure/app/output/svg-default-export) |
128
+ | [React Plugin](https://rsbuild.rs/zh/plugins/list/plugin-react) | Provides support for React | - |
129
+ | [SVGR Plugin](https://rsbuild.rs/zh/plugins/list/plugin-svgr) | Supports converting SVG images into React components | [output.disableSvgr](/configure/app/output/disable-svgr)<br />[output.svgDefaultExport](/configure/app/output/svg-default-export) |
128
130
  | [Styled Components Plugin](https://github.com/rspack-contrib/rsbuild-plugin-styled-components) | Provides compile-time support for styled-components | [tools.styledComponents](/configure/app/tools/styled-components.html) |
129
- | [Assets Retry Plugin](https://rsbuild.dev/zh/plugins/list/plugin-assets-retry) | Automatically retries requests when static asset loading fails | [output.assetsRetry](/configure/app/output/assets-retry.html) |
131
+ | [Assets Retry Plugin](https://rsbuild.rs/zh/plugins/list/plugin-assets-retry) | Automatically retries requests when static asset loading fails | [output.assetsRetry](/configure/app/output/assets-retry.html) |
130
132
  | [Type Check Plugin](https://github.com/rspack-contrib/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) |
131
133
  | [Node Polyfill Plugin](https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill) | Injects polyfills for Node core modules in the browser | [output.disableNodePolyfill](/configure/app/output/disable-node-polyfill.html) |
132
134
  | [Source Build Plugin](https://github.com/rspack-contrib/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) |
@@ -142,9 +144,10 @@ The following are official Rsbuild plugins that are already built into Modern.js
142
144
  The following are official Rsbuild plugins that are not built into Modern.js:
143
145
 
144
146
  - [Image Compress Plugin](https://github.com/rspack-contrib/rsbuild-plugin-image-compress): Compresses image resources used in the project.
145
- - [Stylus Plugin](https://rsbuild.dev/zh/plugins/list/plugin-stylus): Uses Stylus as the CSS preprocessor.
147
+ - [Stylus Plugin](https://rsbuild.rs/zh/plugins/list/plugin-stylus): Uses Stylus as the CSS preprocessor.
146
148
  - [UMD Plugin](https://github.com/rspack-contrib/rsbuild-plugin-umd): Used to build UMD format artifacts.
147
149
 
148
150
  import OtherPlugins from '@site-docs-en/components/other-plugins.mdx';
149
151
 
150
152
  <OtherPlugins />
153
+ ````