@modern-js/main-doc 2.22.1 → 2.23.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/docs/en/apis/app/commands.mdx +5 -5
  3. package/docs/en/apis/app/hooks/config/storybook.mdx +24 -0
  4. package/docs/en/apis/app/hooks/src/stories.mdx +1 -1
  5. package/docs/en/apis/app/runtime/core/bootstrap.mdx +5 -5
  6. package/docs/en/apis/app/runtime/core/use-loader.mdx +2 -2
  7. package/docs/en/apis/app/runtime/core/use-module-apps.mdx +2 -2
  8. package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +1 -1
  9. package/docs/en/apis/app/runtime/testing/render.mdx +1 -1
  10. package/docs/en/components/bff-proxy-path-rewrite.mdx +16 -0
  11. package/docs/en/components/bff-proxy-principle.mdx +1 -0
  12. package/docs/en/components/enable-bff-caution.mdx +3 -0
  13. package/docs/en/components/global-proxy-config.mdx +33 -13
  14. package/docs/en/configure/app/bff/enable-handle-web.mdx +5 -5
  15. package/docs/en/configure/app/bff/prefix.mdx +6 -6
  16. package/docs/en/configure/app/bff/proxy.mdx +19 -30
  17. package/docs/en/configure/app/builder-plugins.mdx +1 -1
  18. package/docs/en/configure/app/plugins.mdx +19 -19
  19. package/docs/en/configure/app/runtime/intro.mdx +28 -4
  20. package/docs/en/configure/app/runtime/master-app.mdx +1 -1
  21. package/docs/en/configure/app/runtime/router.mdx +2 -2
  22. package/docs/en/configure/app/server/base-url.mdx +4 -4
  23. package/docs/en/configure/app/server/enable-framework-ext.mdx +4 -4
  24. package/docs/en/configure/app/server/port.mdx +6 -6
  25. package/docs/en/configure/app/server/public-routes.mdx +5 -5
  26. package/docs/en/configure/app/server/routes.mdx +13 -13
  27. package/docs/en/configure/app/server/ssr-by-entries.mdx +4 -4
  28. package/docs/en/configure/app/server/ssr.mdx +5 -5
  29. package/docs/en/configure/app/testing/transformer.mdx +4 -8
  30. package/docs/en/configure/app/usage.mdx +5 -5
  31. package/docs/en/guides/advanced-features/code-split.mdx +15 -14
  32. package/docs/en/guides/advanced-features/compatibility.mdx +3 -24
  33. package/docs/en/guides/advanced-features/rspack-start.mdx +0 -1
  34. package/docs/en/guides/advanced-features/ssr.mdx +2 -2
  35. package/docs/en/guides/advanced-features/testing.mdx +8 -7
  36. package/docs/en/guides/advanced-features/using-storybook.mdx +44 -0
  37. package/docs/en/guides/advanced-features/web-server.mdx +16 -16
  38. package/docs/en/guides/basic-features/alias.mdx +11 -9
  39. package/docs/en/guides/basic-features/env-vars.mdx +14 -14
  40. package/docs/en/guides/basic-features/html.mdx +41 -43
  41. package/docs/en/guides/basic-features/mock.mdx +10 -10
  42. package/docs/en/guides/topic-detail/framework-plugin/implement.mdx +4 -4
  43. package/docs/en/guides/topic-detail/framework-plugin/introduction.mdx +1 -1
  44. package/docs/en/guides/troubleshooting/cli.mdx +13 -13
  45. package/docs/en/guides/troubleshooting/dependencies.mdx +25 -25
  46. package/docs/en/tutorials/first-app/c03-css.mdx +1 -1
  47. package/docs/zh/apis/app/commands.mdx +4 -4
  48. package/docs/zh/apis/app/hooks/config/storybook.mdx +24 -0
  49. package/docs/zh/apis/app/hooks/src/stories.mdx +1 -1
  50. package/docs/zh/apis/app/runtime/testing/render.mdx +1 -1
  51. package/docs/zh/components/bff-proxy-path-rewrite.mdx +16 -0
  52. package/docs/zh/components/bff-proxy-principle.mdx +1 -0
  53. package/docs/zh/components/enable-bff-caution.mdx +4 -0
  54. package/docs/zh/components/global-proxy-config.mdx +35 -11
  55. package/docs/zh/configure/app/bff/enable-handle-web.mdx +3 -3
  56. package/docs/zh/configure/app/bff/prefix.mdx +2 -3
  57. package/docs/zh/configure/app/bff/proxy.mdx +11 -21
  58. package/docs/zh/configure/app/runtime/intro.mdx +1 -1
  59. package/docs/zh/configure/app/server/base-url.mdx +1 -1
  60. package/docs/zh/configure/app/server/public-routes.mdx +2 -2
  61. package/docs/zh/configure/app/server/routes.mdx +2 -2
  62. package/docs/zh/configure/app/server/ssr-by-entries.mdx +3 -3
  63. package/docs/zh/configure/app/server/ssr.mdx +1 -1
  64. package/docs/zh/configure/app/testing/transformer.mdx +6 -3
  65. package/docs/zh/configure/app/usage.mdx +9 -9
  66. package/docs/zh/guides/advanced-features/code-split.mdx +13 -12
  67. package/docs/zh/guides/advanced-features/rspack-start.mdx +0 -1
  68. package/docs/zh/guides/advanced-features/ssr.mdx +2 -2
  69. package/docs/zh/guides/advanced-features/testing.mdx +4 -4
  70. package/docs/zh/guides/advanced-features/using-storybook.mdx +44 -0
  71. package/docs/zh/guides/basic-features/alias.mdx +5 -3
  72. package/docs/zh/guides/basic-features/html.mdx +9 -9
  73. package/docs/zh/guides/basic-features/mock.mdx +2 -2
  74. package/docs/zh/guides/topic-detail/_category_.json +1 -1
  75. package/docs/zh/guides/troubleshooting/cli.mdx +1 -1
  76. package/docs/zh/guides/troubleshooting/dependencies.mdx +1 -1
  77. package/package.json +7 -6
