@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.
- package/docs/en/_meta.json +10 -5
- package/docs/en/apis/app/hooks/api/lambda.mdx +4 -48
- package/docs/en/apis/app/hooks/api/middleware.mdx +11 -0
- package/docs/en/community/blog/v2-release-note.mdx +1 -1
- package/docs/en/components/enable-bff.mdx +19 -2
- package/docs/en/components/extend-bff-function.mdx +5 -0
- package/docs/en/components/other-plugins.mdx +0 -0
- package/docs/en/configure/app/auto-load-plugin.mdx +4 -0
- package/docs/en/configure/app/plugins.mdx +2 -2
- package/docs/en/configure/app/tools/esbuild.mdx +1 -1
- package/docs/en/configure/app/tools/swc.mdx +1 -1
- package/docs/en/guides/_meta.json +0 -5
- package/docs/en/guides/advanced-features/_meta.json +7 -4
- package/docs/en/guides/advanced-features/bff/_meta.json +1 -1
- package/docs/en/guides/advanced-features/bff/extend-server.mdx +154 -0
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +52 -123
- package/docs/en/guides/advanced-features/bff/function.mdx +108 -80
- package/docs/en/guides/advanced-features/bff/sdk.mdx +40 -51
- package/docs/en/guides/advanced-features/build-performance.mdx +6 -21
- package/docs/en/guides/advanced-features/page-performance/_meta.json +1 -0
- package/docs/en/guides/basic-features/render/streaming-ssr.mdx +1 -1
- package/docs/en/guides/basic-features/routes.mdx +2 -3
- package/docs/en/guides/basic-features/static-assets.mdx +1 -1
- package/docs/en/guides/deprecated.md +2 -0
- package/docs/en/guides/topic-detail/_meta.json +0 -6
- package/docs/en/plugin/_meta.json +19 -0
- package/docs/en/plugin/cli-plugins/_meta.json +1 -0
- package/docs/en/plugin/cli-plugins/plugin-bff.mdx +5 -0
- package/docs/en/plugin/cli-plugins/plugin-ssg.mdx +5 -0
- package/docs/en/{guides/rsbuild-plugins → plugin/cli-plugins}/plugin-swc.mdx +7 -0
- package/docs/en/plugin/cli-plugins/plugin-tailwind.mdx +5 -0
- package/docs/en/plugin/cli-plugins.mdx +6 -0
- package/docs/en/{guides/advanced-features/rsbuild-plugin.mdx → plugin/introduction.mdx} +34 -9
- package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/extend.mdx +1 -1
- package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/implement.mdx +3 -3
- package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/plugin-api.mdx +2 -2
- package/docs/en/plugin/rsbuild-plugins/_meta.json +1 -0
- package/docs/en/plugin/rsbuild-plugins.mdx +3 -0
- package/docs/zh/_meta.json +10 -5
- package/docs/zh/apis/app/hooks/api/lambda.mdx +5 -48
- package/docs/zh/apis/app/hooks/api/middleware.mdx +11 -0
- package/docs/zh/community/blog/v2-release-note.mdx +1 -1
- package/docs/zh/components/enable-bff.mdx +19 -2
- package/docs/zh/components/extend-bff-function.mdx +5 -0
- package/docs/zh/components/other-plugins.mdx +0 -0
- package/docs/zh/configure/app/auto-load-plugin.mdx +4 -0
- package/docs/zh/configure/app/plugins.mdx +2 -2
- package/docs/zh/configure/app/tools/esbuild.mdx +1 -1
- package/docs/zh/configure/app/tools/swc.mdx +1 -1
- package/docs/zh/guides/_meta.json +0 -5
- package/docs/zh/guides/advanced-features/_meta.json +7 -4
- package/docs/zh/guides/advanced-features/bff/_meta.json +1 -1
- package/docs/zh/guides/advanced-features/bff/extend-server.mdx +156 -0
- package/docs/zh/guides/advanced-features/bff/frameworks.mdx +51 -117
- package/docs/zh/guides/advanced-features/bff/function.mdx +69 -59
- package/docs/zh/guides/advanced-features/bff/sdk.mdx +27 -36
- package/docs/zh/guides/advanced-features/build-performance.mdx +6 -21
- package/docs/zh/guides/advanced-features/page-performance/_meta.json +1 -0
- package/docs/zh/guides/advanced-features/rspack-start.mdx +2 -2
- package/docs/zh/guides/basic-features/alias.mdx +5 -11
- package/docs/zh/guides/basic-features/env-vars.mdx +1 -1
- package/docs/zh/guides/basic-features/routes.mdx +1 -2
- package/docs/zh/guides/basic-features/static-assets.mdx +1 -1
- package/docs/zh/guides/deprecated.md +4 -0
- package/docs/zh/guides/topic-detail/_meta.json +0 -6
- package/docs/zh/plugin/_meta.json +19 -0
- package/docs/zh/plugin/cli-plugins/_meta.json +1 -0
- package/docs/zh/plugin/cli-plugins/plugin-bff.mdx +5 -0
- package/docs/zh/plugin/cli-plugins/plugin-ssg.mdx +5 -0
- package/docs/zh/{guides/rsbuild-plugins → plugin/cli-plugins}/plugin-swc.mdx +7 -0
- package/docs/zh/plugin/cli-plugins/plugin-tailwind.mdx +5 -0
- package/docs/zh/plugin/cli-plugins.mdx +6 -0
- package/docs/zh/{guides/advanced-features/rsbuild-plugin.mdx → plugin/introduction.mdx} +36 -11
- package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/extend.mdx +1 -1
- package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/implement.mdx +3 -3
- package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/plugin-api.mdx +2 -2
- package/docs/zh/plugin/rsbuild-plugins/_meta.json +1 -0
- package/docs/zh/plugin/rsbuild-plugins.mdx +4 -0
- package/i18n.json +27 -3
- package/package.json +5 -4
- package/rspress.config.ts +1 -58
- package/src/components/Footer/index.tsx +1 -1
- package/src/pages/index.tsx +0 -1
- package/docs/en/apis/app/hooks/api/api.mdx +0 -80
- package/docs/en/apis/app/hooks/api/app.mdx +0 -12
- package/docs/en/guides/advanced-features/bff/type.mdx +0 -46
- package/docs/en/guides/advanced-features/eslint.mdx +0 -148
- package/docs/zh/apis/app/hooks/api/api.mdx +0 -81
- package/docs/zh/apis/app/hooks/api/app.mdx +0 -12
- package/docs/zh/guides/advanced-features/bff/type.mdx +0 -46
- package/docs/zh/guides/advanced-features/eslint.mdx +0 -152
- /package/docs/en/guides/advanced-features/{bff/index.mdx → bff.mdx} +0 -0
- /package/docs/en/guides/advanced-features/{code-split.mdx → page-performance/code-split.mdx} +0 -0
- /package/docs/en/guides/advanced-features/{inline-assets.mdx → page-performance/inline-assets.mdx} +0 -0
- /package/docs/en/guides/advanced-features/{optimize-bundle.mdx → page-performance/optimize-bundle.mdx} +0 -0
- /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/_meta.json +0 -0
- /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook-list.mdx +0 -0
- /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook.mdx +0 -0
- /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/introduction.mdx +0 -0
- /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/lifecycle.mdx +0 -0
- /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/relationship.mdx +0 -0
- /package/docs/en/{guides → plugin}/rsbuild-plugins/plugin-esbuild.mdx +0 -0
- /package/docs/zh/guides/advanced-features/{bff/index.mdx → bff.mdx} +0 -0
- /package/docs/zh/guides/advanced-features/{code-split.mdx → page-performance/code-split.mdx} +0 -0
- /package/docs/zh/guides/advanced-features/{inline-assets.mdx → page-performance/inline-assets.mdx} +0 -0
- /package/docs/zh/guides/advanced-features/{optimize-bundle.mdx → page-performance/optimize-bundle.mdx} +0 -0
- /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/_meta.json +0 -0
- /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook-list.mdx +0 -0
- /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook.mdx +0 -0
- /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/introduction.mdx +0 -0
- /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/lifecycle.mdx +0 -0
- /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/relationship.mdx +0 -0
- /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
|
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
|
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 {
|
@@ -464,8 +464,7 @@ Modern.js 支持通过 `loading.tsx` 文件来解决这个问题,`routes/` 下
|
|
464
464
|
|
465
465
|
:::tip
|
466
466
|
|
467
|
-
|
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 以提升代码格式化的性能。
|
@@ -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"]
|
@@ -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,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
|
-
|
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
|
-
|
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 />
|
@@ -31,7 +31,7 @@ const myPlugin = {
|
|
31
31
|
};
|
32
32
|
```
|
33
33
|
|
34
|
-
另外,在插件中,允许配置与其他插件的执行顺序。详情可以参考[插件关系](/
|
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](/
|
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](/
|
161
|
+
插件 API 的详细说明,请参考 [Plugin API](/plugin/plugin-system/plugin-api)。
|
162
162
|
|
163
163
|
### 异步 setup
|
164
164
|
|
package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/plugin-api.mdx
RENAMED
@@ -44,7 +44,7 @@ interface UserConfig {
|
|
44
44
|
具体配置字段的意义请参考 [配置](/configure/app/usage)。
|
45
45
|
|
46
46
|
:::tip
|
47
|
-
该方法获取到的是只读配置,不可修改。如果需要修改配置,请使用 [config hook](/
|
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](/
|
70
|
+
该方法获取到的是只读配置,不可修改。如果需要修改配置,请使用 [config hook](/plugin/plugin-system/hook-list.html#config)。
|
71
71
|
:::
|
72
72
|
|
73
73
|
### useAppContext
|
@@ -0,0 +1 @@
|
|
1
|
+
["plugin-esbuild"]
|
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
|
-
"
|
79
|
-
"zh": "
|
80
|
-
"en": "
|
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.
|
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.
|
25
|
+
"@modern-js/sandpack-react": "2.60.0"
|
26
26
|
},
|
27
27
|
"peerDependencies": {
|
28
|
-
"@modern-js/builder-doc": "^2.
|
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.
|
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
|
-
|
85
|
+
lazyCompilation: process.env.LAZY !== 'false',
|
143
86
|
},
|
144
87
|
source: {
|
145
88
|
alias: {
|
package/src/pages/index.tsx
CHANGED
@@ -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
|
-
:::
|