@modern-js/main-doc 2.22.1 → 2.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/docs/en/apis/app/commands.mdx +5 -5
  3. package/docs/en/apis/app/runtime/core/bootstrap.mdx +5 -5
  4. package/docs/en/apis/app/runtime/core/use-loader.mdx +2 -2
  5. package/docs/en/apis/app/runtime/core/use-module-apps.mdx +2 -2
  6. package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +1 -1
  7. package/docs/en/apis/app/runtime/testing/render.mdx +1 -1
  8. package/docs/en/components/bff-proxy-path-rewrite.mdx +16 -0
  9. package/docs/en/components/bff-proxy-principle.mdx +1 -0
  10. package/docs/en/components/enable-bff-caution.mdx +3 -0
  11. package/docs/en/components/global-proxy-config.mdx +33 -13
  12. package/docs/en/configure/app/bff/enable-handle-web.mdx +5 -5
  13. package/docs/en/configure/app/bff/prefix.mdx +6 -6
  14. package/docs/en/configure/app/bff/proxy.mdx +19 -30
  15. package/docs/en/configure/app/builder-plugins.mdx +1 -1
  16. package/docs/en/configure/app/plugins.mdx +19 -19
  17. package/docs/en/configure/app/runtime/intro.mdx +28 -4
  18. package/docs/en/configure/app/runtime/master-app.mdx +1 -1
  19. package/docs/en/configure/app/runtime/router.mdx +2 -2
  20. package/docs/en/configure/app/server/base-url.mdx +4 -4
  21. package/docs/en/configure/app/server/enable-framework-ext.mdx +4 -4
  22. package/docs/en/configure/app/server/port.mdx +6 -6
  23. package/docs/en/configure/app/server/public-routes.mdx +5 -5
  24. package/docs/en/configure/app/server/routes.mdx +13 -13
  25. package/docs/en/configure/app/server/ssr-by-entries.mdx +4 -4
  26. package/docs/en/configure/app/server/ssr.mdx +5 -5
  27. package/docs/en/configure/app/usage.mdx +5 -5
  28. package/docs/en/guides/advanced-features/code-split.mdx +15 -14
  29. package/docs/en/guides/advanced-features/rspack-start.mdx +0 -1
  30. package/docs/en/guides/advanced-features/ssr.mdx +2 -2
  31. package/docs/en/guides/advanced-features/testing.mdx +8 -7
  32. package/docs/en/guides/advanced-features/web-server.mdx +16 -16
  33. package/docs/en/guides/basic-features/alias.mdx +11 -9
  34. package/docs/en/guides/basic-features/env-vars.mdx +14 -14
  35. package/docs/en/guides/basic-features/html.mdx +41 -43
  36. package/docs/en/guides/basic-features/mock.mdx +10 -10
  37. package/docs/en/guides/topic-detail/framework-plugin/implement.mdx +4 -4
  38. package/docs/en/guides/topic-detail/framework-plugin/introduction.mdx +1 -1
  39. package/docs/en/guides/troubleshooting/cli.mdx +13 -13
  40. package/docs/en/guides/troubleshooting/dependencies.mdx +25 -25
  41. package/docs/en/tutorials/first-app/c03-css.mdx +1 -1
  42. package/docs/zh/apis/app/commands.mdx +4 -4
  43. package/docs/zh/apis/app/runtime/testing/render.mdx +1 -1
  44. package/docs/zh/components/bff-proxy-path-rewrite.mdx +16 -0
  45. package/docs/zh/components/bff-proxy-principle.mdx +1 -0
  46. package/docs/zh/components/enable-bff-caution.mdx +4 -0
  47. package/docs/zh/components/global-proxy-config.mdx +35 -11
  48. package/docs/zh/configure/app/bff/enable-handle-web.mdx +3 -3
  49. package/docs/zh/configure/app/bff/prefix.mdx +2 -3
  50. package/docs/zh/configure/app/bff/proxy.mdx +11 -21
  51. package/docs/zh/configure/app/runtime/intro.mdx +1 -1
  52. package/docs/zh/configure/app/server/base-url.mdx +1 -1
  53. package/docs/zh/configure/app/server/public-routes.mdx +2 -2
  54. package/docs/zh/configure/app/server/routes.mdx +2 -2
  55. package/docs/zh/configure/app/server/ssr-by-entries.mdx +3 -3
  56. package/docs/zh/configure/app/server/ssr.mdx +1 -1
  57. package/docs/zh/configure/app/usage.mdx +9 -9
  58. package/docs/zh/guides/advanced-features/code-split.mdx +13 -12
  59. package/docs/zh/guides/advanced-features/rspack-start.mdx +0 -1
  60. package/docs/zh/guides/advanced-features/ssr.mdx +2 -2
  61. package/docs/zh/guides/advanced-features/testing.mdx +4 -4
  62. package/docs/zh/guides/basic-features/alias.mdx +5 -3
  63. package/docs/zh/guides/basic-features/html.mdx +9 -9
  64. package/docs/zh/guides/basic-features/mock.mdx +2 -2
  65. package/docs/zh/guides/topic-detail/_category_.json +1 -1
  66. package/docs/zh/guides/troubleshooting/cli.mdx +1 -1
  67. package/docs/zh/guides/troubleshooting/dependencies.mdx +1 -1
  68. package/package.json +7 -6
