@modern-js/main-doc 2.59.0 → 2.60.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. package/docs/en/_meta.json +10 -5
  2. package/docs/en/apis/app/hooks/api/lambda.mdx +4 -48
  3. package/docs/en/apis/app/hooks/api/middleware.mdx +11 -0
  4. package/docs/en/community/blog/v2-release-note.mdx +1 -1
  5. package/docs/en/components/enable-bff.mdx +19 -2
  6. package/docs/en/components/extend-bff-function.mdx +5 -0
  7. package/docs/en/components/other-plugins.mdx +0 -0
  8. package/docs/en/configure/app/auto-load-plugin.mdx +4 -0
  9. package/docs/en/configure/app/plugins.mdx +2 -2
  10. package/docs/en/configure/app/tools/esbuild.mdx +1 -1
  11. package/docs/en/configure/app/tools/swc.mdx +1 -1
  12. package/docs/en/guides/_meta.json +0 -5
  13. package/docs/en/guides/advanced-features/_meta.json +7 -4
  14. package/docs/en/guides/advanced-features/bff/_meta.json +1 -1
  15. package/docs/en/guides/advanced-features/bff/extend-server.mdx +154 -0
  16. package/docs/en/guides/advanced-features/bff/frameworks.mdx +52 -123
  17. package/docs/en/guides/advanced-features/bff/function.mdx +108 -80
  18. package/docs/en/guides/advanced-features/bff/sdk.mdx +40 -51
  19. package/docs/en/guides/advanced-features/build-performance.mdx +6 -21
  20. package/docs/en/guides/advanced-features/page-performance/_meta.json +1 -0
  21. package/docs/en/guides/basic-features/render/streaming-ssr.mdx +1 -1
  22. package/docs/en/guides/basic-features/routes.mdx +2 -3
  23. package/docs/en/guides/basic-features/static-assets.mdx +1 -1
  24. package/docs/en/guides/deprecated.md +2 -0
  25. package/docs/en/guides/topic-detail/_meta.json +0 -6
  26. package/docs/en/plugin/_meta.json +19 -0
  27. package/docs/en/plugin/cli-plugins/_meta.json +1 -0
  28. package/docs/en/plugin/cli-plugins/plugin-bff.mdx +5 -0
  29. package/docs/en/plugin/cli-plugins/plugin-ssg.mdx +5 -0
  30. package/docs/en/{guides/rsbuild-plugins → plugin/cli-plugins}/plugin-swc.mdx +7 -0
  31. package/docs/en/plugin/cli-plugins/plugin-tailwind.mdx +5 -0
  32. package/docs/en/plugin/cli-plugins.mdx +6 -0
  33. package/docs/en/{guides/advanced-features/rsbuild-plugin.mdx → plugin/introduction.mdx} +34 -9
  34. package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/extend.mdx +1 -1
  35. package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/implement.mdx +3 -3
  36. package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/plugin-api.mdx +2 -2
  37. package/docs/en/plugin/rsbuild-plugins/_meta.json +1 -0
  38. package/docs/en/plugin/rsbuild-plugins.mdx +3 -0
  39. package/docs/zh/_meta.json +10 -5
  40. package/docs/zh/apis/app/hooks/api/lambda.mdx +5 -48
  41. package/docs/zh/apis/app/hooks/api/middleware.mdx +11 -0
  42. package/docs/zh/community/blog/v2-release-note.mdx +1 -1
  43. package/docs/zh/components/enable-bff.mdx +19 -2
  44. package/docs/zh/components/extend-bff-function.mdx +5 -0
  45. package/docs/zh/components/other-plugins.mdx +0 -0
  46. package/docs/zh/configure/app/auto-load-plugin.mdx +4 -0
  47. package/docs/zh/configure/app/plugins.mdx +2 -2
  48. package/docs/zh/configure/app/tools/esbuild.mdx +1 -1
  49. package/docs/zh/configure/app/tools/swc.mdx +1 -1
  50. package/docs/zh/guides/_meta.json +0 -5
  51. package/docs/zh/guides/advanced-features/_meta.json +7 -4
  52. package/docs/zh/guides/advanced-features/bff/_meta.json +1 -1
  53. package/docs/zh/guides/advanced-features/bff/extend-server.mdx +156 -0
  54. package/docs/zh/guides/advanced-features/bff/frameworks.mdx +51 -117
  55. package/docs/zh/guides/advanced-features/bff/function.mdx +69 -59
  56. package/docs/zh/guides/advanced-features/bff/sdk.mdx +27 -36
  57. package/docs/zh/guides/advanced-features/build-performance.mdx +6 -21
  58. package/docs/zh/guides/advanced-features/page-performance/_meta.json +1 -0
  59. package/docs/zh/guides/advanced-features/rspack-start.mdx +2 -2
  60. package/docs/zh/guides/basic-features/alias.mdx +5 -11
  61. package/docs/zh/guides/basic-features/env-vars.mdx +1 -1
  62. package/docs/zh/guides/basic-features/routes.mdx +1 -2
  63. package/docs/zh/guides/basic-features/static-assets.mdx +1 -1
  64. package/docs/zh/guides/deprecated.md +4 -0
  65. package/docs/zh/guides/topic-detail/_meta.json +0 -6
  66. package/docs/zh/plugin/_meta.json +19 -0
  67. package/docs/zh/plugin/cli-plugins/_meta.json +1 -0
  68. package/docs/zh/plugin/cli-plugins/plugin-bff.mdx +5 -0
  69. package/docs/zh/plugin/cli-plugins/plugin-ssg.mdx +5 -0
  70. package/docs/zh/{guides/rsbuild-plugins → plugin/cli-plugins}/plugin-swc.mdx +7 -0
  71. package/docs/zh/plugin/cli-plugins/plugin-tailwind.mdx +5 -0
  72. package/docs/zh/plugin/cli-plugins.mdx +6 -0
  73. package/docs/zh/{guides/advanced-features/rsbuild-plugin.mdx → plugin/introduction.mdx} +36 -11
  74. package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/extend.mdx +1 -1
  75. package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/implement.mdx +3 -3
  76. package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/plugin-api.mdx +2 -2
  77. package/docs/zh/plugin/rsbuild-plugins/_meta.json +1 -0
  78. package/docs/zh/plugin/rsbuild-plugins.mdx +4 -0
  79. package/i18n.json +27 -3
  80. package/package.json +5 -4
  81. package/rspress.config.ts +1 -58
  82. package/src/components/Footer/index.tsx +1 -1
  83. package/src/pages/index.tsx +0 -1
  84. package/docs/en/apis/app/hooks/api/api.mdx +0 -80
  85. package/docs/en/apis/app/hooks/api/app.mdx +0 -12
  86. package/docs/en/guides/advanced-features/bff/type.mdx +0 -46
  87. package/docs/en/guides/advanced-features/eslint.mdx +0 -148
  88. package/docs/zh/apis/app/hooks/api/api.mdx +0 -81
  89. package/docs/zh/apis/app/hooks/api/app.mdx +0 -12
  90. package/docs/zh/guides/advanced-features/bff/type.mdx +0 -46
  91. package/docs/zh/guides/advanced-features/eslint.mdx +0 -152
  92. /package/docs/en/guides/advanced-features/{bff/index.mdx → bff.mdx} +0 -0
  93. /package/docs/en/guides/advanced-features/{code-split.mdx → page-performance/code-split.mdx} +0 -0
  94. /package/docs/en/guides/advanced-features/{inline-assets.mdx → page-performance/inline-assets.mdx} +0 -0
  95. /package/docs/en/guides/advanced-features/{optimize-bundle.mdx → page-performance/optimize-bundle.mdx} +0 -0
  96. /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/_meta.json +0 -0
  97. /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook-list.mdx +0 -0
  98. /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook.mdx +0 -0
  99. /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/introduction.mdx +0 -0
  100. /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/lifecycle.mdx +0 -0
  101. /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/relationship.mdx +0 -0
  102. /package/docs/en/{guides → plugin}/rsbuild-plugins/plugin-esbuild.mdx +0 -0
  103. /package/docs/zh/guides/advanced-features/{bff/index.mdx → bff.mdx} +0 -0
  104. /package/docs/zh/guides/advanced-features/{code-split.mdx → page-performance/code-split.mdx} +0 -0
  105. /package/docs/zh/guides/advanced-features/{inline-assets.mdx → page-performance/inline-assets.mdx} +0 -0
  106. /package/docs/zh/guides/advanced-features/{optimize-bundle.mdx → page-performance/optimize-bundle.mdx} +0 -0
  107. /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/_meta.json +0 -0
  108. /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook-list.mdx +0 -0
  109. /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook.mdx +0 -0
  110. /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/introduction.mdx +0 -0
  111. /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/lifecycle.mdx +0 -0
  112. /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/relationship.mdx +0 -0
  113. /package/docs/zh/{guides → plugin}/rsbuild-plugins/plugin-esbuild.mdx +0 -0
