@modern-js/main-doc 3.0.0-alpha.0 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/docs/en/apis/app/commands.mdx +6 -30
  2. package/docs/en/components/bff-upload.mdx +3 -5
  3. package/docs/en/components/bundler.mdx +1 -1
  4. package/docs/en/components/enable-bff.mdx +6 -2
  5. package/docs/en/components/enable-ssg.mdx +1 -0
  6. package/docs/en/components/esbuild.mdx +2 -2
  7. package/docs/en/components/extend-bff-function.mdx +2 -4
  8. package/docs/en/components/hono.mdx +119 -0
  9. package/docs/en/components/international/custom-instance-code.mdx +16 -0
  10. package/docs/en/components/international/init-options-desc.mdx +1 -0
  11. package/docs/en/components/international/install-command.mdx +15 -1
  12. package/docs/en/components/international/instance-code.mdx +26 -0
  13. package/docs/en/configure/app/builder-plugins.mdx +1 -2
  14. package/docs/en/configure/app/dev/server.mdx +108 -0
  15. package/docs/en/configure/app/experiments/source-build.mdx +0 -1
  16. package/docs/en/configure/app/output/assets-retry.mdx +1 -1
  17. package/docs/en/configure/app/output/disable-inline-runtime-chunk.mdx +2 -2
  18. package/docs/en/configure/app/output/filename.mdx +2 -4
  19. package/docs/en/configure/app/output/temp-dir.mdx +3 -3
  20. package/docs/en/configure/app/performance/build-cache.mdx +1 -1
  21. package/docs/en/configure/app/performance/profile.mdx +1 -1
  22. package/docs/en/configure/app/plugins.mdx +1 -3
  23. package/docs/en/configure/app/runtime/router.mdx +0 -4
  24. package/docs/en/configure/app/security/sri.mdx +0 -1
  25. package/docs/en/configure/app/source/alias.mdx +1 -1
  26. package/docs/en/configure/app/source/enable-async-entry.mdx +1 -1
  27. package/docs/en/configure/app/source/include.mdx +2 -14
  28. package/docs/en/configure/app/tools/dev-server.mdx +8 -8
  29. package/docs/en/configure/app/usage.mdx +0 -12
  30. package/docs/en/guides/_meta.json +5 -0
  31. package/docs/en/guides/advanced-features/bff/_meta.json +9 -1
  32. package/docs/en/guides/advanced-features/bff/cross-project.mdx +1 -1
  33. package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -15
  34. package/docs/en/guides/advanced-features/bff/function.mdx +4 -4
  35. package/docs/en/guides/advanced-features/bff/operators.mdx +628 -0
  36. package/docs/en/guides/advanced-features/bff/sdk.mdx +17 -9
  37. package/docs/en/guides/advanced-features/bff/upload.mdx +3 -1
  38. package/docs/en/guides/advanced-features/international/configuration.mdx +7 -16
  39. package/docs/en/guides/advanced-features/international/quick-start.mdx +4 -32
  40. package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +1 -1
  41. package/docs/en/guides/advanced-features/page-performance/react-compiler.mdx +18 -4
  42. package/docs/en/guides/advanced-features/rspack-start.mdx +1 -1
  43. package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +62 -5
  44. package/docs/en/guides/basic-features/data/data-cache.mdx +60 -76
  45. package/docs/en/guides/basic-features/data/data-fetch.mdx +15 -14
  46. package/docs/en/guides/basic-features/debug/proxy.mdx +6 -9
  47. package/docs/en/guides/basic-features/render/rsc.mdx +24 -19
  48. package/docs/en/guides/basic-features/render/ssg.mdx +4 -9
  49. package/docs/en/guides/basic-features/render/ssr-cache.mdx +0 -4
  50. package/docs/en/guides/basic-features/static-assets/svg-assets.mdx +0 -4
  51. package/docs/en/guides/get-started/tech-stack.mdx +1 -1
  52. package/docs/en/guides/upgrade/_meta.json +1 -0
  53. package/docs/en/guides/upgrade/config.mdx +936 -0
  54. package/docs/en/guides/upgrade/entry.mdx +463 -0
  55. package/docs/en/guides/upgrade/other.mdx +83 -0
  56. package/docs/en/guides/upgrade/overview.mdx +33 -0
  57. package/docs/en/guides/upgrade/tailwindcss.mdx +130 -0
  58. package/docs/en/guides/upgrade/web-server.mdx +91 -0
  59. package/docs/en/plugin/_meta.json +5 -0
  60. package/docs/en/plugin/cli-plugins/_meta.json +1 -1
  61. package/docs/en/plugin/cli-plugins/api.mdx +13 -63
  62. package/docs/en/plugin/cli-plugins/life-cycle.mdx +0 -4
  63. package/docs/en/plugin/introduction.mdx +8 -20
  64. package/docs/en/plugin/plugin-system.mdx +3 -3
  65. package/docs/en/plugin/runtime-plugins/_meta.json +1 -1
  66. package/docs/en/plugin/runtime-plugins/api.mdx +1 -1
  67. package/docs/en/plugin/server-plugins/_meta.json +1 -0
  68. package/docs/en/plugin/server-plugins/api.mdx +210 -1
  69. package/docs/en/plugin/server-plugins/life-cycle.mdx +41 -1
  70. package/docs/zh/apis/app/commands.mdx +6 -30
  71. package/docs/zh/components/bff-operator-code.mdx +5 -0
  72. package/docs/zh/components/bff-upload.mdx +0 -2
  73. package/docs/zh/components/bundler.mdx +1 -1
  74. package/docs/zh/components/enable-bff.mdx +6 -2
  75. package/docs/zh/components/enable-ssg.mdx +3 -1
  76. package/docs/zh/components/esbuild.mdx +2 -2
  77. package/docs/zh/components/extend-bff-function.mdx +2 -4
  78. package/docs/zh/components/hono.mdx +119 -0
  79. package/docs/zh/components/international/custom-instance-code.mdx +16 -0
  80. package/docs/zh/components/international/init-options-desc.mdx +1 -0
  81. package/docs/zh/components/international/install-command.mdx +15 -0
  82. package/docs/zh/components/international/instance-code.mdx +26 -0
  83. package/docs/zh/configure/app/builder-plugins.mdx +1 -2
  84. package/docs/zh/configure/app/dev/server.mdx +109 -2
  85. package/docs/zh/configure/app/experiments/source-build.mdx +0 -1
  86. package/docs/zh/configure/app/output/assets-retry.mdx +1 -1
  87. package/docs/zh/configure/app/output/disable-inline-runtime-chunk.mdx +2 -2
  88. package/docs/zh/configure/app/output/filename.mdx +2 -4
  89. package/docs/zh/configure/app/output/temp-dir.mdx +3 -3
  90. package/docs/zh/configure/app/performance/build-cache.mdx +1 -1
  91. package/docs/zh/configure/app/performance/profile.mdx +1 -1
  92. package/docs/zh/configure/app/plugins.mdx +1 -2
  93. package/docs/zh/configure/app/runtime/router.mdx +0 -4
  94. package/docs/zh/configure/app/security/sri.mdx +0 -1
  95. package/docs/zh/configure/app/source/alias.mdx +1 -1
  96. package/docs/zh/configure/app/source/enable-async-entry.mdx +1 -1
  97. package/docs/zh/configure/app/source/include.mdx +2 -16
  98. package/docs/zh/configure/app/tools/dev-server.mdx +5 -5
  99. package/docs/zh/configure/app/usage.mdx +0 -12
  100. package/docs/zh/guides/advanced-features/bff/_meta.json +9 -1
  101. package/docs/zh/guides/advanced-features/bff/frameworks.mdx +2 -16
  102. package/docs/zh/guides/advanced-features/bff/operators.mdx +628 -0
  103. package/docs/zh/guides/advanced-features/bff/sdk.mdx +19 -12
  104. package/docs/zh/guides/advanced-features/bff/upload.mdx +3 -1
  105. package/docs/zh/guides/advanced-features/international/configuration.mdx +7 -16
  106. package/docs/zh/guides/advanced-features/international/quick-start.mdx +2 -25
  107. package/docs/zh/guides/advanced-features/page-performance/optimize-bundle.mdx +1 -1
  108. package/docs/zh/guides/advanced-features/page-performance/react-compiler.mdx +18 -4
  109. package/docs/zh/guides/advanced-features/server-monitor/monitors.mdx +60 -5
  110. package/docs/zh/guides/basic-features/data/data-cache.mdx +47 -54
  111. package/docs/zh/guides/basic-features/data/data-fetch.mdx +9 -12
  112. package/docs/zh/guides/basic-features/debug/proxy.mdx +4 -7
  113. package/docs/zh/guides/basic-features/render/rsc.mdx +23 -37
  114. package/docs/zh/guides/basic-features/render/ssr-cache.mdx +0 -4
  115. package/docs/zh/guides/basic-features/static-assets/svg-assets.mdx +0 -4
  116. package/docs/zh/guides/get-started/tech-stack.mdx +1 -1
  117. package/docs/zh/guides/troubleshooting/builder.mdx +1 -1
  118. package/docs/zh/guides/upgrade/config.mdx +132 -1
  119. package/docs/zh/plugin/_meta.json +5 -0
  120. package/docs/zh/plugin/cli-plugins/_meta.json +1 -1
  121. package/docs/zh/plugin/cli-plugins/api.mdx +15 -65
  122. package/docs/zh/plugin/cli-plugins/life-cycle.mdx +0 -4
  123. package/docs/zh/plugin/introduction.mdx +4 -16
  124. package/docs/zh/plugin/plugin-system.mdx +3 -14
  125. package/docs/zh/plugin/runtime-plugins/_meta.json +1 -1
  126. package/docs/zh/plugin/runtime-plugins/api.mdx +1 -1
  127. package/docs/zh/plugin/server-plugins/_meta.json +1 -0
  128. package/docs/zh/plugin/server-plugins/api.mdx +210 -1
  129. package/docs/zh/plugin/server-plugins/life-cycle.mdx +41 -1
  130. package/package.json +2 -2
  131. package/src/components/FrameworkCode/index.tsx +605 -0
  132. package/docs/en/configure/app/performance/bundle-analyze.mdx +0 -24
  133. package/docs/en/configure/app/tools/babel.mdx +0 -225
  134. package/docs/en/plugin/cli-plugins/migration.mdx +0 -83
  135. package/docs/en/plugin/runtime-plugins/migration.mdx +0 -110
  136. package/docs/zh/components/default-mwa-generate.mdx +0 -4
  137. package/docs/zh/configure/app/performance/bundle-analyze.mdx +0 -24
  138. package/docs/zh/configure/app/tools/babel.mdx +0 -224
  139. package/docs/zh/plugin/cli-plugins/migration.mdx +0 -83
  140. package/docs/zh/plugin/runtime-plugins/migration.mdx +0 -110
  141. /package/docs/en/components/{router-legacy-tip.mdx → upgrade-config-deploy.mdx} +0 -0
  142. /package/docs/zh/components/{router-legacy-tip.mdx → upgrade-config-deploy.mdx} +0 -0
