@modern-js/main-doc 0.0.0-next-1678243962105 → 0.0.0-next-1678284408052

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/CHANGELOG.md +3 -2
  2. package/en/guides/advanced-features/eslint.mdx +30 -32
  3. package/en/guides/topic-detail/framework-plugin/extend.mdx +20 -19
  4. package/en/guides/topic-detail/framework-plugin/hook-list.mdx +156 -155
  5. package/en/guides/topic-detail/framework-plugin/hook.mdx +58 -43
  6. package/en/guides/topic-detail/framework-plugin/implement.mdx +47 -49
  7. package/en/guides/topic-detail/framework-plugin/introduction.mdx +22 -23
  8. package/en/guides/topic-detail/framework-plugin/plugin-api.mdx +13 -13
  9. package/en/guides/topic-detail/framework-plugin/relationship.mdx +30 -30
  10. package/en/guides/topic-detail/micro-frontend/c01-introduction.mdx +17 -17
  11. package/en/guides/topic-detail/micro-frontend/c02-development.mdx +76 -78
  12. package/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +57 -51
  13. package/en/guides/topic-detail/micro-frontend/c04-communicate.mdx +11 -11
  14. package/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +13 -13
  15. package/en/guides/topic-detail/model/auto-actions.mdx +18 -21
  16. package/en/guides/topic-detail/model/computed-state.mdx +27 -25
  17. package/en/guides/topic-detail/model/define-model.mdx +14 -14
  18. package/en/guides/topic-detail/model/faq.mdx +12 -13
  19. package/en/guides/topic-detail/model/manage-effects.mdx +43 -52
  20. package/en/guides/topic-detail/model/model-communicate.mdx +47 -45
  21. package/en/guides/topic-detail/model/performance.mdx +22 -23
  22. package/en/guides/topic-detail/model/quick-start.mdx +29 -28
  23. package/en/guides/topic-detail/model/redux-integration.mdx +7 -7
  24. package/en/guides/topic-detail/model/test-model.mdx +11 -11
  25. package/en/guides/topic-detail/model/typescript-best-practice.mdx +16 -15
  26. package/en/guides/topic-detail/model/use-model.mdx +40 -45
  27. package/en/guides/topic-detail/model/use-out-of-modernjs.mdx +16 -16
  28. package/en/guides/troubleshooting/cli.mdx +2 -2
  29. package/package.json +3 -3
  30. package/zh/guides/topic-detail/framework-plugin/plugin-api.mdx +2 -2
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @modern-js/main-doc
2
2
 
3
- ## 0.0.0-next-1678243962105
3
+ ## 0.0.0-next-1678284408052
4
4
 
5
5
  ### Patch Changes
6
6
 
@@ -12,5 +12,6 @@
12
12
 
13
13
  修复 Typo
14
14
 
15
+ - Updated dependencies [9736c6a43]
15
16
  - Updated dependencies [2c1151271]
16
- - @modern-js/builder-doc@0.0.0-next-1678243962105
17
+ - @modern-js/builder-doc@0.0.0-next-1678284408052
@@ -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
@@ -1,24 +1,24 @@
1
1
  ---
2
- title: 扩展插件 Hook
2
+ title: Extending
3
3
  sidebar_position: 5
4
4
  ---
5
- # 扩展插件 Hook
5
+ # Extending Plugin Hooks
6
6
 
7
- 本小节介绍如何通过动态注册 [Hook 模型](/guides/topic-detail/framework-plugin/hook) 的方式来扩展插件 Hook。
7
+ This section describes how to extend plugin Hooks by dynamically registering [Hook models](/guides/topic-detail/framework-plugin/hook).
8
8
 
9
- ## 示例
9
+ ## Example
10
10
 
11
- 这里我们用一个简单的例子演示一下。假设我们要添加一些管理控制台输出信息的 Hook。
11
+ Here is a simple example to demonstrate how to extend plugin Hooks by adding Hooks that manage console output.
12
12
 
13
- 首先我们初始化一个空的项目文件,并添加基础依赖:
13
+ First, we initialize an empty project file and add basic dependencies:
14
14
 