@@ -4,7 +4,7 @@ sidebar_position: 8
4
4
  ---
5
5
  # Alias
6
6
 
7
- Modern.js allow aliases in JS and CSS, and the following aliases are built in:
7
+ Modern.js allows you to use alias to import modules from custom directories in JS and CSS, and comes with the following built-in alias:
8
8
 
9
9
  ```js
10
10
  {
@@ -14,11 +14,11 @@ Modern.js allow aliases in JS and CSS, and the following aliases are built in:
14
14
  ```
15
15
 
16
16
  :::info
17
- When the optional features is enable, the generator will also add built-in aliases dynamically. For example, when BFF is enabled, the `@api` alias will be added by default.
17
+ When enabling optional features, the `new` command will also dynamically add built-in alias specific to the features. For example, when enabling BFF, the `@api` alias is added by default.
18
18
 
19
19
  :::
20
20
 
21
- For example, import the modules from the `src/common/` directory in the `src/App.tsx` file:
21
+ For example, importing modules from the `src/common` directory in the `src/App.tsx` file:
22
22
 
23
23
  ```bash
24
24
  .
@@ -27,17 +27,19 @@ For example, import the modules from the `src/common/` directory in the `src/App
27
27
  │ │ └── base.css
28
28
  │ └── utils
29
29
  │ └── index.ts
30
- ├── App.tsx
30
+ └── App.tsx
31
31
  ```
32
32
 
33
- the code in `src/App.tsx`:
33
+ The code in `src/App.tsx` is as follows:
34
34
 
35
35
  ```ts
36
36
  import utils from '@/src/common/utils';
37
37
  import '@/src/common/styles/base.css';
38
38
  ```
39
39
 
40
- Modern.js also provides a way to config aliases. Adding the `@common` alias as an example. For TypeScript projects, you only need to configure `compilerOptions.paths` under the project root directory `tsconfig.json` as follows:
40
+ Modern.js also provides a way to customize alias. For example, adding the `@common` alias is as follows:
41
+
42
+ For TypeScript projects, just set `compilerOptions.paths` in the project's `tsconfig.json`:
41
43
 
42
44
  ```json
43
45
  {
@@ -50,9 +52,9 @@ Modern.js also provides a way to config aliases. Adding the `@common` alias as a
50
52
  }
51
53
  ```
52
54
 
53
- JavaScript project can config by [`source.alias`](/configure/app/source/alias) in `modern.config.js`:
55
+ For JavaScript projects, set `source.alias` in `modern.config.js`:
54
56
 
55
- ```ts title="modern.config.ts"
57
+ ```ts title="modern.config.js"
56
58
  export default defineConfig({
57
59
  source: {
58
60
  alias: {
@@ -62,4 +64,4 @@ export default defineConfig({
62
64
  });
63
65
  ```
64
66
 
65
- For detailed usage, please refer to [source.alias documentation](/configure/app/source/alias).
67
+ For the specific usage of alias configuration, please refer to the [source.alias documentation](/configure/app/source/alias).
@@ -10,15 +10,15 @@ Modern.js provides support for environment variables, including built-in environ
10
10
 
11
11
  ### ASSET_PREFIX
12
12
 
13
- The current path prefix of resource file, which is a **read-only** environment variable.
13
+ The current path prefix of the resource file, which is a read-only environment variable.
14
14
 
15
15
  ### NODE_ENV
16
16
 
17
17
  The current execution environment and is a **read-only** environment variable whose have different values under different execution commands:
18
18
 
19
- - `production`: the default value when exec `modern build` or `modern serve`.
20
- - `test`: the default value when exec `modern test`.
21
- - `development`: the default value when exec `modern dev`, alse the default value of other case.
19
+ - `production`: Default value when running `modern build` or `modern serve`.
20
+ - `test`: Default value when running `modern test`.
21
+ - `development`: Default value when running `modern dev`, also the default value in other cases.
22
22
 
23
23
  ### MODERN_ENV
24
24
 
@@ -33,7 +33,7 @@ MODERN_ENV priority is higher than NODE_ENV.
33
33
 
34
34
  When using `@modern-js/runtime`, Modern.js will automatically inject `MODERN_TARGET` to distinguish between SSR and CSR environments.
35
35
 
36
- You can use `process.env.MODERN_TARGET` to judge the environment and execute the appropriate code.
36
+ You can use `process.env.MODERN_TARGET` to determine the environment and execute appropriate code.
37
37
 