@@ -14,7 +14,6 @@ React Server Components (RSC) 是一种新的组件类型,允许在服务端
14
14
  - **自动代码分割**:基于实际渲染的数据进行代码分割,而不仅仅是路由,实现更精细的代码优化
15
15
  - **更高的内聚性**:与数据、权限、缓存等紧密相关的逻辑可以留在 Server Component 中,组件内聚度更高,减少状态上浮和跨层级传递
16
16
 
17
-
18
17
  :::tip 前置阅读
19
18
  在开始之前,建议你阅读 React 官方的 [Server Components 文档](https://react.dev/reference/rsc/server-components),对 Server Component 有一个基本的了解。
20
19
 
@@ -31,6 +30,7 @@ npm install react-server-dom-webpack
31
30
  ```
32
31
 
33
32
  :::warning 注意事项
33
+
34
34
  1. 目前暂不支持在 SPA 项目中使用 [Server Functions](https://react.dev/reference/rsc/server-functions)
35
35
  2. 目前在 Rspack 构建时,产物分片和体积还未达到最优状态,我们将在近期进一步优化
36
36
 
@@ -91,7 +91,7 @@ export default defineConfig({
91
91
  :::
92
92
 
93
93
  ```tsx title="components/InteractiveCard.tsx"
94
- "use client"; // <--- 这里是 Client Boundary 的起点
94
+ 'use client'; // <--- 这里是 Client Boundary 的起点
95
95
 
96
96
  import { useState } from 'react';
97
97
  import Button from './Button'; // Button.tsx 没有 "use client",但会被包含在客户端 bundle 中
@@ -143,7 +143,7 @@ export default async function Page() {
143
143
  ```
144
144
 
145
145
  ```tsx title="routes/CounterButton.tsx"
146
- "use client"; // Client Component
146
+ 'use client'; // Client Component
147
147
 
148
148
  import { useState } from 'react';
149
149
 
@@ -164,7 +164,7 @@ export default function CounterButton() {
164
164
  你可以将 Server Components 作为 `children` Prop 传递给一个 Client Component。假设一个带动画的 Tabs 组件,Tabs 的切换逻辑本身是客户端的,但每个标签页的内容可能是静态的、从服务器获取的。
165
165
 
166
166
  ```tsx title="app/components/Tabs.tsx"
167
- "use client"; // Client Component
167
+ 'use client'; // Client Component
168
168
 
169
169
  import React, { useState } from 'react';
170
170
 
@@ -199,7 +199,7 @@ import Analytics from '../components/Analytics'; // Server Component
199
199
  import UserSettings from '../components/UserSettings'; // Server Component
200
200
 
201
201
  export default function DashboardPage() {
202
- const labels = ["Analytics", "Settings"];
202
+ const labels = ['Analytics', 'Settings'];
203
203
 
204
204
  return (
205
205
  <main>
@@ -225,7 +225,7 @@ export default function DashboardPage() {
225
225
 
226
226
  每一级的路由组件(如 `layout.tsx`、`page.tsx`)可以独立选择是 Client Component 还是 Server Component:
227
227
 
228
- ```ts
228
+ ```bash
229
229
  - routes
230
230
  - layout.tsx // 可以是 Client Component
231
231
  - page.tsx // 可以是 Server Component
@@ -237,15 +237,13 @@ export default function DashboardPage() {
237
237
 
238
238
  ### 旧 CSR 项目
239
239
 
240
- 如果是 CSR 项目,且项目中使用了 EdenX 的 data loader,开启 RSC 后,data loader 默认是在服务端执行,这意味着需要先把所有的 `.data.ts` 文件改为`.data.client.ts`,才能和之前的行为保持一致。
241
-
242
-
240
+ 如果是 CSR 项目,且项目中使用了 EdenX 的 data loader,开启 RSC 后,data loader 默认是在服务端执行,这意味着需要先把所有的 `.data.ts` 文件改为`.data.client.ts`,才能和之前的行为保持一致。
243
241
 
244
242
  ### 使用 Streaming SSR 的项目
245
243
 
246
244
  如果你同时使用了 Streaming SSR 和 RSC,在 react19 中需要通过使用 `use`,而不再需要使用 `Await` 组件:
247
245
 
248
- ```typescript
246
+ ```ts
249
247
  function NonCriticalUI({ p }: { p: Promise<string> }) {
250
248
  let value = React.use(p);
251
249
  return <h3>Non critical value {value}</h3>;
@@ -256,45 +254,37 @@ function NonCriticalUI({ p }: { p: Promise<string> }) {
256
254
  </React.Suspense>
257
255
  ```
258
256
 
259
-
260
-
261
257
  ## 最佳实践
262
258
 
263
259
  ### 获取数据
264
260
 
265
- 1. 不管是 SSR 还是 RSC 项目,建议在服务端执行的数据获取逻辑默认使用 edenx 提供的 `cache` 函数,这样每一次服务端渲染,不管调用该函数多少次,只会执行一次。
261
+ 1. 不管是 SSR 还是 RSC 项目,建议在服务端执行的数据获取逻辑默认使用 Modern.js 提供的 `cache` 函数,这样每一次服务端渲染,不管调用该函数多少次,只会执行一次。
266
262
 
267
- > 这也是 react.js 推荐的用法,为此 react.js 提供了 [cache](https://react.dev/reference/react/cache) 函数,edenx 的 [cache](https://edenx.bytedance.net/guides/basic-features/data/data-cache.html) 可以视作其超集。
263
+ > 这也是 react.js 推荐的用法,为此 react.js 提供了 [cache](https://react.dev/reference/react/cache), Modern.js 的 [cache](/guides/basic-features/data/data-cache.html) 可以视作其超集。
268
264
 
269
265
  ```typescript
270
- import { cache } from '@edenx/runtime/cache'
266
+ import { cache } from '@modern-js/runtime/cache';
271
267
 
272
268
  const getCriticalCached = cache(getCritical);
273
269
  ```
274
270
 
275
-
276
-
277
- * 在使用 `cache` 函数的基础上,你不再需要通过 `props`,`context` 等管理服务端的状态,我们推荐哪个组件需要数据就在最近的 Server Component 中获取数据,通过 cache 函数,即使多次调用同一个函数,这样可以使项目的状态管理,业务逻辑,性能优化更简单。
271
+ - 在使用 `cache` 函数的基础上,你不再需要通过 `props`,`context` 等管理服务端的状态,我们推荐哪个组件需要数据就在最近的 Server Component 中获取数据,通过 cache 函数,即使多次调用同一个函数,这样可以使项目的状态管理,业务逻辑,性能优化更简单。
278
272
 
279
273
  ```typescript
280
274
  // layout.tsx
281
- export default async function Layout(){
282
- const criticalData = await getCriticalCached();
275
+ export default async function Layout() {
276
+ const criticalData = await getCriticalCached();
283
277
  }
284
278
 
285
- export default async function Page(){
286
- const criticalData = await getCriticalCached();
279
+ export default async function Page() {
280
+ const criticalData = await getCriticalCached();
287
281
  }
288
282
  ```
289
283
 
290
-
291
-
292
284
  ### 最佳性能
293
285
 
294
286
  为了发挥 RSC 或 Streaming SSR 的优势,我们需要使尽可能多的组件流动起来,一个核心原则是使 Suspense 包裹的区域尽可能地小(这也是我们推荐使用 `cache` 函数的原因之一)
295
287
 
296
-
297
-
298
288
  对于直接消费数据的 Server Component,我们推荐在其上层包裹 Suspense:
299
289
 
300
290
  > 这种场景下 Server Component 往往是异步的,还有一种情况 Server Component 为同步的,由 Client Component 消费数据,在下面进行描述
@@ -306,7 +296,9 @@ export default async function PostsList() {
306
296
 
307
297
  return (
308
298
  <ul>
309
- {posts.map(post => <li key={post.id}>{post.title}</li>)}
299
+ {posts.map(post => (
300
+ <li key={post.id}>{post.title}</li>
301
+ ))}
310
302
  </ul>
311
303
  );
312
304
  }
@@ -339,19 +331,19 @@ export default function ProfilePage() {
339
331
  }
340
332
  ```
341
333
 
342
-
343
-
344
334
  还有一种场景是在 Client Component 中消费数据,此时我们应避免在 Server Component 中使用 `await`,避免阻塞渲染:
345
335
 
346
336
  ```javascript
347
337
  // profile/components/PostsList.tsx
348
- 'use client'
338
+ 'use client';
349
339
  export default function PostsList({ postsPromise }) {
350
340
  const posts = use(postsPromise);
351
341
 
352
342
  return (
353
343
  <ul>
354
- {posts.map(post => <li key={post.id}>{post.title}</li>)}
344
+ {posts.map(post => (
345
+ <li key={post.id}>{post.title}</li>
346
+ ))}
355
347
  </ul>
356
348
  );
357
349
  }
@@ -386,11 +378,8 @@ export default function ProfilePage() {
386
378
  </div>
387
379
  );
388
380
  }
389
-
390
381
  ```
391
382
 
392
-
393
-
394
383
  ### Helmet
395
384
 
396
385
  当使用 react19 时,无需再使用 Helmet,推荐直接使用 react 提供的[组件](https://react.dev/reference/react-dom/components)。
@@ -401,7 +390,6 @@ export default function ProfilePage() {
401
390
 
402
391
  项目中的 bundle 引入了非 19 的 react 版本,常见于 monorepo。请确保所有依赖都使用 React 19 版本。
403
392
 
404
-
405
393
  ## 相关链接
406
394
 
407
395
  - [React Server Components 官方文档](https://react.dev/reference/rsc/server-components)
@@ -409,5 +397,3 @@ export default function ProfilePage() {
409
397
  - [数据缓存](/guides/basic-features/data/data-cache)
410
398
  - [服务端渲染(SSR)](/guides/basic-features/render/ssr)
411
399
  - [Streaming SSR](/guides/basic-features/render/streaming-ssr)
412
-
413
-
@@ -8,10 +8,6 @@ title: 渲染缓存
8
8
 
9
9
  Modern.js 支持将服务器端渲染(SSR)结果进行缓存,减少服务器每次请求时的计算和渲染时间,从而加速页面加载速度,提高用户体验。同时,缓存也能降低服务端负载,节省计算资源,提高用户访问速度。
10
10
 
11
- :::tip
12
- 需要 x.43.0+
13
- :::
14
-
15
11
  ## 配置方式
16
12
 
17
13
  在应用中创建 `server/cache.[t|j]s` 文件,并导出 `cacheOption` 配置缓存即可开启 SSR 渲染缓存:
@@ -32,10 +32,6 @@ import Logo from './logo.svg?react';
32
32
  export default () => <Logo />;
33
33
  ```
34
34
 
35
- :::tip
36
- Modern.js >= MAJOR_VERSION.48.3 版本支持上述用法。
37
- :::
38
-
39
35
  Modern.js 也支持以下用法,通过具名导入 `ReactComponent` 来转换 SVG 为 React 组件:
40
36
 
41
37
  ```tsx title="src/component/Logo.tsx"
@@ -34,7 +34,7 @@ Modern.js 使用 [Rspack](https://rspack.rs/) 来打包你的 Web 应用。
34
34
 
35
35
  Modern.js 使用 [SWC](https://swc.rs/) 作为 JS 转译工具,将 TypeScript 或 JSX 转义为可以在浏览器上运行的 JavaScript 代码,并进行语法降级。
36
36
 
37
- 在启用 Rspack 构建时,`babel-loader` 默认不会被启用。如需添加 [Babel](https://babeljs.io/) 插件,可通过 `tools.babel` 配置,此时会产生额外的编译开销,在一定程度上拖慢 Rspack 构建速度。
37
+ 在启用 Rspack 构建时,`babel-loader` 默认不会被启用。如需添加 [Babel](https://babeljs.io/) 插件,可通过 [`babel plugin`](https://rsbuild.rs/plugins/list/plugin-babel#babel-plugin) 配置,此时会产生额外的编译开销,在一定程度上拖慢 Rspack 构建速度。
38
38
 
39
39
  ## 压缩工具
40
40
 
@@ -182,7 +182,7 @@ import type { DebouncedFunc } from 'lodash';
182
182
 
183
183
  ### 升级 Modern.js 版本后,检查出新的 TypeScript 类型错误?
184
184
 
185
- 从 MAJOR_VERSION.47.0 版本开始,Modern.js 优化了 Type Checker 的检查范围。在之前的版本中,Type Checker 只输出 src 目录的类型错误,导致其他目录的类型错误无法被正确输出。
185
+ Modern.js 优化了 Type Checker 的检查范围。在之前的版本中,Type Checker 只输出 src 目录的类型错误,导致其他目录的类型错误无法被正确输出。
186
186
 
187
187
  在新版本中,Modern.js 的 Type Checker 对齐了原生 tsc 的类型检查范围(即 tsconfig.json 的 `include` 和 `exclude` 字段定义的范围),能够完整输出项目中的类型错误。
188
188
 
@@ -341,6 +341,53 @@ export default {
341
341
  };
342
342
  ```
343
343
 
344
+ ### tools.babel
345
+
346
+ **变更内容**: 该配置已废弃,框架不再内置 Babel,请使用 [Rsbuild 的 Babel 插件](https://v0.rsbuild.rs/plugins/list/plugin-babel) 来启用支持。
347
+
348
+ **迁移示例**:
349
+
350
+ ```typescript
351
+ // v2
352
+ tools: {
353
+ babel: {
354
+ plugins: [
355
+ [
356
+ 'babel-plugin-import',
357
+ {
358
+ libraryName: 'xxx-components',
359
+ libraryDirectory: 'es',
360
+ style: true,
361
+ },
362
+ ],
363
+ ],
364
+ },
365
+ }
366
+
367
+ // v3
368
+ import { pluginBabel } from '@rsbuild/plugin-babel';
369
+
370
+ export default {
371
+ // ...
372
+ builderPlugins: [
373
+ pluginBabel({
374
+ babelLoaderOptions: {
375
+ plugins: [
376
+ [
377
+ 'babel-plugin-import',
378
+ {
379
+ libraryName: 'my-components',
380
+ libraryDirectory: 'es',
381
+ style: true,
382
+ },
383
+ ],
384
+ ],
385
+ },
386
+ })
387
+ ];
388
+ }
389
+ ```
390
+
344
391
  ### tools.tailwindcss
345
392
 
346
393
  **变更内容**: 该配置已废弃,请参考 [Tailwind 插件变更](/guides/upgrade/tailwindcss),使用 Rsbuild 的方式来接入 Tailwind CSS。
@@ -734,6 +781,10 @@ export default {
734
781
  };
735
782
  ```
736
783
 
784
+ import ConfigDeploy from '@site-docs/components/upgrade-config-deploy.mdx';
785
+
786
+ <ConfigDeploy />
787
+
737
788
  ## plugins
738
789
 
739
790
  ### app-tools 插件
@@ -756,18 +807,98 @@ plugins: [
756
807
  ],
757
808
  ```
758
809
 
810
+ ## security
811
+
812
+ ### security.sri
813
+
814
+ **变更内容**: `security.sri.hashLoading` 不再需要,可以直接移除。
815
+
759
816
  ## runtime
760
817
 
761
818
  ### runtime.router
762
819
 
763
- **变更内容**: 不再需要,可以直接移除。
820
+ **变更内容**: 不再需要,可以直接移除。该配置移动到 modern.runtime.ts 中的 router 配置中。
821
+
822
+ **迁移示例**:
823
+
824
+ ```typescript
825
+ // v2
826
+ // modern.config.ts
827
+ export default {
828
+ runtime: {
829
+ router: {
830
+ // 路由配置
831
+ },
832
+ },
833
+ };
834
+
835
+ // v3
836
+ // modern.runtime.ts
837
+ import { defineRuntimeConfig } from '@modern-js/runtime';
838
+
839
+ export default defineRuntimeConfig({
840
+ router: {
841
+ // 路由配置
842
+ },
843
+ });
844
+ ```
764
845
 
765
846
  ### runtime.state
766
847
 
767
848
  **变更内容**: 该配置被废弃,建议使用第三方状态管理库。
768
849
 
850
+ ### runtime.masterApp
851
+
852
+ **变更内容**: 该配置被废弃,将该配置移动到 modern.runtime.ts 中的 masterApp 配置。
853
+
854
+ **迁移示例**:
855
+
856
+ ```typescript
857
+ // v2
858
+ // modern.config.ts
859
+ export default {
860
+ runtime: {
861
+ masterApp: {
862
+ apps: [
863
+ {
864
+ name: 'Table',
865
+ entry: 'http://localhost:8081',
866
+ },
867
+ {
868
+ name: 'Dashboard',
869
+ entry: 'http://localhost:8082',
870
+ },
871
+ ],
872
+ },
873
+ },
874
+ };
875
+
876
+ // v3
877
+ // modern.runtime.ts
878
+ import { defineRuntimeConfig } from '@modern-js/runtime';
879
+
880
+ export default defineRuntimeConfig({
881
+ masterApp: {
882
+ apps: [
883
+ {
884
+ name: 'Table',
885
+ entry: 'http://localhost:8081',
886
+ },
887
+ {
888
+ name: 'Dashboard',
889
+ entry: 'http://localhost:8082',
890
+ },
891
+ ],
892
+ },
893
+ });
894
+ ```
895
+
769
896
  ## performance
770
897
 
898
+ ### performance.bundleAnalyze
899
+
900
+ **变更内容**: 该配置已废弃,建议使用 [Rsdoctor](https://rsbuild.rs/zh/guide/debug/rsdoctor) 来分析产物体积
901
+
771
902
  ### performance.transformLodash
772
903
 
773
904
  **变更内容**: 不再需要,可以直接移除。
@@ -11,6 +11,11 @@
11
11
  "name": "runtime-plugins",
12
12
  "label": "runtime-plugins"
13
13
  },
14
+ {
15
+ "type": "dir",
16
+ "name": "server-plugins",
17
+ "label": "server-plugins"
18
+ },
14
19
  {
15
20
  "type": "dir",
16
21
  "name": "official",
@@ -1 +1 @@
1
- ["api", "life-cycle", "migration"]
1
+ ["api", "life-cycle"]
@@ -1,6 +1,6 @@
1
1
  # 插件 API
2
2
 
3
- 本文档详细介绍了 Modern.js CLI 插件的 API。CLI 插件允许您在 Modern.js 项目的构建和开发过程中扩展和定制功能。
3
+ Modern.js CLI 插件允许您在 Modern.js 项目的构建和开发过程中扩展和定制功能。
4
4
 
5
5
  :::info
6
6
 
@@ -28,7 +28,8 @@ const myCliPlugin = (): CliPlugin<AppTools> => ({
28
28
  export default myCliPlugin;
29
29
  ```
30
30
 
31
- `setup` 函数接收一个 `api` 对象,该对象提供了所有可用的 CLI 插件 API。
31
+ - `name`: 插件的唯一标识符。
32
+ - `setup` 函数接收一个 `api` 对象,该对象提供了所有可用的 CLI 插件 API。
32
33
 
33
34
  ## 信息获取
34
35
 
@@ -54,7 +55,7 @@ export default myCliPlugin;
54
55
  | `plugins` | `object[]` | 当前已注册的插件列表 | - |
55
56
  | `entrypoints` | `object[]` | 页面入口信息 | - |
56
57
  | `serverRoutes` | `object[]` | 服务端路由信息 | - |
57
- | `bundlerType` | `webpack \| rspack` | 当前使用的打包工具类型 (`webpack` 或 `rspack`) | `onPrepare` 之后 |
58
+ | `bundlerType` | `rspack` | 当前使用的打包工具类型 | `onPrepare` 之后 |
58
59
  | `metaName` | `string` | 框架内部名称 | - |
59
60
  | `apiDirectory` | `string` | API 模块目录的绝对路径 (BFF 使用) | - |
60
61
  | `lambdaDirectory` | `string` | Lambda 模块目录的绝对路径 (BFF 使用) | - |
@@ -186,12 +187,12 @@ api.config(() => {
186
187
 
187
188
  #### `api.modifyBundlerChain`
188
189
 
189
- 使用 chain API 修改 webpack 或者 Rspack 配置。
190
+ 使用 chain API 修改 Rspack 配置。
190
191
 
191
- - **类型:** `api.modifyBundlerChain(modifyFn: (chain: WebpackChain | RspackChain, utils: WebpackUtils | RspackUtils) => void | Promise<void>)`
192
+ - **类型:** `api.modifyBundlerChain(modifyFn: (chain: RspackChain, utils: RspackUtils) => void | Promise<void>)`
192
193
  - **参数:**
193
- - `modifyFn`: 修改函数,接收 `webpack-chain` 或 `RspackChain` 实例和实用工具作为参数。
194
- - **执行阶段:** 在生成最终的 Webpack 或 Rspack 配置时。
194
+ - `modifyFn`: 修改函数,接收 `RspackChain` 实例和实用工具作为参数。
195
+ - **执行阶段:** 在生成最终的 Rspack 配置时。
195
196
  - **对应 Rsbuild Hook**: [modifybundlerchain](https://rsbuild.rs/zh/plugins/dev/hooks#modifybundlerchain)
196
197
  - **示例:**
197
198
 
@@ -236,7 +237,7 @@ api.modifyRsbuildConfig((config, utils) => {
236
237
  - **示例:**
237
238
 
238
239
  ```typescript
239
- api.modifyRspackConfig((config utils) => {
240
+ api.modifyRspackConfig((config, utils) => {
240
241
  config.builtins.minify = {
241
242
  enable: true,
242
243
  implementation: utils.rspack.SwcJsMinimizerRspackPlugin,
@@ -246,66 +247,16 @@ api.modifyRspackConfig((config, utils) => {
246
247
 
247
248
  ---
248
249
 
249
- #### `api.modifyWebpackChain`
250
-
251
- 使用 [webpack-chain](https://github.com/neutrinojs/webpack-chain) 修改 Webpack 配置。(当使用 Webpack 作为打包工具时)
252
-
253
- - **类型:** `api.modifyWebpackChain(modifyFn: (chain: WebpackChain, utils: WebpackUtils) => void | Promise<void>)`
254
- - **参数:**
255
- - `modifyFn`: 修改函数,接收 `webpack-chain` 实例和实用工具作为参数。
256
- - **执行阶段:** 在生成最终的 Webpack 配置时。
257
- - **示例:**
250
+ **构建配置修改顺序**
258
251
 
259
- ```typescript
260
- api.modifyWebpackChain((chain, utils) => {
261
- // 添加一个自定义的 Webpack loader
262
- chain.module
263
- .rule('my-loader')
264
- .test(/\.my-ext$/)
265
- .use('my-loader')
266
- .loader(require.resolve('./my-loader'));
267
- });
268
252
  ```
269
-
270
- ---
271
-
272
- #### `api.modifyWebpackConfig`
273
-
274
- 直接修改 Webpack 配置对象。(当使用 Webpack 作为打包工具时)
275
-
276
- - **类型:** `api.modifyWebpackConfig(modifyFn: (config: WebpackConfig, utils: WebpackUtils) => WebpackConfig | Promise<WebpackConfig> | void)`
277
- - **参数:**
278
- - `modifyFn`: 修改函数,接收 Webpack 配置对象和实用工具作为参数,可以返回修改后的配置对象、Promise 或不返回(直接修改原对象)。
279
- - **执行阶段:** 在生成最终的 Webpack 配置时。
280
- - **示例:**
281
-
282
- ```typescript
283
- api.modifyWebpackConfig((config, utils) => {
284
- // 禁用 source map
285
- config.devtool = false;
286
- });
253
+ modifyRsbuildConfig
254
+ modifyBundlerChain
255
+ tools.bundlerChain
256
+ modifyRspackConfig
257
+ tools.rspack
287
258
  ```
288
259
 
289
- **构建配置修改顺序**
290
-
291
- - **使用 Rspack 构建**:
292
- ```
293
- modifyRsbuildConfig
294
- modifyBundlerChain
295
- tools.bundlerChain
296
- modifyRspackConfig
297
- tools.rspack
298
- ```
299
- - **使用 Webpack 构建**:
300
- ```
301
- modifyBundlerChain
302
- tools.bundlerChain
303
- modifyWebpackChain
304
- tools.webpackChain
305
- modifyWebpackConfig
306
- tools.webpack
307
- ```
308
-
309
260
  ---
310
261
 
311
262
  #### `api.modifyServerRoutes`
@@ -621,4 +572,3 @@ api.onBeforePrintInstructions(({ instructions }) => {
621
572
  ## 其他说明
622
573
 
623
574
  - 可以参考 [CLI 插件生命周期](./life-cycle.mdx) 了解插件钩子的执行顺序。
624
- - 可以参考 [CLI 插件迁移指南](./migration.mdx) 了解如何从旧版插件迁移到新版。
@@ -36,8 +36,6 @@ flowchart TD
36
36
  modifyBundlerChain(modifyBundlerChain)
37
37
  modifyRsbuildConfig(modifyRsbuildConfig)
38
38
  modifyRspackConfig(modifyRspackConfig)
39
- modifyWebpackChain(modifyWebpackChain)
40
- modifyWebpackConfig(modifyWebpackConfig)
41
39
 
42
40
  onBeforeBuild_rsbuild(onBeforeBuild)
43
41
  onAfterBuild_rsbuild(onAfterBuild)
@@ -63,8 +61,6 @@ flowchart TD
63
61
  registry_rsbuild_hooks --> modifyBundlerChain
64
62
  modifyBundlerChain --> modifyRsbuildConfig
65
63
  modifyRsbuildConfig --> modifyRspackConfig
66
- modifyRspackConfig --> modifyWebpackChain
67
- modifyWebpackChain --> modifyWebpackConfig
68
64
  registry_rsbuild_hooks --> onBeforeBuild_rsbuild
69
65
  onBeforeBuild_rsbuild --> onAfterBuild_rsbuild
70
66
  onAfterBuild_rsbuild --> onDevCompileDone
@@ -18,20 +18,20 @@ Modern.js 提供了一套强大的插件体系,允许开发者通过编写插
18
18
 
19
19
  Modern.js 提供了两种主要的插件类型:Modern.js 框架插件和 Rsbuild 构建插件。选择哪种插件取决于你的具体需求:
20
20
 
21
- - **Rsbuild 构建插件:** 如果你的需求与构建过程密切相关,特别是涉及到 Webpack 或 Rspack 配置的修改,那么你应该选择 Rsbuild 插件。例如:
21
+ - **Rsbuild 构建插件:** 如果你的需求与构建过程密切相关,特别是涉及到 Rspack 配置的修改,那么你应该选择 Rsbuild 插件。例如:
22
22
 
23
- - 修改 Webpack/Rspack 的 `loader` 或 `plugin` 配置。
23
+ - 修改 Rspack 的 `loader` 或 `plugin` 配置。
24
24
  - 处理新的文件类型。
25
25
  - 修改或编译文件内容。
26
26
  - 对构建产物进行优化或处理。
27
27
 
28
28
  - **Modern.js 框架插件:** 如果你的需求与 Modern.js 框架本身的功能扩展、运行时行为或服务端逻辑相关,那么你应该选择 Modern.js 插件。例如:
29
29
  - 添加自定义的命令行命令。
30
- - 修改应用的路由配置。
30
+ - 修改运行时信息。
31
31
  - 定制化应用的渲染过程(如 SSR)。
32
32
  - 添加服务端中间件或处理函数。
33
33
 
34
- 简单来说,需要修改 Webpack/Rspack 配置时,使用 Rsbuild 插件;其他与框架相关的功能扩展,使用 Modern.js 插件。
34
+ 简单来说,需要修改 Rspack 配置时,使用 Rsbuild 插件;其他与框架相关的功能扩展,使用 Modern.js 插件。
35
35
 
36
36
  ## Modern.js 框架插件
37
37
 
@@ -101,12 +101,6 @@ export default defineServerConfig({
101
101
  });
102
102
  ```
103
103
 
104
- :::tip
105
- Modern.js 从 `MAJOR_VERSION.66.0` 起正式对外使用新的插件机制。
106
-
107
- 如果你的当前版本低于 MAJOR_VERSION.66.0,可通过执行 `npx modern upgrade` 进行升级。
108
- :::
109
-
110
104
  ### 开发插件
111
105
 
112
106
  如果你需要开发 Modern.js 框架插件,请阅读 [Modern.js 插件系统](/plugin/plugin-system) 获取更多信息。
@@ -122,12 +116,6 @@ Rsbuild 是 Modern.js 底层的构建工具,通过添加 Rsbuild 插件可修
122
116
 
123
117
  你可以在 `modern.config.ts` 中通过 `builderPlugins` 选项注册 Rsbuild 插件,详见 [builderPlugins 构建插件](/configure/app/builder-plugins.html)。
124
118
 
125
- :::tip
126
- Modern.js 从 `MAJOR_VERSION.46.0` 起,底层构建工具升级为 [Rsbuild](https://rsbuild.rs/)。
127
-
128
- 如果你的当前版本低于 MAJOR_VERSION.46.0,可通过执行 `npx modern upgrade` 进行升级。
129
- :::
130
-
131
119
  :::info
132
120
  可以阅读 [Rsbuild 官网 - 插件](https://rsbuild.rs/plugins/list/index) 了解更多 Rsbuild 插件体系内容。
133
121
  :::
@@ -57,12 +57,12 @@ const myPlugin: Plugin = {
57
57
  usePlugins: [], // 内部使用的插件实例列表,默认为空数组
58
58
 
59
59
  // 注册新的 Hook (可选)
60
- registryHook: {},
60
+ registryHooks: {},
61
61
 
62
62
  // 插件的入口函数(必需)
63
63
  setup(api) {
64
64
  // 插件的核心逻辑,通过 api 对象调用插件 API
65
- api.modifyWebpackConfig(config => {
65
+ api.modifyRspackConfig(config => {
66
66
  /* ... */
67
67
  });
68
68
  api.onPrepare(() => {
@@ -173,7 +173,7 @@ const myPlugin2 = () => ({
173
173
  name: 'my-plugin-2',
174
174
  setup: api => {
175
175
  api.onAfterPrepare(async () => {
176
- // TOOD
176
+ // TODO
177
177
  });
178
178
  },
179
179
  });
@@ -214,17 +214,6 @@ const myPlugin = () => ({
214
214
  });
215
215
  },
216
216
  });
217
-
218
- // 其他插件使用 Hooks
219
- const myPlugin2 = () => ({
220
- name: 'my-plugin',
221
- setup: api => {
222
- api.modifyRoutes(async routes => {
223
- // 修改 routes
224
- return routes;
225
- });
226
- },
227
- });
228
217
  ```
229
218
 
230
219
  ## 插件开发最佳实践
@@ -1 +1 @@
1
- ["api", "life-cycle", "migration"]
1
+ ["api", "life-cycle"]
@@ -37,7 +37,7 @@ export default myRuntimePlugin;
37
37
  ```
38
38
 
39
39
  - `name`: 插件的唯一标识符。
40
- - `setup`: 插件的主要逻辑,接收一个 `api` 对象作为参数,用于注册钩子。
40
+ - `setup`: 函数接收一个 `api` 对象,该对象提供了所有可用的 Runtime 插件 API。
41
41
 
42
42
  ## API 概览
43
43
 
@@ -0,0 +1 @@
1
+ ["api", "life-cycle"]