15
15
  ```bash
16
16
  $ npx @modern-js/create modern-js-demo
17
17
  ```
18
18
 
19
- ### 创建 Hook
19
+ ### Creating Hooks
20
20
 
21
- 我们先创建一个 Hook 模型:
21
+ First, let's create a Hook model:
22
22
 
23
23
  ```ts title=config/plugin/myPlugin.ts
24
24
  import { createWaterfall } from '@modern-js/plugin';
@@ -26,7 +26,7 @@ import { createWaterfall } from '@modern-js/plugin';
26
26
  const message = createWaterfall<string[]>();
27
27
  ```
28
28
 
29
- 然后注册它:
29
+ then register:
30
30
 
31
31
  ```ts title=config/plugin/myPlugin.ts
32
32
  import type { CliPlugin } from '@modern-js/core';
@@ -40,7 +40,7 @@ export default (): CliPlugin => ({
40
40
  });
41
41
  ```
42
42
 
43
- 添加 Hook 类型:
43
+ add Hook types:
44
44
 
45
45
  ```ts title=config/plugin/myPlugin.ts
46
46
  declare module '@modern-js/core' {
@@ -50,9 +50,9 @@ declare module '@modern-js/core' {
50
50
  }
51
51
  ```
52
52
 
53
- ### 使用 Hook
53
+ ### Using Hooks
54
54
 
55
- 创建插件,通过 `commands` Hook 函数,添加命令处理逻辑:
55
+ Create a plugin and add command handling logic through the `commands` Hook function:
56
56
 
57
57
  ```ts title=config/plugin/myPlugin.ts
58
58
  import type { CliPlugin } from '@modern-js/core';
@@ -74,7 +74,7 @@ export default (): CliPlugin => ({
74
74
  });
75
75
  ```
76
76
 
77
- 最后 `config/plugin/myPlugin.ts` 的状态是:
77
+ now `config/plugin/myPlugin.ts` is:
78
78
 
79
79
  ```ts title=config/plugin/myPlugin.ts
80
80
  import { createWaterfall } from '@modern-js/plugin';
@@ -109,7 +109,7 @@ declare module '@modern-js/core' {
109
109
  }
110
110
  ```
111
111
 
112
- 然后在 `modern.config.ts` 中添加这个插件:
112
+ Then add this plugin in `modern.config.ts`:
113
113
 
114
114
  ```ts title="modern.config.ts"
115
115
  import { defineConfig } from '@modern-js/app-tools';
@@ -120,9 +120,9 @@ export default defineConfig({
120
120
  });
121
121
  ```
122
122
 
123
- 这时运行 `npx modern message` 就会执行相关逻辑,但由于没有收集到任何信息,所以控制台输出为空。
123
+ Now, run `npx modern message`, and the related logic will be executed, but no information is collected, so the console output is empty.
124
124
 
125
- 那这里我们添加一个:
125
+ add:
126
126
 
127
127
  ```ts title=config/plugin/otherPlugin.ts
128
128
  import type { CliPlugin } from '@modern-js/core';
@@ -140,7 +140,7 @@ export default (): CliPlugin => ({
140
140
  });
141
141
  ```
142
142
 
143
- 将它添加到配置中:
143
+ add to config:
144
144
 
145
145
  ```ts title="modern.config.ts"
146
146
  import { defineConfig } from '@modern-js/app-tools';
@@ -152,7 +152,7 @@ export default defineConfig({
152
152
  });
153
153
  ```
154
154
 
155
- 这时运行 `npx modern message` 就可以在控制台看到信息了:
155
+ run `npx modern message`, then we can get follow in console:
156
156
 
157
157
  ```bash
158
158
  $ modern message
@@ -160,4 +160,5 @@ $ modern message
160
160
  [foo] line 1
161
161
  ```
162
162
 
163
- 以上面这种方式就可以扩展出拥有各种能力的插件 Hook。
163
+ By using the above approach, you can extend plugin Hooks with various capabilities.
164
+