38
38
  ```ts title="App.tsx"
39
39
  function App() {
@@ -65,7 +65,7 @@ function App() {
65
65
  This can provide different outputs for different environments to ensure that the bundle size is minimized. It can also be convenient to deal with some side effects for different environments.
66
66
 
67
67
  :::note Dead Code Elimination
68
- In the production environment, minimizers such as Terser and SWC will analyze the code and remove dead code to reduce the bundle size. This process is called "Dead Code Elimination" (DCE).
68
+ In production environment, minimizers such as Terser and SWC will analyze the code and remove dead code to reduce the bundle size. This process is called "Dead Code Elimination" (DCE).
69
69
 
70
70
  For example, the code inside the `if (false)` statement will be removed, while the code inside the `if (true)` will be preserved.
71
71
 
@@ -75,9 +75,9 @@ If you do not use `process.env.MODERN_TARGET` as described above, the code minim
75
75
 
76
76
  ## Custom Environment Variables
77
77
 
78
- Custom environment variables can be specified in both `shell` and `.env` files.
78
+ You can specify custom environment variables in both `shell` and `.env` files.
79
79
 
80
- ### Specify via `shell`
80
+ ### Via `shell`
81
81
 
82
82
  Add custom environment variables before the command:
83
83
 
@@ -85,7 +85,7 @@ Add custom environment variables before the command:
85
85
  REACT_APP_FOO=123 BAR=456 pnpm run dev
86
86
  ```
87
87
 
88
- ### Specify via `.env` file
88
+ ### Via `.env` file
89
89
 
90
90
  Create a `.env` file in the project root and add custom environment variables, which are added to the Node.js process by default, for example:
91
91
 
@@ -97,7 +97,7 @@ BAR=456
97
97
  The `.env` file follows the following loading rules:
98
98
 
99
99
  - `.env`: default.
100
- - `.env.{ MODERN_ENV | NODE_ENV }`: Setting environment variables for a specific environment overrides the same in `.env`.
100
+ - `.env.{ MODERN_ENV | NODE_ENV }`: Overrides `.env` for a specific environment.
101
101
 
102
102
  When you need to use different config according to the environment, you can define environment variables in the `.env` file corresponding to the environment name, and manually set the execution environment when starting the project.
103
103
 
@@ -137,7 +137,7 @@ In custom HTML templates, you can also use such environment variables directly.
137
137
 
138
138
  ### Any Other Names
139
139
 
140
- If you need to use environment variables with any other names in your code, you can config [`source.globalVars`](/configure/app/source/global-vars), for example:
140
+ If you need to use environment variables with any other names in your code, you can configure them in [`source.globalVars`](/configure/app/source/global-vars). For example:
141
141
 
142
142
  ```ts title="modern.config.ts"
143
143
  export default defineConfig({
@@ -149,7 +149,7 @@ export default defineConfig({
149
149
  });
150
150
  ```
151
151
 
152
- At this point, the `process.env.VERSION` in the code will be replaced with the value of `VERSION` in the environment variables.
152
+ At this point, the `process.env.VERSION` in the code will be replaced by the value of `VERSION` in the environment variables.
153
153
 
154
154
  :::note
155
155
  `source.globalVars` also supports replacing other expressions or strings with specified values, not limited to environment variables.
@@ -158,7 +158,7 @@ At this point, the `process.env.VERSION` in the code will be replaced with the v
158
158
 
159
159
  ## Use Global Replacement
160
160
 
161
- In addition to environment variables, Modern.js also supports replacing variables in code with other values or expressions, which can be used like distinguish development environment and production environment in code.
161
+ In addition to environment variables, Modern.js also supports replacing variables in code with other values or expressions, which can be used to distinguish between development environment and production environment in code.
162
162
 
163
163
  For example, converts the expression `TWO` to `1 + 1`:
164
164
 
@@ -179,4 +179,4 @@ const foo = TWO;
179
179
  const foo = 1 + 1;
180
180
  ```
181
181
 
182
- In most cases, `source.globalVars` is already sufficient to replace variables. But the values passed in by `source.globalVars` will be serialized by JSON by default. So it cannot be replaced like `1 + 1` in the example above, at this time, we need use [`source.define`](/configure/app/source/define).
182
+ In most cases, `source.globalVars` is already sufficient to replace variables. But the values passed in by `source.globalVars` will be serialized by JSON by default. So it cannot be replaced like `1 + 1` in the example above, at this time, we need to use [`source.define`](/configure/app/source/define).
@@ -4,13 +4,13 @@ sidebar_position: 9
4
4
  ---
5
5
  # HTML Template
6
6
 
7
- Modern.js provides **JSX syntax** and **HTML(EJS) syntax** for customizing HTML template.
7
+ Modern.js provides **JSX syntax** and **HTML(EJS) syntax** to customize the HTML template.
8
8
 
9
- ## JSX syntax
9
+ ## JSX Syntax
10
10
 
11
- Modern.js convention, in the `src/`, or in the entry directory, you can create `Document.[jt]sx` and export a component by default. The rendering result of this component can be used as an HTML template for the entry.
11
+ According to Modern.js conventions, you can create a `Document.[jt]sx` file under `src/` or the entry directory and default export a component". The rendering result of this component can be used as the HTML template of the entry.
12
12
 
13
- For example the following directory structure:
13
+ For example, consider the following directory structure:
14
14
 
15
15
  ```bash
