@modern-js/main-doc 2.7.0 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +17 -0
  3. package/README.md +2 -2
  4. package/en/apis/app/commands.mdx +2 -0
  5. package/en/apis/app/runtime/model/connect.mdx +1 -1
  6. package/en/apis/app/runtime/model/model_.mdx +1 -1
  7. package/en/apis/app/runtime/model/use-model.mdx +1 -1
  8. package/en/apis/app/runtime/web-server/hook.mdx +2 -2
  9. package/en/apis/app/runtime/web-server/middleware.mdx +33 -9
  10. package/en/components/enable-bff.mdx +4 -4
  11. package/en/components/init-rspack-app.mdx +7 -0
  12. package/en/configure/app/bff/enable-handle-web.mdx +24 -0
  13. package/en/configure/app/server/enable-framework-ext.mdx +1 -1
  14. package/en/guides/advanced-features/bff/_category_.json +1 -1
  15. package/en/guides/advanced-features/eslint.mdx +30 -32
  16. package/en/guides/advanced-features/low-level.mdx +1 -1
  17. package/en/guides/advanced-features/rspack-start.mdx +13 -17
  18. package/en/guides/advanced-features/web-server.mdx +87 -20
  19. package/en/guides/concept/builder.mdx +1 -1
  20. package/en/guides/topic-detail/framework-plugin/extend.mdx +20 -19
  21. package/en/guides/topic-detail/framework-plugin/hook-list.mdx +156 -155
  22. package/en/guides/topic-detail/framework-plugin/hook.mdx +58 -43
  23. package/en/guides/topic-detail/framework-plugin/implement.mdx +47 -49
  24. package/en/guides/topic-detail/framework-plugin/introduction.mdx +22 -23
  25. package/en/guides/topic-detail/framework-plugin/plugin-api.mdx +13 -13
  26. package/en/guides/topic-detail/framework-plugin/relationship.mdx +30 -30
  27. package/en/guides/topic-detail/generator/plugin/develop.mdx +1 -1
  28. package/en/guides/topic-detail/micro-frontend/c01-introduction.mdx +17 -17
  29. package/en/guides/topic-detail/micro-frontend/c02-development.mdx +76 -78
  30. package/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +57 -51
  31. package/en/guides/topic-detail/micro-frontend/c04-communicate.mdx +11 -11
  32. package/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +13 -13
  33. package/en/guides/topic-detail/model/auto-actions.mdx +18 -21
  34. package/en/guides/topic-detail/model/computed-state.mdx +27 -25
  35. package/en/guides/topic-detail/model/define-model.mdx +14 -14
  36. package/en/guides/topic-detail/model/faq.mdx +12 -13
  37. package/en/guides/topic-detail/model/manage-effects.mdx +43 -52
  38. package/en/guides/topic-detail/model/model-communicate.mdx +47 -45
  39. package/en/guides/topic-detail/model/performance.mdx +22 -23
  40. package/en/guides/topic-detail/model/quick-start.mdx +29 -28
  41. package/en/guides/topic-detail/model/redux-integration.mdx +7 -7
  42. package/en/guides/topic-detail/model/test-model.mdx +11 -11
  43. package/en/guides/topic-detail/model/typescript-best-practice.mdx +16 -15
  44. package/en/guides/topic-detail/model/use-model.mdx +40 -45
  45. package/en/guides/topic-detail/model/use-out-of-modernjs.mdx +16 -16
  46. package/en/guides/troubleshooting/cli.mdx +2 -2
  47. package/package.json +5 -5
  48. package/zh/apis/app/commands.mdx +2 -0
  49. package/zh/apis/app/runtime/model/connect.mdx +1 -1
  50. package/zh/apis/app/runtime/model/model_.mdx +1 -1
  51. package/zh/apis/app/runtime/model/use-model.mdx +1 -1
  52. package/zh/apis/app/runtime/web-server/hook.mdx +2 -4
  53. package/zh/apis/app/runtime/web-server/middleware.mdx +30 -10
  54. package/zh/apis/monorepo/commands/gen-release-note.mdx +3 -3
  55. package/zh/components/enable-bff.mdx +4 -4
  56. package/zh/components/init-rspack-app.mdx +7 -0
  57. package/zh/components/release-note.mdx +1 -1
  58. package/zh/configure/app/bff/enable-handle-web.mdx +24 -0
  59. package/zh/configure/app/server/enable-framework-ext.mdx +1 -1
  60. package/zh/guides/advanced-features/bff/_category_.json +1 -1
  61. package/zh/guides/advanced-features/rspack-start.mdx +13 -17
  62. package/zh/guides/advanced-features/web-server.mdx +81 -16
  63. package/zh/guides/concept/builder.mdx +1 -1
  64. package/zh/guides/topic-detail/changesets/github.mdx +2 -2
  65. package/zh/guides/topic-detail/changesets/release-note.mdx +1 -1
  66. package/zh/guides/topic-detail/framework-plugin/plugin-api.mdx +2 -2
  67. package/zh/guides/topic-detail/generator/plugin/develop.mdx +1 -1
  68. package/zh/guides/topic-detail/model/faq.mdx +1 -1
  69. package/zh/guides/topic-detail/model/manage-effects.mdx +1 -1
  70. package/zh/guides/topic-detail/model/model-communicate.mdx +1 -1
  71. package/zh/guides/topic-detail/model/performance.mdx +1 -1
  72. package/zh/guides/topic-detail/model/quick-start.mdx +2 -2
  73. package/zh/guides/topic-detail/model/use-model.mdx +3 -3