@@ -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.
@@ -5,7 +5,7 @@ title: Add Style
5
5
 
6
6
  import { Tabs, Tab as TabItem } from "@theme";
7
7
 
8
- In the previous chapter, we learned how to use components from the three-way library.
8
+ In the previous chapter, we learned how to use components from the third-party library.
9
9
 
10
10
  In this chapter, we will learn how to implement UI components.
11
11
 
@@ -106,12 +106,13 @@ File sizes after production build:
106
106
 
107
107
  `modern new` 命令用于在已有项目中添加项目元素。
108
108
 
109
- 比如添加应用入口、启用启用一些可选功能如 Tailwind CSS、微前端开发模式等。
109
+ 比如添加应用入口、启用一些可选功能如 Tailwind CSS、微前端开发模式等。
110
110
 
111
111
  ```bash
112
112
  Usage: modern new [options]
113
113
 
114
114
  Options:
115
+ --lang <lang> 设置 new 命令执行语言(zh 或者 en)
115
116
  -d, --debug 开启 Debug 模式,打印调试日志信息 (default: false)
116
117
  -c, --config <config> 生成器运行默认配置(JSON 字符串)
117
118
  --dist-tag <tag> 生成器使用特殊的 npm Tag 版本
@@ -162,7 +163,6 @@ Usage: modern serve [options]
162
163
  Options:
163
164
  -c --config <config> 指定配置文件路径,可以为相对路径或绝对路径
164
165
  -h, --help 显示命令帮助
165
- --web-only 仅启动 Web 服务
166
166
  --api-only 仅启动 API 接口服务
167
167
  ```
168
168
 