16
16
  .
@@ -24,44 +24,42 @@ For example the following directory structure:
24
24
  └── modern-app-env.d.ts
25
25
  ```
26
26
 
27
- `entry-a` will take precedence over the `Docoument.[jt]sx` file under the current entry. If the current entry does not have a `Document.[jt]sx` file, such as `entry-b`, it will look for the `Document.[jt]sx` file in the root directory.
27
+ `entry-a` will use the `Docoument.[jt]sx` file under the current entry as the template. If there is no `Document.[jt]sx` file under the current entry, like `entry-b`, it will look for the `Document.[jt]sx` file under the root directory.
28
28
 
29
- If not, it will go to the the logic of traditional templates.
29
+ If not found, default template will be used.
30
30
 
31
- ### HTML Component
31
+ ### HTML Components
32
32
 
33
- Modern.js provides a list of components for rendering pages to help developers generate templates, which can be exported from `@modern-js/runtime/document`:
33
+ Modern.js provides some components for rendering pages to help developers generate templates. These components can be used from `@modern-js/runtime/document`:
34
34
 
35
35
  ```tsx
36
36
  import { Html, Body, Root, Head, Scripts } from '@modern-js/runtime/document';
37
37
  ```
38
38
 
39
- These components are rendered:
39
+ - `Html`: provide the ability of native HTML Element and and render necessary components that the developer did not add by default. `<Head>` and `<Body>` must exist, and other components can be assembled as needed.
40
40
 
41
- - `Html`: Provide the ability of native HTML Elements, and render necessary components that the developer did not add by default. `<Head>` and `<Body>` must exist, and other components can be assembled by selecting appropriate components on demand.
41
+ - `Body`: provide the ability of native Body Element and needs to contain the `<Root>` component internally. It also supports other elements as child elements at the same time, such as adding footers.
42
42
 
43
- - `Body`: Provide the ability of native Body Element, which needs to contain the `<Root>` component internally, and also supports other elements as child elements at the same time, such as adding footers.
43
+ - `Root`: the root node `<div id='root'></div>` to be rendered. The default id of the root node is `id = 'root'`. You can set `props.rootId` to change the id attribute. Child components can be added and will be rendered in the HTML template. After React rendering is complete, it will be overwritten and is generally used to implement global Loading.
44
44
 
45
- - `Root`: React root element `<div id='root'></div>`. the default element id is `id = 'root'`, can set `props.rootId` to change the id.Child components can be added, and will also be rendered into HTML templates, which will be overwritten when React rendering is complete, generally used to implement global Loading.
45
+ - `Head`: provide the ability of native Head Element and automatically fills in `<meta>` and `<Scripts>` components.
46
46
 
47
- - `Head`: Provides native Head Element capabilities and automatically populates `<meta>`, as well as the `<Scripts>` component.
47
+ - `Scripts`: provide the ability to adjust the position of script tags injected into the HTML during the build process. By default, it is placed in the `<Head>` component.
48
48
 
49
- - `Scripts`: The script content generated by the webpack, which can be used to adjust the position of the bundle result, is placed in the `<Head>` component by default.
49
+ - `Comment`: retain user-written comments like `<!-- gateway -->` and outputs them to the rendered HTML.
50
50
 
51
- - `Comment`: Make the comment like `<!-- gateway -->`, could be stay to the html that final render.
51
+ ### Template Parameters
52
52
 
53
- ### Template Params
53
+ Because it is in JSX format, various variables can be used freely in the component to assign values to various custom components in `Document.[jt]sx`.
54
54
 
55
- Because it is in the form of JSX, in `Document.[jt]sx`, you can use various variables in the component to assign values to various custom components more freely.
55
+ Modern.js also provides `DocumentContext` to provide some configuration and environment parameters for easy access. The main parameters are:
56
56
 
57
- At the same time, Modern.js provides `DocumentContext` to provide some configuration and environment parameters, The main parameters as follow:
57
+ - `processEnv`: provides the `process.env` during the build.
58
+ - `config`: the configuration of the Modern.js project. Currently, only the output configuration is exposed.
59
+ - `entryName`: the current entry name.
60
+ - `templateParams`: parameters of HTML template (compatible with traditional templates, so it's not recommended for use).
58
61
 
59
- - `processEnv`: Provide build-time env vars.
60
- - `config`: The configuration of the project, only `output` are exposed.
61
- - `entryName`: current entry name.
62
- - `templateParams`: HTML template params(in order to be compatible with traditional templates, it is not recommended to use).
63
-
64
- ### Examples
62
+ ### Example
65
63
 
66
64
  ```tsx
67
65
  import React, { useContext } from 'react';
@@ -102,7 +100,7 @@ export default function Document(): React.ReactElement {
102
100
  }
103
101
  ```
104
102
 
105
- The above JSX component will generate the following HTML template:
103
+ The above JSX components will generate the following HTML template:
106
104
 
107
105
  ```html
108
106
  <!DOCTYPE html>