@@ -15,9 +15,7 @@ sidebar_position: 4
15
15
 
16
16
  ## 通过 `tsconfig.json` 的 `paths` 配置
17
17
 
18
- 你可以通过 `tsconfig.json` 中的 `paths` 来配置别名,这是我们在 TypeScript 项目中推荐使用的方式,因为它可以解决路径别名的 TS 类型问题。
19
-
20
- 比如:
18
+ 你可以通过 `tsconfig.json` 中的 `paths` 来配置别名,这是我们在 TypeScript 项目中推荐使用的方式,因为它可以解决路径别名的 TS 类型问题。比如:
21
19
 
22
20
  ```json title="tsconfig.json"
23
21
  {
@@ -29,7 +27,7 @@ sidebar_position: 4
29
27
  }
30
28
  ```
31
29
 
32
- 以上配置完成后,如果你在代码中引用 `@common/Foo.tsx`, 则会映射到 `<project>/src/common/Foo.tsx` 路径上。
30
+ 以上配置完成后,如果你在代码中引用 `@common/Foo.tsx`,则会映射到 `<project>/src/common/Foo.tsx` 路径上。
33
31
 
34
32
  :::tip
35
33
  你可以阅读 [TypeScript - paths](https://www.typescriptlang.org/tsconfig#paths) 文档来了解更多用法。
@@ -47,9 +45,7 @@ Modern.js 提供了 [source.alias](/configure/app/source/alias) 配置项,对
47
45
 
48
46
  ### 对象用法
49
47
 
50
- 你可以通过对象的方式来配置 `source.alias`,其中的相对路径会被自动补全为绝对路径。
51
-
52
- 比如:
48
+ 你可以通过对象的方式来配置 `source.alias`,其中的相对路径会被自动补全为绝对路径。比如:
53
49
 
54
50
  ```js
55
51
  export default {
@@ -61,13 +57,11 @@ export default {
61
57
  };
62
58
  ```
63
59
 
64
- 以上配置完成后,如果你在代码中引用 `@common/Foo.tsx`, 则会映射到 `<project>/src/common/Foo.tsx` 路径上。
60
+ 以上配置完成后,如果你在代码中引用 `@common/Foo.tsx`,则会映射到 `<project>/src/common/Foo.tsx` 路径上。
65
61
 
66
62
  ### 函数用法
67
63
 
68
- 你也可以将 `source.alias` 配置为一个函数,拿到内置的 `alias` 对象,对其进行修改。
69
-
70
- 比如:
64
+ 你也可以将 `source.alias` 配置为一个函数,拿到内置的 `alias` 对象,对其进行修改。比如:
71
65
 
72
66
  ```js
73
67
  export default {
@@ -61,7 +61,7 @@ function App() {
61
61
  }
62
62
  ```
63
63
 
64
- 这种方式可以针对不同客户端提供不同的产物,保证代码体积最小化;也便于处理不同环境下代码中的一些副作用。
64
+ 这种方式可以针对不同客户端提供不同的产物,保证代码体积最小化,也便于处理不同环境下代码中的一些副作用。
65
65
 
66
66
  :::note 死代码移除
67
67
  在生产环境,Terser 和 SWC 等代码压缩工具会分析代码,并将 dead code 移除,从而减少产物体积,这个过程被称为死代码移除(DCE)。
@@ -464,8 +464,7 @@ Modern.js 支持通过 `loading.tsx` 文件来解决这个问题,`routes/` 下
464
464
 
465
465
  :::tip
466
466
 
467
- - 该功能目前仅在 Webpack 项目中支持,Rspack 项目暂不支持。
468
- - 对数据的预加载目前只会预加载 SSR 项目中 [Data Loader](/guides/basic-features/data/data-fetch) 中返回的数据。
467
+ 对数据的预加载目前只会预加载 SSR 项目中 [Data Loader](/guides/basic-features/data/data-fetch) 中返回的数据。
469
468
 
470
469
  :::
471
470
 
@@ -72,7 +72,7 @@ console.log(largeImage); // "/static/largeImage.6c12aba3.png"
72
72
  console.log(smallImage); // "data:image/png;base64,iVBORw0KGgo..."
73
73
  ```
74
74
 
75
- 关于资源内联的更详细介绍,请参考 [静态资源内联](/guides/advanced-features/inline-assets) 章节。
75
+ 关于资源内联的更详细介绍,请参考 [静态资源内联](/guides/advanced-features/page-performance/inline-assets) 章节。
76
76
 
77
77
  ## 构建产物
78
78
 
@@ -13,3 +13,7 @@ Modern.js 之前提供的 Monorepo 方案是基于 [pnpm Workspace](https://pnpm
13
13
  ## new 命令开启 test 能力
14
14
 
15
15
  Modern.js 之前提供的测试能力是基于 Jest 的简单封装。该封装导致 Jest 配置不直观、用户配置更加复杂等问题。在 [v2.53.0](https://github.com/web-infra-dev/modern.js/releases/tag/v2.53.0) 版本中,移除了在应用项目和模块项目中开启 test 功能的选项。推荐直接使用社区提供的测试方案。
16
+
17
+ ## Eslint 规则集
18
+
19
+ Modern.js 之前提供了 ESLint 的完整规则集,涵盖了 @modern-js(针对 Node.js 项目的 Lint 规则)和 @modern-js-app(针对前端项目的 Lint 规则)。在 [v2.60.0](https://github.com/web-infra-dev/modern.js/releases/tag/v2.60.0) 版本中,我们正式移除了这些规则集。我们鼓励开发者根据自身需求选择合适的代码规范工具,直接使用 ESLint 并结合社区推荐的规则,或使用 Biome 以提升代码格式化的性能。
@@ -5,12 +5,6 @@
5
5
  "label": "micro-frontend",
6
6
  "collapsed": true
7
7
  },
8
- {
9
- "type": "dir",
10
- "name": "framework-plugin",
11
- "label": "framework-plugin",
12
- "collapsed": true
13
- },
14
8
  {
15
9
  "type": "dir",
16
10
  "name": "model",
@@ -0,0 +1,19 @@
1
+ [
2
+ "introduction",
3
+ {
4
+ "type": "dir",
5
+ "name": "plugin-system",
6
+ "label": "plugin-system",
7
+ "collapsed": true
8
+ },
9
+ {
10
+ "type": "dir",
11
+ "name": "cli-plugins",
12
+ "label": "cli-plugins"
13
+ },
14
+ {
15
+ "type": "dir",
16
+ "name": "rsbuild-plugins",
17
+ "label": "rsbuild-plugins"
18
+ }
19
+ ]
@@ -0,0 +1 @@
1
+ ["plugin-tailwind", "plugin-bff", "plugin-ssg", "plugin-swc"]
@@ -0,0 +1,5 @@
1
+ # BFF 插件
2
+
3
+ 在 Modern.js 应用中,通过 BFF 插件,开发者可以在 `api/lambda` 目录下定义接口文件,并导出接口函数。在前端代码中,可以用文件引用的方式,直接调用这些接口函数,发起接口请求。
4
+
5
+ 详细内容可以参考 [BFF - 基础用法](/guides/advanced-features/bff/function)。
@@ -0,0 +1,5 @@
1
+ # SSG 插件
2
+
3
+ SSG(Static Site Generation)是一种基于数据与模板,在构建时渲染完整静态网页的技术解决方案。这意味着在生产环境中,页面默认就是有内容的,并且可以被 CDN 缓存。对于无需数据的页面,SSG 可以提供更好的性能和更高的安全性。
4
+
5
+ 详细内容可以参考 [静态站点生成(SSG)](/guides/basic-features/render/ssg)。
@@ -4,6 +4,13 @@ sidebar_position: 2
4
4
 
5
5
  # SWC 插件
6
6
 
7
+ :::warning
8
+ **当前文档中的 SWC 功能已停止迭代**,我们更推荐使用 Rspack + SWC 的方案。
9
+
10
+ 请参考[「使用 Rspack」](/guides/advanced-features/rspack-start.html)了解更多。
11
+
12
+ :::
13
+
7
14
  import SWC from '@modern-js/builder-doc/docs/zh/shared/swc.md';
8
15
 
9
16
  <SWC />
@@ -0,0 +1,5 @@
1
+ # Tailwind CSS 插件
2
+
3
+ Tailwind CSS 是一个以 Utility Class 为基础的 CSS 框架和设计系统,可以快速地为组件添加常用样式,同时支持主题样式的灵活扩展。
4
+
5
+ 详细内容可以参考 [使用 Tailwind CSS](/guides/basic-features/css/tailwindcss)。
@@ -0,0 +1,6 @@
1
+ # 概览
2
+
3
+ - [@modern-js/plugin-tailwindcss](/plugin/cli-plugins/plugin-tailwind):提供使用 Tailwind CSS 样式的能力。
4
+ - [@modern-js/plugin-bff](/plugin/cli-plugins/plugin-bff):提供 BFF 服务,一体化调用的能力。
5
+ - [@modern-js/plugin-ssg](/plugin/cli-plugins/plugin-bff):提供静态站点生成的能力。
6
+ - [@modern-js/plugin-swc](/plugin/cli-plugins/plugin-swc):提供 SWC 编译支持。
@@ -1,11 +1,28 @@
1
- ---
2
- sidebar_position: 21
3
- title: 使用 Rsbuild 插件
4
- ---
1
+ # 插件
5
2
 
6
- # 使用 Rsbuild 插件
3
+ Modern.js 中目前可以直接使用两种插件,分别是 Modern.js 框架插件和 Rsbuild 构建插件。
7
4
 
8
- ## 插件介绍
5
+ ## Modern.js 框架插件
6
+
7
+ Modern.js 拥有自己的框架插件系统,你可以通过在 `modern.config.ts` 中配置 [`plugins`](/configure/app/plugins) 字段来使用 Modern.js 插件。
8
+
9
+ ### 插件类型
10
+
11
+ 框架插件可以细分成三类,分别是:
12
+
13
+ 1. [CLI 插件](/plugin/cli-plugins):用于在应用执行 Modern.js 命令时,提供额外的功能。例如,添加命令、修改配置、监听文件等。大多数构建相关的能力都可以通过 CLI 插件来实现。
14
+ 2. 服务端插件:用于在应用接受请求时,提供额外的功能。例如,添加中间件、修改请求响应等。
15
+ 3. 运行时插件:用于在应用运行 React 代码时,提供额外的功能。例如,执行初始化行为,包裹 React 高阶组件等。
16
+
17
+ :::note
18
+ 服务端插件和运行时插件即将正式对外开放。
19
+ :::
20
+
21
+ ### 开发插件
22
+
23
+ 如果你需要开发 Modern.js 框架插件,可以阅读 [Modern.js 插件系统](/plugin/plugin-system/introduction) 获取更多信息。
24
+
25
+ ## Rsbuild 构建插件
9
26
 
10
27
  Rsbuild 是 Modern.js 底层的构建工具,可通过添加 Rsbuild 插件修改默认的构建行为并添加各类额外功能,包括但不限于:
11
28
 
@@ -17,14 +34,18 @@ Rsbuild 是 Modern.js 底层的构建工具,可通过添加 Rsbuild 插件修
17
34
  你可以在 `modern.config.ts` 中通过 `builderPlugins` 选项来注册 Rsbuild 插件,详见 [builderPlugins 构建插件](/configure/app/builder-plugins.html)。
18
35
 
19
36
  :::tip
20
- Modern.js 从 `MAJOR_VERSION.46.0` 起开始将底层的构建工具升级为 [Rsbuild](https://rsbuild.dev/)
37
+ Modern.js 从 `MAJOR_VERSION.46.0` 起开始将底层的构建工具升级为 [Rsbuild](https://rsbuild.dev/).
38
+
39
+ 如果你当前版本低于 MAJOR_VERSION.46.0,可通过执行 `npx modern upgrade` 进行升级。
40
+ :::
21
41
 
22
- 如果你当前版本低于 MAJOR_VERSION.46.0, 可通过执行 `npx modern upgrade` 进行升级。
42
+ :::info
43
+ 可以阅读 [Rsbuild 官网 - 插件](https://rsbuild.dev/plugins/list/index) 来了解更多 Rsbuild 插件体系的内容。
23
44
  :::
24
45
 
25
- ## 官方插件
46
+ ### 官方插件
26
47
 
27
- ### 内置插件
48
+ #### 内置插件
28
49
 
29
50
  以下是已在 Modern.js 中内置的 Rsbuild 官方插件,无需安装,即可启用:
30
51
 
@@ -44,10 +65,14 @@ Modern.js 从 `MAJOR_VERSION.46.0` 起开始将底层的构建工具升级为 [R
44
65
  | [YAML 插件](https://github.com/rspack-contrib/rsbuild-plugin-yaml) | 用于引用 YAML 文件,并将其转换为 JavaScript 对象 | [TOML 文件](/guides/basic-features/static-assets/json-files.html#toml-文件) |
45
66
  | [TOML 插件](https://github.com/rspack-contrib/rsbuild-plugin-toml) | 用于引用 TOML 文件,并将其转换为 JavaScript 对象 | [YAML 文件](/guides/basic-features/static-assets/json-files.html#yaml-文件) |
46
67
 
47
- ### 未内置插件
68
+ #### 未内置的插件
48
69
 
49
70
  以下是未在 Modern.js 中内置的 Rsbuild 官方插件:
50
71
 
51
72
  - [Image Compress 插件](https://github.com/rspack-contrib/rsbuild-plugin-image-compress):将项目中用到的图片资源进行压缩处理。
52
73
  - [Stylus 插件](https://rsbuild.dev/zh/plugins/list/plugin-stylus):使用 Stylus 作为 CSS 预处理器。
53
74
  - [UMD 插件](https://github.com/rspack-contrib/rsbuild-plugin-umd):用于构建 UMD 格式的产物。
75
+
76
+ import OtherPlugins from '@site-docs/components/other-plugins.mdx';
77
+
78
+ <OtherPlugins />
@@ -4,7 +4,7 @@ sidebar_position: 5
4
4
 
5
5
  # 扩展插件 Hook
6
6
 
7
- 本小节介绍如何通过动态注册 [Hook 模型](/guides/topic-detail/framework-plugin/hook) 的方式来扩展插件 Hook。
7
+ 本小节介绍如何通过动态注册 [Hook 模型](/plugin/plugin-system/hook) 的方式来扩展插件 Hook。
8
8
 
9
9
  ## 示例
10
10
 
@@ -31,7 +31,7 @@ const myPlugin = {
31
31
  };
32
32
  ```
33
33
 
34
- 另外,在插件中,允许配置与其他插件的执行顺序。详情可以参考[插件关系](/guides/topic-detail/framework-plugin/relationship)。
34
+ 另外,在插件中,允许配置与其他插件的执行顺序。详情可以参考[插件关系](/plugin/plugin-system/relationship)。
35
35
 
36
36
  ### 插件类型
37
37
 
@@ -115,7 +115,7 @@ import type { MyPluginHook } from 'xxx';
115
115
  const myPlugin: CliPlugin<AppTools & { hooks: MyPluginHook }> = {};
116
116
  ```
117
117
 
118
- 详细说明,请参考 [扩展 Hook](/guides/topic-detail/framework-plugin/extend)。
118
+ 详细说明,请参考 [扩展 Hook](/plugin/plugin-system/extend)。
119
119
 
120
120
  ### 插件配置项
121
121
 
@@ -158,7 +158,7 @@ export const myPlugin = (): CliPlugin => ({
158
158
  });
159
159
  ```
160
160
 
161
- 插件 API 的详细说明,请参考 [Plugin API](/guides/topic-detail/framework-plugin/plugin-api)。
161
+ 插件 API 的详细说明,请参考 [Plugin API](/plugin/plugin-system/plugin-api)。
162
162
 
163
163
  ### 异步 setup
164
164
 
@@ -44,7 +44,7 @@ interface UserConfig {
44
44
  具体配置字段的意义请参考 [配置](/configure/app/usage)。
45
45
 
46
46
  :::tip
47
- 该方法获取到的是只读配置,不可修改。如果需要修改配置,请使用 [config hook](/guides/topic-detail/framework-plugin/hook-list.html#config)。
47
+ 该方法获取到的是只读配置,不可修改。如果需要修改配置,请使用 [config hook](/plugin/plugin-system/hook-list.html#config)。
48
48
  :::
49
49
 
50
50
  ### useResolvedConfigContext
@@ -67,7 +67,7 @@ interface NormalizedConfig {
67
67
  配置字段的完整内容请参考 [配置](/configure/app/usage)。
68
68
 
69
69
  :::tip
70
- 该方法获取到的是只读配置,不可修改。如果需要修改配置,请使用 [config hook](/guides/topic-detail/framework-plugin/hook-list.html#config)。
70
+ 该方法获取到的是只读配置,不可修改。如果需要修改配置,请使用 [config hook](/plugin/plugin-system/hook-list.html#config)。
71
71
  :::
72
72
 
73
73
  ### useAppContext
@@ -0,0 +1 @@
1
+ ["plugin-esbuild"]
@@ -0,0 +1,4 @@
1
+ # 概览
2
+
3
+ - [@modern-js/plugin-esbuild](/plugin/rsbuild-plugins/plugin-esbuild):提供 esbuild 编译支持。
4
+
package/i18n.json CHANGED
@@ -11,6 +11,10 @@
11
11
  "zh": "配置",
12
12
  "en": "Config"
13
13
  },
14
+ "plugin-menu": {
15
+ "zh": "插件",
16
+ "en": "Plugin"
17
+ },
14
18
  "apis": {
15
19
  "zh": "API",
16
20
  "en": "API"
@@ -71,13 +75,33 @@
71
75
  "zh": "使用 BFF",
72
76
  "en": "Using BFF"
73
77
  },
78
+ "page-performance": {
79
+ "zh": "优化页面性能",
80
+ "en": "Optimize Page Performance"
81
+ },
74
82
  "micro-frontend": {
75
83
  "zh": "微前端",
76
84
  "en": "Micro Frontend"
77
85
  },
78
- "framework-plugin": {
79
- "zh": "框架插件",
80
- "en": "Framework Plugin"
86
+ "plugin-system": {
87
+ "zh": "插件系统",
88
+ "en": "Plugin System"
89
+ },
90
+ "cli-plugins": {
91
+ "zh": "CLI 插件",
92
+ "en": "CLI Plugins"
93
+ },
94
+ "server-plugins": {
95
+ "zh": "服务端插件",
96
+ "en": "Server Plugins"
97
+ },
98
+ "runtime-plugins": {
99
+ "zh": "运行时插件",
100
+ "en": "Runtime Plugins"
101
+ },
102
+ "rsbuild-plugins": {
103
+ "zh": "Rsbuild 插件",
104
+ "en": "Rsbuild Plugins"
81
105
  },
82
106
  "reduck": {
83
107
  "zh": "Reduck 状态管理",
package/package.json CHANGED
@@ -15,17 +15,17 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.59.0",
18
+ "version": "2.60.0",
19
19
  "publishConfig": {
20
20
  "registry": "https://registry.npmjs.org/",
21
21
  "access": "public",
22
22
  "provenance": true
23
23
  },
24
24
  "dependencies": {
25
- "@modern-js/sandpack-react": "2.59.0"
25
+ "@modern-js/sandpack-react": "2.60.0"
26
26
  },
27
27
  "peerDependencies": {
28
- "@modern-js/builder-doc": "^2.59.0"
28
+ "@modern-js/builder-doc": "^2.60.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@rspress/shared": "1.28.2",
@@ -39,10 +39,11 @@
39
39
  "rspress": "1.28.2",
40
40
  "ts-node": "^10.9.1",
41
41
  "typescript": "^5",
42
- "@modern-js/builder-doc": "2.59.0"
42
+ "@modern-js/builder-doc": "2.60.0"
43
43
  },
44
44
  "scripts": {
45
45
  "dev": "rspress dev",
46
+ "dev:no_lazy": "LAZY=false rspress dev",
46
47
  "build": "npx ts-node ./scripts/sync.ts",
47
48
  "build:doc": "rspress build",
48
49
  "preview": "rspress preview"
package/rspress.config.ts CHANGED
@@ -6,61 +6,6 @@ const { version } = require('./package.json');
6
6
 
7
7
  const docPath = path.join(__dirname, 'docs');
8
8
 
9
- const getNavbar = (lang: string): NavItem[] => {
10
- const cn = lang === 'zh';
11
- const prefix = cn ? '' : '/en';
12
- const getLink = (str: string) => `${prefix}${str}`;
13
- const getText = (cnText: string, enText: string) => (cn ? cnText : enText);
14
- return [
15
- {
16
- text: getText('指南', 'Guide'),
17
- link: getLink('/guides/get-started/introduction'),
18
- activeMatch: '/guides/',
19
- },
20
- {
21
- text: getText('教程', 'Tutorials'),
22
- link: getLink('/tutorials/foundations/introduction'),
23
- activeMatch: '/tutorials/',
24
- },
25
- {
26
- text: getText('配置', 'Configure'),
27
- link: getLink('/configure/app/usage'),
28
- activeMatch: '/configure/app',
29
- },
30
- {
31
- text: getText('API', 'API'),
32
- link: getLink('/apis/app/commands'),
33
- activeMatch: '/apis/',
34
- },
35
- {
36
- text: getText('社区', 'Community'),
37
- link: getLink('/community/showcase'),
38
- activeMatch: '/community/',
39
- },
40
- {
41
- text: `v${version}`,
42
- items: [
43
- {
44
- text: 'Rsbuild',
45
- link: 'https://github.com/web-infra-dev/rsbuild',
46
- },
47
- {
48
- text: 'Rspress',
49
- link: 'https://github.com/web-infra-dev/rspress',
50
- },
51
- {
52
- text: 'Modern.js Module',
53
- link: 'https://modernjs.dev/module-tools/en/',
54
- },
55
- {
56
- text: 'Modern.js v1',
57
- link: 'https://modernjs.dev/v1/',
58
- },
59
- ],
60
- },
61
- ];
62
- };
63
-
64
9
  export default defineConfig({
65
10
  root: docPath,
66
11
  base: '/',
@@ -134,12 +79,10 @@ export default defineConfig({
134
79
  ],
135
80
  builderConfig: {
136
81
  output: {
137
- disableTsChecker: true,
138
- svgDefaultExport: 'component',
139
82
  dataUriLimit: 0,
140
83
  },
141
84
  dev: {
142
- startUrl: false,
85
+ lazyCompilation: process.env.LAZY !== 'false',
143
86
  },
144
87
  source: {
145
88
  alias: {
@@ -76,7 +76,7 @@ export default function Footer() {
76
76
  },
77
77
  {
78
78
  label: t('pluginSystem'),
79
- to: useUrl('/guides/topic-detail/framework-plugin/introduction'),
79
+ to: useUrl('/plugin/plugin-system/introduction'),
80
80
  },
81
81
  {
82
82
  label: t('projectGenerator'),
@@ -1,4 +1,3 @@
1
- /* eslint-disable react/no-unescaped-entities */
2
1
  import clsx from 'clsx';
3
2
  import { useEffect } from 'react';
4
3
  import { Helmet, useLang, useLocation } from 'rspress/runtime';
@@ -1,80 +0,0 @@
1
- ---
2
- title: '**/*.[tj]s'
3
- sidebar_position: 1
4
- ---
5
- # **/*.[tj]s
6
-
7
- Files that declare API routes in the [BFF Function Mode](/guides/advanced-features/bff/type.html#function-mode). Except for some [convention files](/apis/app/hooks/api/api#allow-list), files in the `api` directory will be registered as the routes.
8
-
9
- :::info
10
- Using the `api` directory requires enabling the BFF feature, and you need to run the `new` command in the project to enable the "BFF" feature.
11
-
12
- This file supports using the `js` or `ts` language, but you must use `esm` syntax to export functions.
13
-
14
- :::
15
-
16
- ## Routing File Convention
17
-
18
- ### Default Routing
19
-
20
- The routing system will map files named `index` to the previous directory.
21
-
22
- - `api/index.ts` -> `$BASENAME/`
23
- - `api/user/index.ts` -> `$BASENAME/user`
24
-
25
- ### Nested Routing
26
-
27
- The routing system also supports parsing nested files. If you create a nested folder structure, the files will still automatically resolve routes in the same way.
28
-
29
- - `api/hello.ts` -> `$BASENAME/hello`
30
- - `api/user/list.ts` -> `$BASENAME/user/list`
31
-
32
- ### Dynamic Routing
33
-
34
- The routing system supports generating dynamic routes through file directories named with `[]`.
35
-
36
- - `api/user/[username]/info.ts` -> `$BASENAME/user/:username/info`
37
- - `api/user/[username]/delete.ts` -> `$BASENAME/user/:username/delete`
38
- - `api/article/[id]/info.ts` -> `$BASENAME/article/:id/info`
39
-
40
- The `$BASENAME` can be configured in `modern.config.js`, and the default value is `/api`.
41
-
42
- ### Allow List
43
-
44
- By default, all files in the `api` directory will be parsed as BFF function files, but we also set a white list for these files that are not parsed:
45
-
46
- - Files whose names start with `_`. For example: `_utils.ts`.
47
- - All files in folders whose names start with `_`. For example: `_utils/index.ts`, `_utils/cp.ts`.
48
- - Test files. For example: `foo.test.ts`.
49
- - TypeScript type files. For example: `hello.d.ts`.
50
- - Files under `node_modules`.
51
-
52
- ## Function Definition
53
-
54
- In addition to the routing rules above, there are also conventions for function definitions and exports in the code.
55
-
56
- Functions are exported by name, and the name of the exported function is the HTTP method accepted by the corresponding interface, that is:
57
-
58
- ```ts
59
- export const get = async () => {
60
- return {
61
- name: 'Modern.js',
62
- desc: 'Modern web Solutions',
63
- };
64
- };
65
- ```
66
-
67
- By exporting functions in this way, you will get a `GET` interface.
68
-
69
- The application project supports 9 Method definitions, namely: `GET`, `POST`, `PUT`, `DELETE`, `CONNECT`, `TRACE`, `PATCH`, `OPTION`, `HEAD`, that is, these Methods can be used as the names of the exported functions.
70
-
71
- The name is case-insensitive, that is, if it is `GET`, it can be written as `get`, `Get`, `GEt`, `GET`, all of which can be accurately recognized. The default export, that is, `export default xxx`, will be mapped to `Get`.
72
-
73
- Because `delete` is a keyword in JavaScript, you can use `del` or `DELETE` instead.
74
-
75
- Multiple functions with different Methods can be defined in one file, but if multiple functions with the same Method are defined, only the first one will take effect.
76
-
77
- :::info
78
- It should be noted that the defined functions should all be asynchronous, which is related to the type when calling the function.
79
-
80
- :::
@@ -1,12 +0,0 @@
1
- ---
2
- title: _app.[tj]s
3
- sidebar_position: 2
4
- ---
5
- # _app.[tj]s
6
-
7
- In the [BFF Function Mode](/guides/advanced-features/bff/type.html#function-mode), this file can add pre-middleware for BFF functions.
8
-
9
- :::note
10
- For specific examples, please refer to [hook](/apis/app/runtime/bff/hook).
11
-
12
- :::
@@ -1,46 +0,0 @@
1
- ---
2
- sidebar_position: 2
3
- title: BFF Type
4
- ---
5
- # BFF Type
6
-
7
- Runtime framework support is also an important part of **BFF**. Modern.js supports extending BFF's runtime framework through plugins, and provides a series of built-in plugins, developers can directly use the conventions and ecology of the framework.
8
-
9
- The plugin is compatible with most of the specifications of these frameworks, and each framework needs to provide two types of ways to extend the writing of BFF functions, namely **Function Mode** and **Framework Mode**.
10
-
11
- :::note
12
- Whether the current `api/` directory structure is written as a framework is determined by the corresponding plugin, Modern.js don't care.
13
-
14
- :::
15
-
16
- ## Function Mode
17
-
18
- When the plugin considers that it is currently written as a function, it must support writing middleware in the `api/_ app.ts` to extend the BFF function.
19
-
20
- Modern.js collects the middleware in the `api/_app.ts` and passes it to the plugin, which injects the middleware into the runtime, for example:
21
-
22
- ```ts
23
- import { hook } from '@modern-js/runtime/server';
24
-
25
- export default hook(({ addMiddleware }) => {
26
- addMiddleware(myMiddleware);
27
- });
28
- ```
29
-
30
- :::note
31
- The writing of middleware for different plugins is not the same, see [Runtime Framework](/guides/advanced-features/bff/frameworks) for details.
32
-
33
- :::
34
-
35
- ## Framework Mode
36
-
37
- Framework writing is a way of using frame structure to extend BFF functions. Compared with function writing, although frame writing can use more frame structure and make the entire BFF Server clearer in complex scenarios, it is also more complex and requires more attention to the content at the framework level.
38
-
39
- In the framework writing method, all BFF functions need to be written in the `api/lambda/` directory, and the hook file `_app.[tj]s` cannot be used.
40
-
41
- In most cases, the function writing method can cover the customization requirements of most BFF functions. Only when your project server level logic is more complex, the code needs to be layered, or you need to use more elements of the framework, you need to use the framework writing method.
42
-
43
- :::note
44
- The directory structure of different plugin frameworks is not the same, see [Runtime Frameworks](/guides/advanced-features/bff/frameworks) for details.
45
-
46
- :::