@@ -1,4 +1,4 @@
1
1
 
2
- > @modern-js/main-doc@2.7.0 build /github/workspace/packages/toolkit/main-doc
2
+ > @modern-js/main-doc@2.8.0 build /home/runner/work/modern.js/modern.js/packages/toolkit/main-doc
3
3
  > npx ts-node ./scripts/sync.ts
4
4
 
package/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # @modern-js/main-doc
2
+
3
+ ## 2.8.0
4
+
5
+ ### Patch Changes
6
+
7
+ - ea7bb41e30: feat: add custom web server docs
8
+ feat: 添加自定义 Web Server 文档
9
+ - 1104a9f18b: feat: support start web service only
10
+ feat: 支持只启动 web 服务
11
+ - bd58566b32: Fix Typo
12
+
13
+ 修复 Typo
14
+
15
+ - Updated dependencies [9736c6a43d]
16
+ - Updated dependencies [2c1151271d]
17
+ - @modern-js/builder-doc@2.8.0
package/README.md CHANGED
@@ -19,8 +19,8 @@ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-sta
19
19
 
20
20
  ## Contributing
21
21
 
22
- Please read the [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md).
22
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
23
23
 
24
24
  ## License
25
25
 
26
- Modern.js is [MIT licensed](https://github.com/modern-js-dev/modern.js/blob/main/LICENSE).
26
+ Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
@@ -20,6 +20,7 @@ Options:
20
20
  -c --config <config> configuration file path, which can be a relative path or an absolute path
21
21
  -h, --help show command help
22
22
  --analyze analyze the bundle and view size of each module
23
+ --web-only only start web service
23
24
  --api-only only start API service
24
25
  ```
25
26
 
@@ -161,6 +162,7 @@ Usage: modern serve [options]
161
162
  Options:
162
163
  -c --config <config> configuration file path, which can be a relative path or an absolute path
163
164
  -h, --help show command help
165
+ --web-only only run web service
164
166
  --api-only only run API service
165
167
  ```
166
168
 
@@ -9,7 +9,7 @@ import ReduckTip from "@site-docs-en/components/reduck-tip"
9
9
  <ReduckTip />
10
10
 
11
11
  :::tip
12
- The original type of Reduck is complex. The following type definition shows the simplified type information. For the original type, see [**connect**](https://github.com/modern-js-dev/reduck/blob/main/packages/react/src/connect.ts).
12
+ The original type of Reduck is complex. The following type definition shows the simplified type information. For the original type, see [**connect**](https://github.com/web-infra-dev/reduck/blob/main/packages/react/src/connect.ts).
13
13
 
14
14
  :::
15
15
 
@@ -9,7 +9,7 @@ import ReduckTip from "@site-docs-en/components/reduck-tip"
9
9
  <ReduckTip />
10
10
 
11
11
  :::tip
12
- The original type of Reduck is complex. The following type definition shows the simplified type information. For the original type, see [**model**](https://github.com/modern-js-dev/reduck/blob/main/packages/store/src/model/model.ts).
12
+ The original type of Reduck is complex. The following type definition shows the simplified type information. For the original type, see [**model**](https://github.com/web-infra-dev/reduck/blob/main/packages/store/src/model/model.ts).
13
13
 
14
14
  :::
15
15
 
@@ -9,7 +9,7 @@ import ReduckTip from "@site-docs-en/components/reduck-tip"
9
9
  <ReduckTip />
10
10
 
11
11
  :::tip
12
- The original type of Reduck is complex. The following type definition shows the simplified type information. For the original type, see [**model**](https://github.com/modern-js-dev/reduck/blob/main/packages/store/src/model/model.ts).
12
+ The original type of Reduck is complex. The following type definition shows the simplified type information. For the original type, see [**model**](https://github.com/web-infra-dev/reduck/blob/main/packages/store/src/model/model.ts).
13
13
 
14
14
  :::
15
15
 
@@ -3,7 +3,7 @@ title: Hook
3
3
  ---
4
4
  # Hook
5
5
 
6
- Used to extend Modern.js built-in Web Server, requests except BFF are handled by these hooks.
6
+ Used to extend Modern.js built-in Web Server, all page requests are handled by these hooks.
7
7
 
8
8
  :::note
9
9
  For more detail, see [Extend Web Server](/guides/advanced-features/web-server).
@@ -63,7 +63,7 @@ type HookContext = {
63
63
  function Hook(context: HookContext, next: NextFunction): Promsie<void> | void;
64
64
  ```
65
65
 
66
- different Hooks additionally provide different contexts. Currently Modern.js support `AtferMatch` and `AfterRender`.
66
+ different Hooks additionally provide different contexts. Currently Modern.js support `AfterMatch` and `AfterRender`.
67
67
 
68
68
  ```ts
69
69
  type AfterMatchContext = HookContext & {
@@ -3,9 +3,7 @@ title: Middleware
3
3
  ---
4
4
  # Middleware
5
5
 
6
- Used to extend Modern.js built-in Web Server, only SSR requests are handled by these middleware.
7
-
8
- Unlike [Hook](/apis/app/runtime/web-server/hook), middleware can be extended using the framework plugin.
6
+ Used to extend the built-in Web Server of Modern.js, unlike [Hook](/apis/app/runtime/web-server/hook), Middleware can directly operate Node's origin request and response, and can be extended using the framework plugin.
9
7
 
10
8
  :::note
11
9
  For more detail, see [Extend Web Server](/guides/advanced-features/web-server).
@@ -38,6 +36,11 @@ pnpm run new
38
36
  ## Function Signature
39
37
 
40
38
  ```ts
39
+ type Middleware = (
40
+ context: MiddlewareContext,
41
+ next: NextFunction,
42
+ ) => Promise<void> | void;
43
+
41
44
  type MiddlewareContext = {
42
45
  response: {
43
46
  set: (key: string, value: string) => void;
@@ -70,11 +73,6 @@ type MiddlewareContext = {
70
73
  res: ServerResponse;
71
74
  };
72
75
  };
73
-
74
- type RequestHandler = (
75
- context: Context,
76
- next: NextFunction,
77
- ) => Promise<void> | void;
78
76
  ```
79
77
 
80
78
  ### Input
@@ -85,6 +83,10 @@ type RequestHandler = (
85
83
  - `source`: provides Node.js native `req` and `res` object.
86
84
  - `next`: call next listener(not affect the server process, only current hook).
87
85
 
86
+ :::warning
87
+ The execution of the `next` function does not affect built-in processes, only controls whether the next middleware executes. Rendering processes are interrupted only when the response is written.
88
+ :::
89
+
88
90
  ## Example
89
91
 
90
92
  ### Tracking
@@ -106,5 +108,27 @@ Modern.js provides `res.locals` to store local variables for the current request
106
108
  export const Middleware = () => async (ctx, next) => {
107
109
  ctx.res.locals.id = 'Modern.js';
108
110
  ctx.res.locals.rpc = createRpcInstance();
109
- });
111
+ };
110
112
  ```
113
+
114
+ ### Framework Extension
115
+
116
+ Middleware can also use runtime framework extensions like BFF.
117
+
118
+ When using framework runtime extensions, type information is exported from `@modern-js/runtime/{namespace}`. Middleware can use framework syntax, such as framework middleware writing, the following is pseudo-code:
119
+
120
+ ```ts
121
+ import { SomeType } from '@modern-js/runtime/{namespace}';
122
+
123
+ export const middleware: SomeType = (ctx, next) => {
124
+ console.log(ctx.url);
125
+ next();
126
+ };
127
+ ```
128
+
129
+ By default, the framework extension capability of Web Server is turned off after installing the framework extension plug-in. If you want to use the framework extension, you can turn it on through ['server.enableFrameworkExt'](/configure/app/server/enable-framework-ext.html).
130
+
131
+
132
+ :::info
133
+ The type name exported by the framework extension may not 'Middleware', but is named by the framework extension plugin.
134
+ :::
@@ -7,8 +7,8 @@ import { Tabs, Tab as TabItem } from "@theme";
7
7
  <TabItem value="express" label="Express.js" default>
8
8
 
9
9
  ```ts title="edenx.config.ts"
10
- import expressPlugin from '@edenx/plugin-express';
11
- import bffPlugin from '@edenx/plugin-bff';
10
+ import expressPlugin from '@modern-js/plugin-express';
11
+ import bffPlugin from '@modern-js/plugin-bff';
12
12
 
13
13
  export default defineConfig({
14
14
  plugins: [expressPlugin(), bffPlugin()],
@@ -19,8 +19,8 @@ export default defineConfig({
19
19
  <TabItem value="koa" label="Koa.js">
20
20
 
21
21
  ```ts title="edenx.config.ts"
22
- import koaPlugin from '@edenx/plugin-koa';
23
- import bffPlugin from '@edenx/plugin-bff';
22
+ import koaPlugin from '@modern-js/plugin-koa';
23
+ import bffPlugin from '@modern-js/plugin-bff';
24
24
 
25
25
  export default defineConfig({
26
26
  plugins: [koaPlugin(), bffPlugin()],
@@ -0,0 +1,7 @@
1
+ ```bash
2
+ $ npx @modern-js/create myapp
3
+ ? Please select the solution you want to create: Web App Solution
4
+ ? Development Language: TS
5
+ ? Package Management Tool: pnpm
6
+ ? Build Tools: Rspack
7
+ ```
@@ -0,0 +1,24 @@
1
+ ---
2
+ title: enableHandleWeb
3
+ ---
4
+
5
+ # bff.enableHandleWeb
6
+
7
+ - **Type:** `boolean`
8
+ - **Default:** `false`
9
+
10
+ :::caution
11
+ First you need to enable the "BFF" function using [new](/apis/app/commands#modern-new) command.
12
+ :::
13
+
14
+ By default, the BFF service can only handle requests from the BFF API.
15
+
16
+ When this value is set to `true`, page request traffic also goes through the BFF, and the logic built into Modern.js for page rendering defaults to running as the last middleware for the BFF service.
17
+
18
+ ```ts title="modern.config.ts"
19
+ export default defineConfig({
20
+ bff: {
21
+ enableHandleWeb: true,
22
+ },
23
+ });
24
+ ```
@@ -35,7 +35,7 @@ export const middleware: Middleware = (ctx, next) => {
35
35
  When enabled, Middleware types will be exported from other namespaces and can the syntax of framework extensions:
36
36
 
37
37
  ```ts title="server/index.ts"
38
- import { SomeType } from '@modern-js/runtime/{frameworknName}';
38
+ import { SomeType } from '@modern-js/runtime/{namespace}';
39
39
 
40
40
  export const middleware: SomeType = (...args) => {
41
41
  console.log(args[0].url);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "label": "BFF",
3
- "position": 1,
3
+ "position": 2,
4
4
  "link": {
5
5
  "type": "doc",
6
6
  "id": "guides/advanced-features/bff/index"
@@ -16,12 +16,11 @@ Most problems will be solved by the automatic fix of ESLint rules or the code fo
16
16
 
17
17
  :::info
18
18
  This kind of automatic fix is mainly performed when the IDE saves the file, and a few will be automatically fix on submit.
19
-
20
19
  :::
21
20
 
22
21
  ### Batch Automatic Fix
23
22
 
24
- 在少数情况下,比如旧项目迁移的时候,可以执行以下命令,批量修复和检查所有文件:
23
+ In rare cases, such as when an old project is migrated, the following commands can be executed to repair and inspect all files in bulk:
25
24
 
26
25
  ```bash
27
26
  pnpm run lint:error
@@ -29,13 +28,13 @@ pnpm run lint:error
29
28
 
30
29
  ### Manual Fix
31
30
 
32
- 对于无法自动修复的问题,可以在 IDE 里点击问题提示框里的规则链接,打开这条规则的文档,查看问题的解释和解决方案。
31
+ For problems that cannot be automatically fixed, you can click the rule link in the problem prompt box in the IDE to open the document of this rule to view the explanation and solution of the problem.
33
32
 
34
- ### 声明例外情况
33
+ ### Claim Exceptions
35
34
 
36
- 目前阶段,有些规则并不能做到足够智能,多数情况下会有很大收益,在少数情况下也许不适用。但如果为了这些少数情况就把整个规则关掉或改掉,得不偿失。
35
+ At this stage, some rules are not smart enough, and in most cases there will be great benefits, and in a few cases it may not apply. But if the entire rule is turned off or changed for these few cases, the gain is not worth the loss.
37
36
 
38
- 这种情况下可以用 [eslint-disable](https://eslint.org/docs/user-guide/configuring/rules#disabling-rules) 注释,对符合**少数情况**的代码块做标注,声明这里是一个例外,应该忽略。比如:
37
+ In this case, you can use the [eslint-disable](https://eslint.org/docs/user-guide/configuring/rules#disabling-rules) comment to mark the code blocks that meet the **rare case**, stating that this is an exception and should be ignored. For example:
39
38
 
40
39
  ```js
41
40
  /* eslint-disable filenames/match-exported */
@@ -44,19 +43,19 @@ pnpm run lint:error
44
43
  ```
45
44
 
46
45
  :::info
47
- VS Code 编辑器里输入 eslint,会自动出现关于 "eslint-disable" 的提示框,选择提示选项生成对应注释对。
48
-
46
+ Enter eslint in the VS Code editor, a prompt box about `eslint-disable` will automatically appear, select the prompt option to generate the corresponding comment pair.
49
47
  :::
50
48
 
51
- Modern.js ESLint 规则集】要求 [eslint-disable](https://eslint.org/docs/user-guide/configuring/rules#disabling-rules) 必须成对使用,必须明确表达要影响的范围,以及在这个范围内明确表达要禁用什么规则,目的是让**例外**有明确的、最小化的范围,避免 [eslint-disable](https://eslint.org/docs/user-guide/configuring/rules#disabling-rules) 被滥用,导致不属于例外的代码也被禁用了规则。
49
+ [Modern.js ESLint Rule Set] requires that [eslint-disable](https://eslint.org/docs/user-guide/configuring/rules#disabling-rules) must be used in pairs, the scope to be affected must be clearly expressed, and what rules to disable within this scope must be clearly expressed, the purpose is to make **exceptions** Clear, minimized scope to avoid abuse of [eslint-disable](https://eslint.org/docs/user-guide/configuring/rules#disabling-rules), resulting in code that does not belong to the exception being disabled by the rule.
52
50
 
53
- ## Q: 如何自定义 ESLint 规则
51
+ ## Q: How to customize ESLint rules
54
52
 
55
- ### 仓库根目录下 `package.json` 里的 "eslintConfig" 字段
53
+ ### The `eslintConfig` field in `package.json` in the root directory
56
54
 
57
- 这个地方是整个仓库的默认 ESLint 配置,是针对纯 Node.js 代码(只能在 Node.js 里运行)设计的。
55
+ This place is the default ESLint configuration for the entire repository and is designed for pure Node.js code (which can only run in Node.js).
56
+
57
+ If the project does have special requirements or inevitable compatibility issues with some rules (not exceptions), you can add rule configuration here. This configuration will take precedence over the default [Modern.js ESLint ruleset], such as:
58
58
 
59
- 如果项目在某些规则上确实有特殊要求或不可避免的兼容问题(不是例外),可以在这里增加规则配置。该配置会优先于默认的【Modern.js ESLint 规则集】,比如:
60
59
 
61
60
  ```json
62
61
  "eslintConfig": {
@@ -70,16 +69,15 @@ pnpm run lint:error
70
69
 
71
70
  ```
72
71
 
73
- ### `src/.eslintrc.js` 文件
72
+ ### `src/.eslintrc.js`
74
73
 
75
- Modern.js 的应用工程、模块工程,源代码目录里都会默认有这个配置文件,是针对 Universal JS 代码设计的。
74
+ The application project and module project of Modern.js will have this configuration file by default in the source code directory, which is designed for Universal JS code.
76
75
 
77
76
  :::info
78
- Universal JS 代码是既能浏览器端也能在服务器端运行的代码。
79
-
77
+ Universal JS code is code that can run on both the browser side and the server side.
80
78
  :::
81
79
 
82
- 如果项目在某些规则上确实有特殊要求或不可避免的兼容问题(不是例外),可以在这里增加规则配置,该配置会优先于默认的【Modern.js ESLint 规则集】,比如:
80
+ If the project does have special requirements or inevitable compatibility issues with some rules (not exceptions), you can add a rule configuration here, which will take precedence over the default [Modern.js ESLint ruleset], such as:
83
81
 
84
82
  ```js
85
83
  // eslint-disable-next-line import/no-commonjs
@@ -96,7 +94,7 @@ module.exports = {
96
94
  };
97
95
  ```
98
96
 
99
- 如果有需要,还可以继续在不同的子目录里增加 `.eslintrc.js` 文件,针对这个子目录里的代码做特殊配置:
97
+ If necessary, you can continue to add the `.eslintrc.js` file in different subdirectories, and make special configuration for the code in this subdirectory:
100
98
 
101
99
  ```js
102
100
  module.exports = {
@@ -107,13 +105,13 @@ module.exports = {
107
105
  ```
108
106
 
109
107
  :::tip
110
- 注意:没有必要使用 `extends` 字段,会自动继承父目录的配置。
108
+ Note: It is not necessary to use the `extends` field, it will automatically inherit the configuration of the parent directory.
111
109
 
112
110
  :::
113
111
 
114
- ### package.json 里的 `eslintIgnore` 字段
112
+ ### `eslintIgnore` field in `package.json`
115
113
 
116
- 把包含 `.js`、`.jsx`、`.ts`、`.tsx` 文件、但不需要做代码检查和自动修复的目录,添加到 `eslintIgnore` 里,可以优化 ESLint 检查的速度,比如:
114
+ Adding directories that contain `.js`, `.jsx`, `.ts`, `.tsx` files, but do not require code inspection and automatic repair, to `eslintIgnore` can optimize the speed of ESLint inspection, such as:
117
115
 
118
116
  ```json
119
117
  "eslintIgnore": [
@@ -123,25 +121,25 @@ module.exports = {
123
121
  ],
124
122
  ```
125
123
 
126
- ## Q: 如何升级 ESLint 插件的版本
124
+ ## Q: How to upgrade the version of the ESLint plugin
127
125
 
128
- 只要不是 Major 版本的变化(不符合 [Semver](https://semver.org/) 规则的 `^` 符号),就可以直接在业务项目的 `package.json` 里指定这个依赖,删除 Lock 文件(或尝试手动删除 Lock 文件中这个包名的内容),执行 `pnpm install` 重新安装依赖并且生成新的 Lock 文件。
126
+ As long as it is not a change in the Major version (the "^" symbol that does not comply with the [Semver](https://semver.org/) rule), you can specify this dependency directly in the `package.json` of the business project, delete the Lock file (or try to manually delete the Lock file). the contents of this package name in the file), execute `pnpm install` to reinstall the dependency and generate a new Lock file.
129
127
 
130
- 做完这些操作之后,在业务项目的 `./node_modules` 目录里,这个插件应该只存在一份,并且升级到了你指定的版本。
128
+ After doing this, the plugin should only exist in the `./node_modules` directory of the business project and be upgraded to the version you specified.
131
129
 
132
130
  :::tip
133
- - Major 版本就是主版本号。更多信息,请阅读【[Semantic Versioning](https://semver.org/#summary)】。
134
- - 所有被 Modern.js 封装的上游项目(比如 ESLint[ESLint 插件](https://eslint.org/docs/user-guide/configuring/plugins#plugins)[React Router](https://reactrouter.com/) 等),也都可以这样升级。
135
- - Modern.js 也会在每次发版中尽量及时的升级这些上游依赖。
136
- - Major 版本的升级需要由 Modern.js 来发版。
131
+ - Major version is the major version number. For more information, please read [[Semantic Versioning](https://semver.org/#summary) ].
132
+ - All upstream projects encapsulated by Modern.js (such as ESLint, [ESLint plugin](https://eslint.org/docs/user-guide/configuring/plugins#plugins), [React Router](https://reactrouter.com/), etc.) can also be upgraded in this way.
133
+ - Modern.js will also try to upgrade these upstream dependencies as timely as possible in each release.
134
+ - Major version upgrades need to be published by Modern.js.
137
135
 
138
136
  :::
139
137
 
140
- ## Q: WebStorm 有时候会报 ESLint 错误
138
+ ## Q: WebStorm sometimes reports ESLint errors
141
139
 
142
- 由于 WebStorm 认为 ESLint 执行目录是根据 `.eslintrc` 文件来决定的。因此 `src/.eslintrc` 文件位置的放置会导致 `tsconfig.json` 文件指定的位置(项目根目录下)在 `src/` 目录下找不到。
140
+ Since WebStorm believes that the ESLint execution directory is determined based on the `.eslintrc'` file. Therefore, the placement of the `src/.eslintrc` file location will cause the location specified by the `tsconfig.json` file (in the project root directory) to not be found in the'src/'directory.
143
141
 
144
- 此时需要手动配置一下:
142
+ you need to configure it manually:
145
143
 
146
144
  ```json
147
145
  --parser-options=project:../tsconfig.json
@@ -6,7 +6,7 @@ sidebar_position: 11
6
6
 
7
7
  ## Usage
8
8
 
9
- Modern.js internally integrates tools such as [Babel](https://babeljs.io/), [TypeScript](https://www.typescriptlang.org/), [Webpack](https://webpack.js.org/), [PostCSS](https://postcss.org/), [Tailwind CSS] (https://tailwindcss.com/) by default.
9
+ Modern.js internally integrates tools such as [Babel](https://babeljs.io/), [TypeScript](https://www.typescriptlang.org/), [Webpack](https://webpack.js.org/), [PostCSS](https://postcss.org/), [Tailwind CSS](https://tailwindcss.com/) by default.
10
10
 
11
11
  Usually, the default configuration can meet most development needs. When there are special needs, it can be achieved through the underlying configuration.
12
12
 
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  title: Rspack Start
3
- sidebar_position: 12
3
+ sidebar_position: 1
4
4
  ---
5
5
 
6
6
  # Rspack Start
7
7
 
8
- [Rspack](https://www.rspack.org/) is a Rust-based web bundler developed by the ByteDance Web Infra team. The core architecture of Rspack is aligned with the implementation of webpack, and provides out-of-the-box support for commonly used build features.
8
+ [Rspack](https://www.rspack.dev/) is a Rust-based web bundler developed by the ByteDance Web Infra team. The core architecture of Rspack is aligned with the implementation of webpack, and provides out-of-the-box support for commonly used build features.
9
9
 
10
10
  Rspack optimizes compilation performance by:
11
11
 
@@ -13,22 +13,18 @@ Rspack optimizes compilation performance by:
13
13
  - Take full advantage of multi-core, and the entire compilation process is fully optimized for multi-threading.
14
14
  - On-demand compilation based on request (Lazy Compilation), reducing the number of modules per compilation to improve the speed of cold start.
15
15
 
16
- ## Initializing an rspack project
16
+ ## Initializing an Rspack project
17
17
 
18
- The Modern.js generator provides an interactive question-and-answer interface to initialize a project. To create an rspack project, simply select the **rspack** build tool by running:
18
+ The Modern.js generator provides an interactive question-and-answer interface to initialize a project. To create an Rspack project, simply select the **Rspack** build tool by running:
19
19
 
20
- ```bash
21
- $ npx @modern-js/create myapp
22
- ? Please select the solution you want to create: Web App Solution
23
- ? Development Language: TS
24
- ? Package Management Tool: pnpm
25
- ? Build Tools: rspack
26
- ```
20
+ import InitRspackApp from "@site-docs-en/components/init-rspack-app"
21
+
22
+ <InitRspackApp />
27
23
 
28
24
  After the project is created, you can experience the project by running `pnpm run dev`. For more project information, please refer to [Quick Start](/guides/get-started/quick-start.html).
29
25
 
30
26
  :::tip
31
- When using rspack as the bundler, the following features are currently not supported:
27
+ When using Rspack as the bundler, the following features are currently not supported:
32
28
 
33
29
  - Server-side rendering (SSR)
34
30
  - Static Site Generation (SSG)
@@ -37,17 +33,17 @@ When using rspack as the bundler, the following features are currently not suppo
37
33
 
38
34
  :::
39
35
 
40
- ## Migrating from webpack to rspack
36
+ ## Migrating from webpack to Rspack
41
37
 
42
- You can enable rspack build by running `pnpm run new`:
38
+ You can enable Rspack build by running `pnpm run new`:
43
39
 
44
40
  ```bash
45
41
  $ pnpm run new
46
42
  ? Action: Enable features
47
- ? Enable features: Enable rspack Build
43
+ ? Enable features: Enable Rspack Build
48
44
  ```
49
45
 
50
- After executing the command, enable the rspack build in `modern.config.ts`:
46
+ After executing the command, enable the Rspack build in `modern.config.ts`:
51
47
 
52
48
  ```ts title=modern.config.ts
53
49
  import appTools, { defineConfig } from '@modern-js/app-tools';
@@ -65,5 +61,5 @@ export default defineConfig<'rspack'>({
65
61
  ```
66
62
 
67
63
  :::tip
68
- Migrating from webpack to rspack may have some differences in build and configuration capabilities. For more details, please refer to [Configuration Differences](https://modernjs.dev/builder/en/guide/advanced/rspack-start.html#migrating-from-webpack-to-rspack)
64
+ Migrating from webpack to Rspack may have some differences in build and configuration capabilities. For more details, please refer to [Configuration Differences](https://modernjs.dev/builder/en/guide/advanced/rspack-start.html#migrating-from-webpack-to-rspack).
69
65
  :::
@@ -1,23 +1,37 @@
1
1
  ---
2
2
  title: Custom Web Server
3
- sidebar_position: 2
3
+ sidebar_position: 3
4
4
  ---
5
5
  # Custom Web Server
6
6
 
7
- Modern.js 作为以客户端为中心的开发框架,对服务端的定制能力较弱。而在有些开发场景下,需要定制特殊的服务端逻辑,例如用户鉴权、请求预处理、添加页面渲染骨架等。
7
+ As a client side-centric development framework, Modern.js has weak customization capabilities on the server side. In some development scenarios, special server level logic needs to be customized, such as user authentication, request preprocessing, and adding page rendering skeletons.
8
8
 
9
- 因此 Modern.js 提供了一种功能,让项目可以在给定的范围内扩展 Modern.js 内置的 Web Server,来实现相应的需求。
9
+ Some developers may be wondering, Modern.js already provides [BFF](/guides/advanced-features/bff/function.html), why do you need **Custom Web Server**.
10
10
 
11
- ## 创建自定义 Web Server
11
+ Because by default, page routing does not go through BFF, it has no way to provide server-side custom logic for page access. The reason for this design is that we do not want the service that controls the page to be bound to the BFF service, so as to avoid the BFF framework restricting how the page is deployed.
12
12
 
13
- 在项目根目录执行 `pnpm run new` 命令,按照如下选择,开启「自定义 Web Serve」功能:
13
+ For example, hosting pages separately from BFF, deploying page services to non-Node environments, or customizing for deployment platforms, etc.
14
+
15
+ For the above reasons, Modern.js provides three ways that projects can customize server level capabilities progressively according to their needs.
16
+
17
+ :::warning
18
+ The three extension methods cannot work at the same time, and developers need to choose the appropriate method according to the scenario.
19
+ :::
20
+
21
+ ## Extending Web Server with API
22
+
23
+ The first way is to customize the server level at a specific life cycle through the server level runtime API provided by Modern.js. The purpose of providing this way is that in some cases, developers do not need to control the full Web Server, but only need to add server level logic.
24
+
25
+ Because the full web server cannot be controlled this way, and the extension logic **only takes effect when the page is requested**. Therefore, it is relatively simple to apply to server level logic, and you do not want to create additional BFFs or BFFs and pages without common server level logic scenarios.
26
+
27
+ You can execute the'pnpm run new 'command in the project root directory to enable the "Custom Web Serve" function:
14
28
 
15
29
  ```bash
16
- ? 请选择你想要的操作 创建工程元素
17
- ? 创建工程元素 新建「自定义 Web Server」源码目录
30
+ ? Action Create project element
31
+ ? New "Custom Web Server" source code directory
18
32
  ```
19
33
 
20
- 执行命令后,在 `modern.config.ts` 中注册 Server 插件:
34
+ After executing the command, register the `@modern-js/plugin-server` plugin in `modern.config.ts`:
21
35
 
22
36
  ```ts title="modern.config.ts"
23
37
  import serverPlugin from '@modern-js/plugin-server';
@@ -27,31 +41,84 @@ export default defineConfig({
27
41
  });
28
42
  ```
29
43
 
30
- 项目目录下会新建 `server/index.ts` 文件,自定义逻辑在这个文件中编写。
44
+ After the function is turned on, the `server/index.ts` file will be automatically created in the project directory, and custom logic can be written in this file. Modern.js provides two types of APIs, **Hook** and **Middleware**, to extend Web Server.
45
+
46
+ ### Hook
31
47
 
32
- ## 使用 API 扩展 Web Server
48
+ The Hook provided by Modern.js is used to control the built-in logic in the Web Server, and all page requests go through the Hook.
33
49
 
34
- Modern.js 提供了 **Hook** **Middleware** 两类 API 来扩展 Web Server。
50
+ There are currently two Hooks provided, namely `AfterMatch` and `AfterRender`, which can be used to modify the rendering results. It can be written in `server/index.ts` like this:
35
51
 
36
- ### Hook
52
+ ```ts
53
+ import type { AfterMatchHook, AfterRenderHook } from '@modern-js/runtime/server';
54
+
55
+ export const afterMatch: AfterMatchHook = (ctx, next) => {
56
+ next();
57
+ }
58
+
59
+ export const afterRender: AfterRenderHook = (ctx, next) => {
60
+ next();
61
+ }
62
+ ```
37
63
 
38
- Hook 可以控制 Web Server 对请求处理的内置逻辑,非 BFF 请求会经过 Hook 的处理。
64
+ Projects should have the following best practices when using Hook:
39
65
 
40
- Hook 不可以使用运行时框架拓展。
66
+ 1. Permission verification in afterMatch.
67
+ 2. Do Rewrite and Redirect in afterMatch.
68
+ 3. Do HTML content injection in afterRender.
41
69
 
42
- 详细 API 可以查看 [Hook](/apis/app/runtime/web-server/hook)。
70
+ :::note
71
+ For more detail, see [Hook](/apis/app/runtime/web-server/hook)。
72
+ :::
43
73
 
44
74
  ### Middleware
45
75
 
46
- Middleware 可以为 Web Server 添加前置中间件,只有 SSR 请求会经过 Middleware 的处理。
76
+ For some projects, there may be more requirements at the server level, Modern.js provides Middleware to add pre-middleware for Web Server. It can only run in a Node environment, so if the project is deployed to another environment, such as a Worker environment, Middleware cannot be used.
47
77
 
48
- Middleware 可以使用运行时框架拓展。
78
+ Modern.js provides a set of APIs by default for projects to use:
49
79
 
50
- 详细 API 可以查看 [Hook](/apis/app/runtime/web-server/middleware)。
80
+ ```ts
81
+ import { Middlewre } from '@modern-js/runtime/server';
51
82
 
52
- ## 完全自定义的 Web Server
83
+ export const middleware = (context, next) => {
84
+ const { source: { req, res } } = context;
85
+ console.log(req.url);
86
+ next();
87
+ };
88
+ ```
53
89
 
54
90
  :::note
55
- 敬请期待
91
+ For more detail, see [Middleware] (/apis/app/runtime/web-server/middleware).
92
+ :::
93
+
94
+ Projects should have the following best practices when using Middleware:
95
+
96
+ 1. In Middleware, you can directly operate origin request and response objects, do event tracking, and inject Node services (databases, Redis, etc.) that may be used for SSR rendering.
97
+ 2. Marking and crawler optimization can be done in Middleware.
98
+ 3. In Middleware, you can ignore the default rendering and customize the rendering process.
99
+
100
+ **In general, in CSR projects, using Hook can basically meet all the needs of simple scenarios. In SSR projects, Middleware can be used for more complex Node extensions.**
101
+
102
+ ## Managed Page Requests with BFF
103
+
104
+ The second way is to use BFF to Managed page rendering. In this way, all requests will first hit the BFF service.
105
+
106
+ This method can uniformly control the server level logic of all requests through BFF. Therefore, it is suitable for scenarios where the server level logic is complex, and BFF and pages need common server level logic. But it still relies on the Web Server of Modern.js as a whole, and cannot run the logic on existing services.
107
+
108
+ To use this method, we need to first enable the "BFF" function through `pnpm new`. Then add [`bff.enableHandleWeb`](/configure/app/bff/enable-handle-web.html) configuration in the configuration file:
56
109
 
110
+ ```ts
111
+ export default defineConfig({
112
+ bff: {
113
+ enableHandleWeb: true,
114
+ },
115
+ });
116
+ ```
117
+
118
+ When this value is set to `true`, page request traffic also goes through the BFF, and the logic built into Modern.js for page rendering defaults to running as the last middleware for the BFF service.
119
+
120
+ ## Fully Customized Web Server
121
+
122
+ :::note
123
+ Comming soon..
57
124
  :::
@@ -6,7 +6,7 @@ sidebar_position: 2
6
6
 
7
7
  **Modern.js uses [Modern.js Builder](https://modernjs.dev/builder) to build your Web App.**
8
8
 
9
- Modern.js Builder is one of the core components of Modern.js. It is A Build Engine for web development. and can be used independently of Modern.js. Modern.js Builder supports multiple bundlers such as webpack and rspack, and it uses webpack by default.
9
+ Modern.js Builder is one of the core components of Modern.js. It is A build engine for web development. and can be used independently of Modern.js. Modern.js Builder supports multiple bundlers such as webpack and Rspack, and it uses webpack by default.
10
10
 
11
11
  ## Build Architecture
12
12