@@ -149,22 +147,22 @@ The above JSX component will generate the following HTML template:
149
147
 
150
148
  ```
151
149
 
152
- ## Html Synxtax
150
+ ## HTML Syntax
153
151
 
154
- Modern.js also supports HTML syntax. By default, an HTML template is built into the Modern.js application project to generate HTML code.
152
+ Modern.js also supports HTML syntax. By default, Modern.js application projects will include a built-in HTML template for generating HTML code.
155
153
 
156
- Based on HTML syntax templates, Modern.js provides **Custom HTML Fragments** and **Fully Custom HTML Templates** two ways to customize templates.
154
+ Based on the HTML syntax template, Modern.js provides two ways to customize the template: **custom HTML fragments** and **custom the whole HTML**.
157
155
 
158
156
  ### Custom HTML Fragments
159
157
 
160
- In the application root directory, create the `config/html/` directory, which supports the creation of four kinds of HTML fragments.
158
+ Under the application root directory, create the `config/html/` directory, which supports the creation of four types of HTML fragments:
161
159
 
162
160
  - `top.html`
163
161
  - `head.html`
164
162
  - `body.html`
165
163
  - `bottom.html`
166
164
 
167
- **These fragments will be injected into the default HTML template.**
165
+ **These fragments will be injected into the default HTML template according to their positions.**
168
166
 
169
167
  ```html
170
168
  <!DOCTYPE html>
@@ -189,44 +187,44 @@ In the application root directory, create the `config/html/` directory, which su
189
187
  </html>
190
188
  ```
191
189
 
192
- HTML Fragments support the use [Lodash template](https://lodash.com/docs/4.17.15#template).
190
+ HTML fragments support the use of [Lodash template](https://lodash.com/docs/4.17.15#template).
193
191
 
194
- For example, insert a script in `body.html`:
192
+ For example, to insert an external script in `body.html`:
195
193
 
196
194
  ```html title="config/html/body.html"
197
195
  <script src="//example.com/assets/a.js"></script>
198
196
  ```
199
197
 
200
198
  :::info
201
- The implementation of the custom HTML fragment is to merge the fragment with the built-in template of the frame. Since `<title>` already exists in the default template of the frame, the `<title>` in the custom HTML template cannot take effect. Please pass [html.title](/configure/app/html/title) to modify the page title.
199
+ The implementation of custom HTML fragments is to merge the fragments with the built-in template. Since the `<title>` already exists in the default template, the title tag in the custom HTML template will not take effect. Please use [html.title](/configure/app/html/title) to modify the page title.
202
200
 
203
201
  :::
204
202
 
205
- ### Fully Custom HTML Templates
203
+ ### Custom the entire HTML Template
206
204
 
207
- In some cases, HTML snippets do not meet the customization requirements, Modern.js provide a fully customized way.
205
+ In some cases, HTML fragments may be is not better meet the customization requirements. Modern.js provides a fully customized way.
208
206
 
209
- :::caution
210
- It is not recommended to override the default HTML template directly, and some features may be lost. Even if it needs to be replaced, it is recommended to build on the built-in template and modify it as needed.
207
+ :::caution Note
208
+ It is generally not recommended to directly override the default HTML template, as some functional options may be lost. If it is truly necessary to customize the entire HTML template, it is recommended to modify based on the built-in template as needed.
211
209
 
212
210
  :::
213
211
 
214
- In the `config/html/` directory, create a index.html file that will override the default HTML template.
212
+ Under the `config/html/` directory, create an `index.html` file that will replace the default HTML template.
215
213
 
216
214
  :::info
217
- The internal default HTML template can be viewed in `node_modules/.modern-js/${entryName}/index.html`.
215
+ The default HTML template can be viewed in `node_modules/.modern-js/${entryName}/index.html`.
218
216
 
219
217
  :::
220
218
 
221
- ### Template Params
219
+ ### Template Parameters
222
220
 
223
- The parameters used in the template can be defined by the [html.templateParameters](/configure/app/html/template-parameters).
221
+ The parameters used in the template can be defined by the [html.templateParameters](/configure/app/html/template-parameters) configuration.
224
222
 
225
223
  ### Config By Entry
226
224
 
227
- The fragment in the `config/html/` directory are valid for all entries in the application. If you want to customize the HTML by entry, you can create a new directory named with the **entry name** in the `config/html/` directory, and then customize the HTML snippets in this directory.
225
+ The HTML fragments in the `config/html/` directory take effect for all entries in the application. If you want to customize HTML fragments by entry, you can create a directory named after the **entry name** under the `config/html/` directory, and then customize the HTML fragments in this directory.
228
226
 
229
- For example, the following HTML fragment is only valid for `entry1`:
227
+ For example, the following HTML fragments are only effective for the `entry1` entry:
230
228
 
231
229
  ```bash
232
230
  .
@@ -4,11 +4,11 @@ sidebar_position: 6
4
4
  ---
5
5
  # Mock
6
6
 
7
- Modern.js provides the ability to quickly generate Mock data, allowing the front-end to develop independently without being blocked by the back-end interface.
7
+ Modern.js allows you to easily generate mock data so that the front-end can develop independently without depending on the back-end API.
8
8
 