@@ -180,7 +180,7 @@ export default defineConfig({
180
180
 
181
181
  在项目根目录下执行命令 `npx modern upgrade`,会默认将当前执行命令项目的 `package.json` 中的 Modern.js 相关依赖更新至最新版本。
182
182
 
183
- ```
183
+ ```bash
184
184
  Usage: modern upgrade [options]
185
185
 
186
186
  Options:
@@ -194,7 +194,7 @@ Options:
194
194
 
195
195
  `modern inspect` 命令用于查看项目的 [Modern.js Builder 配置](https://modernjs.dev/builder/guide/basic/builder-config.html) 以及 webpack 配置。
196
196
 
197
- ```
197
+ ```bash
198
198
  Usage: modern inspect [options]
199
199
 
200
200
  Options:
@@ -41,7 +41,7 @@ function render(ui: React.ReactElement<any>, options: Options): RenderResult;
41
41
  - `options`:render 可选配置。
42
42
  - `container`:表示组件所要挂载到的 DOM 节点,默认是会创建一个 `div` 元素,并自动添加到 `document.body` 上。这个 `div` 元素就是组件要挂载的节点。默认值是 `document.body.append(document.createElement('div'))`。
43
43
  - `baseElement`:用于指定 `queries` 中使用到的 `basename`。如果指定了 `container`, 则默认值为 `container` 的值,否则就是 `document.body`。
44
- - `hydrate`:如果设置为 `true`,则会使用 [ReactDOM.hydrate](https://reactjs.org/docs/react-dom.html#hydrate) 渲染组件。默认值为 `false`。
44
+ - `hydrate`:如果设置为 `true`,则会使用 [ReactDOM.hydrate](https://zh-hans.react.dev/reference/react-dom/hydrate) 渲染组件。默认值为 `false`。
45
45
  - `wrapper`:是一个 react 组件,可用于自定义渲染逻辑。
46
46
  - `queries`:自定义一些自己的 `queries`。
47
47
 
@@ -0,0 +1,16 @@
1
+ 这里还可以进行路径重写,如将发送到 `localhost:8080/api/topics` 的请求代理到 `https://cnodejs.org/api/v1/topics`。
2
+
3
+ ```ts title="modern.server-runtime.config.ts"
4
+ import { defineConfig } from '@modern-js/app-tools/server';
5
+ export default defineConfig({
6
+ bff: {
7
+ proxy: {
8
+ '/api': {
9
+ target: 'https://cnodejs.org',
10
+ pathRewrite: { '/api/topics': '/api/v1/topics' },
11
+ changeOrigin: true,
12
+ },
13
+ },
14
+ },
15
+ });
16
+ ```
@@ -0,0 +1 @@
1
+ BFF Proxy 使用了强大的 [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware),如果需要更多高级的用法, 可以查看它的[文档](https://github.com/chimurai/http-proxy-middleware#options)。
@@ -0,0 +1,4 @@
1
+ :::caution 注意
2
+ 请先在当前应用项目根目录使用【[new](/apis/app/commands#modern-new)】 启用 BFF 功能。
3
+
4
+ :::
@@ -1,14 +1,37 @@
1
1
  - **类型:** `string | Object`
2
2
  - **默认值:** `null`
3
3
 
4
- 配置该选项后,开发环境时会启动全局代理,类似 [Fiddler](https://www.telerik.com/fiddler), [Charles](https://www.charlesproxy.com/) web 代理调试工具,可以用来查看、修改 HTTP/HTTPS 请求、响应、也可以用作代理服务器。
4
+ 该选项用于在开发环境下启用基于 [whistle](https://wproxy.org/whistle/) 的全局代理,可以用来查看、修改 HTTP/HTTPS 请求、响应、也可以用作代理服务器。
5
5
 
6
- :::tip 提示
7
- 使用该选项需要提前安装 `@modern-js/plugin-proxy`。
6
+ ### 注册插件
8
7
 
9
- :::
8
+ 使用该选项前,你需要提前安装和注册 `@modern-js/plugin-proxy` 插件:
9
+
10
+ ```bash
11
+ # npm
12
+ npm add @modern-js/plugin-proxy -D
13
+
14
+ # yarn
15
+ yarn add @modern-js/plugin-proxy -D
16
+
17
+ # pnpm
18
+ pnpm add @modern-js/plugin-proxy -D
19
+ ```
20
+
21
+ 安装完成后,在 `modern.config.ts` 文件中注册插件:
22
+
23
+ ```ts title="modern.config.ts"
24
+ import appTools, { defineConfig } from '@modern-js/app-tools';
25
+ import proxyPlugin from '@modern-js/plugin-proxy';
26
+
27
+ export default defineConfig({
28
+ plugins: [appTools(), proxyPlugin()],
29
+ });
30
+ ```
10
31
 
11
- 值为 `Object` 时,对象的 `key` 对应匹配的 `pattern`,对象的 `value` 对应匹配的 `target`。
32
+ ### Object 类型
33
+
34
+ `dev.proxy` 的值为 `Object` 时,对象的 `key` 对应匹配的 `pattern`,对象的 `value` 对应匹配的 `target`。
12
35
 
13
36
  例如:
14
37
 
@@ -24,7 +47,11 @@ export default defineConfig({
24
47
  });
25
48
  ```
26
49
 
27
- 值为 `string` 时, 可以用来指定单独的代理文件,例如:
50
+ 请参考 [whistle - 匹配模式](https://wproxy.org/whistle/pattern.html) 来了解详细用法。
51
+
52
+ ### String 类型
53
+
54
+ `dev.proxy` 的值为 `string` 时, 可以用来指定单独的代理文件,例如:
28
55
 
29
56
  ```ts title="modern.config.ts"
30
57
  export default defineConfig({
@@ -43,10 +70,7 @@ module.exports = {
43
70
  };
44
71
  ```
45
72
 
46
- :::info
47
- Modern.js 全局代理实现底层基于 [whistle](https://wproxy.org/whistle/), 更多匹配模式请参考: [匹配模式](https://wproxy.org/whistle/pattern.html)
48
-
49
- :::
73
+ ### 启动代理
50
74
 
51
75
  执行 `dev`, 提示如下时,即代理服务器启动成功:
52
76
 
@@ -64,7 +88,7 @@ Modern.js 全局代理实现底层基于 [whistle](https://wproxy.org/whistle/),
64
88
 
65
89
  ![proxy ui 界面](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/docs/dev-proxy.png)
66
90
 
67
- :::caution 注意
91
+ :::info
68
92
  https 代理自动安装证书需要获取 root 权限, 请根据提示输入密码即可。**密码仅在信任证书时使用,不会泄漏或者用于其他环节**。
69
93
 
70
94
  :::