9
- ## Mock File
9
+ ## Enabling Mock
10
10
 
11
- By convention, when there is `index.[jt]s` in the `config/mock/` directory, the Mock Data will be automatically enabled, as follows:
11
+ By convention, when there is an `index.[jt]s` in the `config/mock/` directory, mock data will be automatically enabled:
12
12
 
13
13
  ```bash
14
14
  .
@@ -22,7 +22,7 @@ By convention, when there is `index.[jt]s` in the `config/mock/` directory, the
22
22
 
23
23
  ## Writing Mock Files
24
24
 
25
- the `config/mock/index.ts` file only needs to export an object containing all Mock APIs. The properties of the object are composed of the request configuration `method` and `url`, and the corresponding property values can be `Object`, `Array`, `Function`:
25
+ The `config/mock/index.ts` file only needs to export an object containing all Mock APIs. The properties of the object are composed of the request configuration `method` and `url`, and the corresponding property values can be `Object`, `Array`, or `Function`:
26
26
 
27
27
  ```js
28
28
  export default {
@@ -40,11 +40,11 @@ export default {
40
40
  };
41
41
  ```
42
42
 
43
- when access `http://localhost:8080/api/getInfo`, the api will return json `{ "data": [1, 2, 3, 4] }`.
43
+ When you access `http://localhost:8080/api/getInfo`, the API will return JSON `{ "data": [1, 2, 3, 4] }`.
44
44
 
45
45
  ## Return Random Data
46
46
 
47
- Libraries such as [Mock.js](https://github.com/nuysoft/Mock/wiki/Getting-Started) can be used in `config/mock/index.js` to generate random data, for example:
47
+ Libraries such as [Mock.js](https://github.com/nuysoft/Mock/wiki/Getting-Started) can be used in `config/mock/index.js` to generate random data. For example:
48
48
 
49
49
  ```js
50
50
  const Mock = require('mockjs');
@@ -56,16 +56,16 @@ module.exports = {
56
56
  };
57
57
  ```
58
58
 
59
- :::info Other Mock Lib
59
+ :::info Other Mock Libraries
60
60
 
61
61
  - [Chancejs](https://github.com/chancejs/chancejs)
62
62
  - [Mock](https://github.com/nuysoft/Mock/wiki/Getting-Started)
63
63
 
64
64
  :::
65
65
 
66
- ## Delayed Return
66
+ ## Delayed Response
67
67
 
68
- - It can be achieved using the function of the browser "weak connection simulation".
68
+ - You can do this by using the browser's "weak connection simulation" feature.
69
69
  - Delays can be set via `setTimeout`, for example:
70
70
 
71
71
  ```ts
@@ -92,7 +92,7 @@ export const config = {
92
92
  }
93
93
  ```
94
94
 
95
- Currently only the `enable` configuration is supported, through which developers can control whether to execute Mock.
95
+ Currently only the `enable` configuration is supported, which allows developers to control whether to execute mock.
96
96
 
97
97
  :::note
98
98
  After modifying `config`, there is no need to restart the service, which will take effect immediately.
@@ -1,10 +1,10 @@
1
1
  ---
2
- title: Write Plugins
2
+ title: Develop Plugins
3
3
  sidebar_position: 3
4
4
  ---
5
- # How to Write Plugins
5
+ # How to Develop Plugins
6
6
 
7
- The previous section introduced the Hook models used by Modern.js plugins, while this section describes how to write plugins.
7
+ The previous section introduced the Hook models used by Modern.js plugins, while this section describes how to develop plugins.
8
8
 
9
9
  ## Implementing a Plugin
10
10
 
@@ -115,7 +115,7 @@ Please refer to [Extending Hooks](/guides/topic-detail/framework-plugin/extend)
115
115
 
116
116
  ### Plugin Configuration
117
117
 
118
- **It is recommended to write plugins in the form of functions**, so that plugins can receive configuration options through function parameters:
118
+ **It is recommended to develop plugins in the form of functions**, so that plugins can receive configuration options through function parameters:
119
119
 
120
120
  ```ts
121
121
  import type { CliPlugin } from '@modern-js/core';
@@ -33,7 +33,7 @@ Among them, the CLI plugin is the main running flow control model in Modern.js,
33
33
 
34
34
  ## What Plugins Can Do
35
35
 
36
- All of Modern.js's features are implemented through this set of plugins, which means that all of Modern.js's capabilities are open to developers. Developers can write plugins to extend more functionality and adapt to complex scenarios, including but not limited to:
36
+ All of Modern.js's features are implemented through this set of plugins, which means that all of Modern.js's capabilities are open to developers. Developers can develop plugins to extend more functionality and adapt to complex scenarios, including but not limited to:
37
37
 
38
38
  - Registering commands
39
39
  - Modifying Modern.js configuration and validation schema
@@ -4,21 +4,21 @@ sidebar_position: 2
4
4
 
5
5
  # CLI FAQ
6
6
 
7
- ### Can't pass command line arguments correctly when using pnpm?
7
+ ### Unable to pass command line arguments correctly when using pnpm?
8
8
 
9
- The pnpm v6 and pnpm v7 versions do not use the same posture when executing commands. The following should be noted:
9
+ There are some differences between pnpm v6 and pnpm v7 in how they execute commands, and the following should be noted:
10
10
 
11
11
  pnpm v7:
12
12
 
13
- When using pnpm to invoke a command in `package.json`, if you need to pass arguments to pnpm, you need to put the arguments before the command.
13
+ When using pnpm to call the commands in `package.json`, if you need to pass parameters to pnpm, you need to put the parameters before the command.
14
14
 
15
- For example, execute the prepare command with the pnpm '--filter' parameter:
15
+ For example, using the pnpm `--filter` parameter to run the prepare command:
16
16
 
17
17
  ```bash
18
18
  pnpm run --filter "./packages/**" prepare
19
19
  ```
20
20
 
21
- If you need to pass parameters to a command, you need to put the parameters after the command.
21
+ If you need to pass parameters to the command, you need to put the parameters after the command.
22
22
 
23
23
  For example, in the following `package.json` configuration:
24
24
 
@@ -30,7 +30,7 @@ For example, in the following `package.json` configuration:
30
30
  }
31
31
  ```
32
32
 
33
- The way to carry parameters when executing the command command is:
33
+ The way to pass parameters when running the command is:
34
34
 
35
35
  ```bash
36
36
  pnpm run command --options
@@ -48,16 +48,16 @@ In the following `package.json` configuration:
48
48
  }
49
49
  ```
50
50
 
51
- If you need to execute `modern command --option`,
51
+ If you need to run `modern command --option`:
52
52
 
53
- When using pnpm, you need to execute the `pnpm run command -- --option`.
53
+ When using pnpm, you need to run `pnpm run command -- --option`.
54
54
 
55
- This is because pnpm does not handle command parameters the same as Yarn, but is similar to npm: when not adding a `--` character string, the parameters of pnpm are passed; when using a `--` character string, the parameters of the execution script are passed.
55
+ This is because pnpm's handling of command parameters is different from that of Yarn, but similar to that of npm: when the `--` string is not added, the parameters passed are for pnpm; when the `--` string is used, the parameters passed are for running the script.
56
56
 
57
- In the above example the parameter `--option` is passed to `modern command`. If `pnpm run command --option` is executed, the parameter `--option` will be passed to pnpm.
57
+ In the above example, the `--option` parameter is passed to `modern command`. If you run `pnpm run command --option`, the `--option` parameter will be passed to pnpm.
58
58
 
59
- Summary:
59
+ In summary:
60
60
 
61
- **When using pnpm v7, if you pass arguments to pnpm, you need to put the arguments before the command**
61
+ **When using pnpm v7, if passing parameters to pnpm, the parameters need to be placed before the command.**
62
62
 
63
- **When using pnpm v6, if the parameter passed to pnpm, you do not need to add `--`; if the parameter passed is for script use, you need to add `--` character string**.
63
+ **When using pnpm v6, if the parameters are passed to pnpm, `--` is not required; if the parameters are passed to the script, the `--` string needs to be added.**
@@ -6,15 +6,15 @@ sidebar_position: 1
6
6
 
7
7
  ### How to check the actual installed version of a dependency in the project?
8
8
 
9
- You can use the `ls` command that provided by the package manager to view the dependencies version.
9
+ You can use the `ls` command provided by the package manager to view the version of the dependency in the project.
10
10
 
11
- The following are some basic examples, please refer to the documentation of each package manager for detailed usage.
11
+ Here are some basic examples. For detailed usage, please refer to the documentation of each package manager.
12
12
 
13
13
  **npm / yarn**
14
14
 
15
- For projects using npm or yarn, the `npm ls` command can be used.
15
+ For projects using npm or yarn, you can use the `npm ls` command.
16
16
 
17
- For example, execute `npm ls @modern-js/core`, you can see the following results:
17
+ For example, running `npm ls @modern-js/core` will show the following result:
18
18
 
19
19
  ```
20
20
  project
@@ -24,9 +24,9 @@ project
24
24
 
25
25
  **pnpm**
26
26
 
27
- For projects using pnpm, you can use `pnpm ls` command.
27
+ For projects using pnpm, you can use the `pnpm ls` command.
28
28
 
29
- For example, execute `pnpm ls @modern-js/core --depth Infinity`, you can see the following results:
29
+ For example, running `pnpm ls @modern-js/core --depth Infinity` will show the following result:
30
30
 
31
31
  ```
32
32
  devDependencies:
@@ -36,9 +36,9 @@ devDependencies:
36
36
 
37
37
  ---
38
38
 
39
- ### The engine "node" is incompatible when installing dependencies?
39
+ ### Getting "The engine "node" is incompatible" error during dependency installation?
40
40
 
41
- If the following error message appears when installing dependencies, it means that the version of Node.js used in the current environment is too low, and Node.js needs to be upgraded to a higher version.
41
+ If you encounter the following error message during dependency installation, it means that the current environment is using a Node.js version that is too low, and you need to upgrade Node.js to a higher version.
42
42
 
43
43
  ```bash
44
44
  The engine "node" is incompatible with this module.
@@ -46,11 +46,11 @@ The engine "node" is incompatible with this module.
46
46
  Expected version ">=14.17.6". Got "12.20.1"
47
47
  ```
48
48
 
49
- When using Modern.js, it is recommended to use [Node.js 14.x](https://nodejs.org/download/release/latest-v14.x/) or [Node.js 16.x](https://nodejs.org/download/release/latest-v16.x/).
49
+ When using Modern.js, it is recommended to use the latest version of [Node.js 14.x](https://nodejs.org/download/release/latest-v14.x/) or [Node.js 16.x](https://nodejs.org/download/release/latest-v16.x/).
50
50
 
51
- If the Node.js version in the current environment is lower than the required version, you can use [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz /fnm) and other tools for version switching.
51
+ If the Node.js version of the current environment is lower than the above requirement, you can use tools such as [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz/fnm) to switch versions.
52
52
 
53
- Here's an example using nvm:
53
+ Here is an example of using nvm:
54
54
 
55
55
  ```
56
56
  # Install Node.js v14
@@ -63,13 +63,13 @@ nvm use 14
63
63
  nvm default 14
64
64
  ```
65
65
 
66
- It is recommended to use [fnm](https://github.com/Schniz/fnm) in the local development environment. Its usage is similar to nvm, but it has better performance than nvm.
66
+ For local development environments, it is recommended to use [fnm](https://github.com/Schniz/fnm), which has better performance than nvm and has similar usage.
67
67
 
68
68
  ---
69
69
 
70
- ### ReactNode type error after upgrading dependencies?
70
+ ### Getting a ReactNode type error after upgrading dependencies?
71
71
 
72
- If the following types of errors are reported after upgrading the project's dependencies, it means that the wrong `@types/react` version is installed in the project.
72
+ After upgrading the dependencies of the project, if the following type error occurs, it means that the wrong version of `@types/react` is installed in the project.
73
73
 
74
74
  ```bash
75
75
  The types returned by 'render()' are incompatible between these types.
@@ -77,9 +77,9 @@ Type 'React.ReactNode' is not assignable to type 'import("/node_modules/@types/r
77
77
  Type '{}' is not assignable to type 'ReactNode'.
78
78
  ```
79
79
 
80
- The reason for this problem is that the ReactNode type definitions in React 18 and React 16/17 are different. If there are multiple different `@types/react` versions in the project, there will be a ReactNode type conflict, resulting in the above error.
80
+ The reason for this problem is that the ReactNode type definition in React 18 is different from that in React 16/17. If there are multiple different versions of `@types/react` in the project, a ReactNode type conflict will occur, resulting in the above error.
81
81
 
82
- The solution is to lock `@types/react` and `@types/react-dom` in the project to a unified version, such as `v17`.
82
+ The solution is to lock the `@types/react` and `@types/react-dom` in the project to a unified version, such as `v17`.
83
83
 
84
84
  ```json
85
85
  {
@@ -88,23 +88,23 @@ The solution is to lock `@types/react` and `@types/react-dom` in the project to
88
88
  }
89
89
  ```
90
90
 
91
- For the method of locking the dependency version, please refer to [Lock nested dependency](/guides/get-started/upgrade.html#lock-nested-dependency).
91
+ For methods of locking dependency versions, please refer to [Lock nested dependency](/guides/get-started/upgrade.html#lock-nested-dependency).
92
92
 
93
93
  ---
94
94
 
95
- ### After pnpm install, there are some peer dependencies warnings in the console?
95
+ ### Getting peer dependencies warnings in the console after running `pnpm install`?
96
96
 
97
- The reason for this warning is that the version range of peer dependencies declared by some third-party npm packages does not match the version range installed in Modern.js.
97
+ The reason for this warning is that the version range of peer dependencies declared by some third-party npm packages is inconsistent with the version range installed in Modern.js.
98
98
 
99
- In most cases, you can ignore the peer dependency warnings because it will not affect the use of Modern.js.
99
+ In most cases, peer dependencies warnings will not affect the project operation and do not need to be processed separately. Please ignore the relevant warnings.
100
100
 
101
101
  ---
102
102
 
103
- ### What is the minimum React version supported by the Modern.js framework?
103
+ ### What is the minimum supported version of React for the Modern.js framework?
104
104
 
105
- The recommended React version for **Modern.js framework is >= 18.0.0**, and different features have different React version requirements.
105
+ **The recommended React version for the Modern.js framework is >= 18.0.0**, and different functions have different requirements for the React version.
106
106
 
107
- - If you are using React 17, some framework features, such as Steaming SSR, will not be available as they rely on new features provided by React 18.
108
- - If you're still using React 16, you won't be able to use Modern.js's runtime or server-side featurs. You can consider using Modern.js's build mode, that is, only use Modern.js as a builder. In this case, you can still use React 16.
107
+ - If you are using React 17, some framework functions will not be available, such as Steaming SSR, because it relies on new features provided by React 18.
108
+ - If you are still using React 16, you will not be able to use Modern.js's runtime or server-side capabilities. You can consider using the build mode of Modern.js, that is, only using Modern.js's build capabilities. In this case, React 16 can still be used.
109
109
 
110
- In a future major release of Modern.js, we will remove support for React 16 and React 17. Please upgrade to React 18+ as soon as possible.
110
+ In future major versions of Modern.js, we will gradually remove support for React 16 and React 17. Therefore, please upgrade to React 18 or higher as soon as possible.