@modern-js/main-doc 2.22.1 → 2.23.0
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.
- package/CHANGELOG.md +38 -0
- package/docs/en/apis/app/commands.mdx +5 -5
- package/docs/en/apis/app/runtime/core/bootstrap.mdx +5 -5
- package/docs/en/apis/app/runtime/core/use-loader.mdx +2 -2
- package/docs/en/apis/app/runtime/core/use-module-apps.mdx +2 -2
- package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +1 -1
- package/docs/en/apis/app/runtime/testing/render.mdx +1 -1
- package/docs/en/components/bff-proxy-path-rewrite.mdx +16 -0
- package/docs/en/components/bff-proxy-principle.mdx +1 -0
- package/docs/en/components/enable-bff-caution.mdx +3 -0
- package/docs/en/components/global-proxy-config.mdx +33 -13
- package/docs/en/configure/app/bff/enable-handle-web.mdx +5 -5
- package/docs/en/configure/app/bff/prefix.mdx +6 -6
- package/docs/en/configure/app/bff/proxy.mdx +19 -30
- package/docs/en/configure/app/builder-plugins.mdx +1 -1
- package/docs/en/configure/app/plugins.mdx +19 -19
- package/docs/en/configure/app/runtime/intro.mdx +28 -4
- package/docs/en/configure/app/runtime/master-app.mdx +1 -1
- package/docs/en/configure/app/runtime/router.mdx +2 -2
- package/docs/en/configure/app/server/base-url.mdx +4 -4
- package/docs/en/configure/app/server/enable-framework-ext.mdx +4 -4
- package/docs/en/configure/app/server/port.mdx +6 -6
- package/docs/en/configure/app/server/public-routes.mdx +5 -5
- package/docs/en/configure/app/server/routes.mdx +13 -13
- package/docs/en/configure/app/server/ssr-by-entries.mdx +4 -4
- package/docs/en/configure/app/server/ssr.mdx +5 -5
- package/docs/en/configure/app/usage.mdx +5 -5
- package/docs/en/guides/advanced-features/code-split.mdx +15 -14
- package/docs/en/guides/advanced-features/rspack-start.mdx +0 -1
- package/docs/en/guides/advanced-features/ssr.mdx +2 -2
- package/docs/en/guides/advanced-features/testing.mdx +8 -7
- package/docs/en/guides/advanced-features/web-server.mdx +16 -16
- package/docs/en/guides/basic-features/alias.mdx +11 -9
- package/docs/en/guides/basic-features/env-vars.mdx +14 -14
- package/docs/en/guides/basic-features/html.mdx +41 -43
- package/docs/en/guides/basic-features/mock.mdx +10 -10
- package/docs/en/guides/topic-detail/framework-plugin/implement.mdx +4 -4
- package/docs/en/guides/topic-detail/framework-plugin/introduction.mdx +1 -1
- package/docs/en/guides/troubleshooting/cli.mdx +13 -13
- package/docs/en/guides/troubleshooting/dependencies.mdx +25 -25
- package/docs/en/tutorials/first-app/c03-css.mdx +1 -1
- package/docs/zh/apis/app/commands.mdx +4 -4
- package/docs/zh/apis/app/runtime/testing/render.mdx +1 -1
- package/docs/zh/components/bff-proxy-path-rewrite.mdx +16 -0
- package/docs/zh/components/bff-proxy-principle.mdx +1 -0
- package/docs/zh/components/enable-bff-caution.mdx +4 -0
- package/docs/zh/components/global-proxy-config.mdx +35 -11
- package/docs/zh/configure/app/bff/enable-handle-web.mdx +3 -3
- package/docs/zh/configure/app/bff/prefix.mdx +2 -3
- package/docs/zh/configure/app/bff/proxy.mdx +11 -21
- package/docs/zh/configure/app/runtime/intro.mdx +1 -1
- package/docs/zh/configure/app/server/base-url.mdx +1 -1
- package/docs/zh/configure/app/server/public-routes.mdx +2 -2
- package/docs/zh/configure/app/server/routes.mdx +2 -2
- package/docs/zh/configure/app/server/ssr-by-entries.mdx +3 -3
- package/docs/zh/configure/app/server/ssr.mdx +1 -1
- package/docs/zh/configure/app/usage.mdx +9 -9
- package/docs/zh/guides/advanced-features/code-split.mdx +13 -12
- package/docs/zh/guides/advanced-features/rspack-start.mdx +0 -1
- package/docs/zh/guides/advanced-features/ssr.mdx +2 -2
- package/docs/zh/guides/advanced-features/testing.mdx +4 -4
- package/docs/zh/guides/basic-features/alias.mdx +5 -3
- package/docs/zh/guides/basic-features/html.mdx +9 -9
- package/docs/zh/guides/basic-features/mock.mdx +2 -2
- package/docs/zh/guides/topic-detail/_category_.json +1 -1
- package/docs/zh/guides/troubleshooting/cli.mdx +1 -1
- package/docs/zh/guides/troubleshooting/dependencies.mdx +1 -1
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,43 @@
|
|
1
1
|
# @modern-js/main-doc
|
2
2
|
|
3
|
+
## 2.23.0
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 8a93276: docs(main): update basic features alias doc
|
8
|
+
|
9
|
+
docs(main): 更新基础功能 -- 别名文档
|
10
|
+
|
11
|
+
- 7e6fb5f: chore: publishConfig add provenance config
|
12
|
+
|
13
|
+
chore: publishConfig 增加 provenance 配置
|
14
|
+
|
15
|
+
- 372b950: docs(main): update plugin config doc
|
16
|
+
|
17
|
+
docs(main): 更新插件配置文档
|
18
|
+
|
19
|
+
- f28b485: docs(main): update faq doc
|
20
|
+
|
21
|
+
docs(main): 更新 faq 文档
|
22
|
+
|
23
|
+
- f264c4a: docs(main): update html template doc
|
24
|
+
|
25
|
+
docs(main): 更新 HTML 模板文档
|
26
|
+
|
27
|
+
- 5cba7c4: docs(main): update bff config doc
|
28
|
+
|
29
|
+
docs(main): 更新 BFF 配置文档
|
30
|
+
|
31
|
+
- ef865f2: docs(main): update config server doc
|
32
|
+
|
33
|
+
docs(main): 更新 server 配置文档
|
34
|
+
|
35
|
+
- 8bb0e14: chore: review code split docs
|
36
|
+
chore: 审查代码分割文档
|
37
|
+
- Updated dependencies [7e6fb5f]
|
38
|
+
- Updated dependencies [692cc0e]
|
39
|
+
- @modern-js/builder-doc@2.23.0
|
40
|
+
|
3
41
|
## 2.22.1
|
4
42
|
|
5
43
|
### Patch Changes
|
@@ -112,6 +112,7 @@ For example, add application entry, enable some optional features such as Tailwi
|
|
112
112
|
Usage: modern new [options]
|
113
113
|
|
114
114
|
Options:
|
115
|
+
--lang <lang> set the language (zh or en) for the new command.
|
115
116
|
-d, --debug using debug mode to log something (default: false)
|
116
117
|
-c, --config <config> set default generator config(json string)
|
117
118
|
--dist-tag <tag> use specified tag version for its generator
|
@@ -136,7 +137,7 @@ In the project, execute the `new` command to enable features as follows:
|
|
136
137
|
|
137
138
|
```bash
|
138
139
|
$ npx modern new
|
139
|
-
? Please select the operation you want: Enable
|
140
|
+
? Please select the operation you want: Enable Features
|
140
141
|
? Please select the feature name: (Use arrow keys)
|
141
142
|
❯ Enable Tailwind CSS
|
142
143
|
Enable BFF
|
@@ -162,11 +163,10 @@ Usage: modern serve [options]
|
|
162
163
|
Options:
|
163
164
|
-c --config <config> configuration file path, which can be a relative path or an absolute path
|
164
165
|
-h, --help show command help
|
165
|
-
--web-only only run web service
|
166
166
|
--api-only only run API service
|
167
167
|
```
|
168
168
|
|
169
|
-
By default, the project will run in `localhost:8080`, you can modify the
|
169
|
+
By default, the project will run in `localhost:8080`, you can modify the server port number with `server.port`:
|
170
170
|
|
171
171
|
```js
|
172
172
|
export default defineConfig({
|
@@ -180,7 +180,7 @@ export default defineConfig({
|
|
180
180
|
|
181
181
|
Execute the command `npx modern upgrade` in the project, by default, dependencies in the `package.json` are updated to the latest version.
|
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
|
The `modern inspect` command is used to view the [Modern.js Builder config](https://modernjs.dev/builder/en/guide/basic/builder-config.html) and webpack config of the project.
|
196
196
|
|
197
|
-
```
|
197
|
+
```bash
|
198
198
|
Usage: modern inspect [options]
|
199
199
|
|
200
200
|
Options:
|
@@ -3,7 +3,7 @@ title: bootstrap
|
|
3
3
|
---
|
4
4
|
# bootstrap
|
5
5
|
|
6
|
-
Used to start and mount App, usually
|
6
|
+
Used to start and mount App, usually not manually called. This API is only required when using [Custom Bootstrap](/guides/concept/entries#custom-bootstrap).
|
7
7
|
|
8
8
|
## Usage
|
9
9
|
|
@@ -32,10 +32,10 @@ type BootStrap<T = unknown> = (
|
|
32
32
|
|
33
33
|
### Input
|
34
34
|
|
35
|
-
- `AppComponent`:
|
36
|
-
- `rootId`: DOM root element id to mount,
|
37
|
-
- `root`:
|
38
|
-
- `ReactDOM`: ReactDOM object
|
35
|
+
- `AppComponent`: The ReactElement instance created by [`createApp`](./create-app).
|
36
|
+
- `rootId`: DOM root element id to mount, such as `"root"`.
|
37
|
+
- `root`: The return value of ReactDOM.createRoot, used for scenarios where the root needs to be destroyed outside of the bootstrap function.
|
38
|
+
- `ReactDOM`: The ReactDOM object, used to differentiate between React 18 and React 17 APIs.
|
39
39
|
|
40
40
|
## Example
|
41
41
|
|
@@ -3,10 +3,10 @@ title: useLoader
|
|
3
3
|
---
|
4
4
|
# useLoader
|
5
5
|
|
6
|
-
Isomorphic API, usually used to make asynchronous requests.
|
6
|
+
`useLoader` is an Isomorphic API, usually used to make asynchronous requests. During Server-Side Rendering (SSR), the server uses `useLoader` to prefetch the data, which is then reused on the client side.
|
7
7
|
|
8
8
|
:::tip
|
9
|
-
|
9
|
+
The `useLoader` API is currently not supported when using Rspack as the bundler.
|
10
10
|
:::
|
11
11
|
|
12
12
|
## Usage
|
@@ -3,7 +3,7 @@ title: useModuleApps
|
|
3
3
|
---
|
4
4
|
# useModuleApps
|
5
5
|
|
6
|
-
Returns the React components of all micro-front-end sub-applications for
|
6
|
+
Returns the React components of all micro-front-end sub-applications, allowing for flexible control over routing.
|
7
7
|
|
8
8
|
## Usage
|
9
9
|
|
@@ -107,7 +107,7 @@ After starting the application in this way, accessing the `/dashboard` route wil
|
|
107
107
|
|
108
108
|
## Load Animation
|
109
109
|
|
110
|
-
|
110
|
+
You can customize the transition animation of the component loading process as follows.
|
111
111
|
|
112
112
|
```tsx title=App.tsx
|
113
113
|
function App() {
|
@@ -41,7 +41,7 @@ function render(ui: React.ReactElement<any>, options: Options): RenderResult;
|
|
41
41
|
- `options`: render options.
|
42
42
|
- `container`: the dom which component mounted. by default create a `div` element, and auto append to `document.body`. the default value is `document.body.append(document.createElement('div'))`.
|
43
43
|
- `baseElement`: Used to specify the `basename` used in `queries`. If `container` is specified, the default value is the value of `container`, otherwise it is `document.body`.
|
44
|
-
- `hydrate`: If set to `true`, the [ReactDOM.hydrate](https://
|
44
|
+
- `hydrate`: If set to `true`, the [ReactDOM.hydrate](https://react.dev/reference/react-dom/hydrate) rendering component is used. The default value is `false`.
|
45
45
|
- `wrapper`: a react component that can be used to customize rendering logic.
|
46
46
|
- `queries`: customize some own `queries`.
|
47
47
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Path rewriting can also be performed here, such as proxying the request sent to `localhost:8080/api/topics` to `https://cnodejs.org/api/v1/topics`.
|
2
|
+
|
3
|
+
```js title="modern.server-runtime.config.js"
|
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 uses the powerful [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware). For more advanced usage, please refer to its [documentation](https://github.com/chimurai/http-proxy-middleware#options).
|
@@ -1,16 +1,37 @@
|
|
1
1
|
- **Type:** `string | Object`
|
2
2
|
- **Default:** `null`
|
3
3
|
|
4
|
-
|
4
|
+
This option is used to configure a global proxy based on [whistle](https://wproxy.org/whistle/) in the development environment, which can be used to view and modify HTTP/HTTPS requests, responses, and can also be used as a proxy server.
|
5
5
|
|
6
|
-
|
7
|
-
Using this option requires advance installation `@modern-js/plugin-proxy`.
|
6
|
+
### Register Plugin
|
8
7
|
|
9
|
-
|
8
|
+
Before using this option, you need to install and register the `@modern-js/plugin-proxy` plugin:
|
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
|
+
After the installation, please register the plugin in the `modern.config.ts` file:
|
22
|
+
|
23
|
+
```ts title="modern.config.ts"
|
24
|
+
import appTools, { defineConfig } from '@modern-js/app-tools';
|
25
|
+
import proxyPlugin from '@modern-js/plugin-proxy';
|
10
26
|
|
11
|
-
|
27
|
+
export default defineConfig({
|
28
|
+
plugins: [appTools(), proxyPlugin()],
|
29
|
+
});
|
30
|
+
```
|
12
31
|
|
13
|
-
|
32
|
+
### Object Type
|
33
|
+
|
34
|
+
When the value of `dev.proxy` is object type, the `key` of the object corresponds to the matching `pattern`, and the `value` of the object corresponds to the matching `target`.
|
14
35
|
|
15
36
|
Example:
|
16
37
|
|
@@ -26,9 +47,11 @@ export default defineConfig({
|
|
26
47
|
});
|
27
48
|
```
|
28
49
|
|
29
|
-
|
50
|
+
Please refer to [whistle - Matching Patterns](https://wproxy.org/whistle/pattern.html) for detailed usage.
|
51
|
+
|
52
|
+
### String Type
|
30
53
|
|
31
|
-
When the value is
|
54
|
+
When the value of `dev.proxy` is string type, it can be used to specify a separate proxy file, for example:
|
32
55
|
|
33
56
|
```ts title="modern.config.ts"
|
34
57
|
export default defineConfig({
|
@@ -47,10 +70,7 @@ module.exports = {
|
|
47
70
|
};
|
48
71
|
```
|
49
72
|
|
50
|
-
|
51
|
-
Modern.js global proxy implementation is based on [whistle](https://wproxy.org/whistle/), for more matching patterns, please refer to: [Matching Patterns](https://wproxy.org/whistle/pattern.html)
|
52
|
-
|
53
|
-
:::
|
73
|
+
### Start Proxy
|
54
74
|
|
55
75
|
Execute `dev`, when the prompt is as follows, the proxy server starts successfully:
|
56
76
|
|
@@ -68,7 +88,7 @@ Access the `localhost:8899` to view the Network and configure proxy rules on the
|
|
68
88
|
|
69
89
|

|
70
90
|
|
71
|
-
:::
|
91
|
+
:::info
|
72
92
|
The https agent automatically installs the certificate to obtain root privileges. Please enter the password as prompted. ** The password is only used when the certificate is trusted and will not be leaked or used for other links **.
|
73
93
|
|
74
94
|
:::
|
@@ -7,13 +7,13 @@ title: enableHandleWeb
|
|
7
7
|
- **Type:** `boolean`
|
8
8
|
- **Default:** `false`
|
9
9
|
|
10
|
-
|
11
|
-
First you need to enable the "BFF" function using [new](/apis/app/commands#modern-new) command.
|
12
|
-
:::
|
10
|
+
import EnableBFFCaution from "@site-docs-en/components/enable-bff-caution";
|
13
11
|
|
14
|
-
|
12
|
+
<EnableBFFCaution />
|
15
13
|
|
16
|
-
|
14
|
+
By default, the BFF service can only handle requests for BFF APIs.
|
15
|
+
|
16
|
+
When this value is set to `true`, page request will also pass through BFF, and the default logic for page rendering built in Modern.js will run as the last middleware of the BFF service.
|
17
17
|
|
18
18
|
```ts title="modern.config.ts"
|
19
19
|
export default defineConfig({
|
@@ -7,18 +7,18 @@ sidebar_label: prefix
|
|
7
7
|
- **Type:** `string`
|
8
8
|
- **Default:** `/api`
|
9
9
|
|
10
|
-
|
11
|
-
First you need to enable the "BFF" function using [new](/apis/app/commands#modern-new) command.
|
12
|
-
:::
|
10
|
+
import EnableBFFCaution from "@site-docs-en/components/enable-bff-caution";
|
13
11
|
|
14
|
-
|
12
|
+
<EnableBFFCaution />
|
13
|
+
|
14
|
+
By default, the prefix for accessing routes in the BFF API directory is `/api`, as shown in the following directory structure:
|
15
15
|
|
16
16
|
```bash
|
17
17
|
api
|
18
18
|
└── hello.ts
|
19
19
|
```
|
20
20
|
|
21
|
-
The corresponding
|
21
|
+
The route corresponding to `api/hello.ts` when accessed is `localhost:8080/api/hello`.
|
22
22
|
|
23
23
|
This configuration option can modify the default route prefix:
|
24
24
|
|
@@ -30,4 +30,4 @@ export default defineConfig({
|
|
30
30
|
});
|
31
31
|
```
|
32
32
|
|
33
|
-
The corresponding `api/hello.ts`
|
33
|
+
The corresponding route for `api/hello.ts` when accessed is `localhost:8080/api-demo/hello`.
|
@@ -7,16 +7,13 @@ sidebar_label: proxy
|
|
7
7
|
- **Type:** `Record<string, string>`
|
8
8
|
- **Default:** `{}`
|
9
9
|
|
10
|
-
|
11
|
-
First you need to enable the "BFF" function using [new](/apis/app/commands#modern-new) command.
|
10
|
+
import EnableBFFCaution from "@site-docs-en/components/enable-bff-caution";
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
With simple configuration, no code is required, Modern.js automatically forwards requests. Requests sent to Modern.js BFF server are proxied to the specified service.
|
12
|
+
<EnableBFFCaution />
|
16
13
|
|
17
|
-
|
14
|
+
With simple configuration, Modern.js can automatically proxy requests sent to the BFF server to the specified service.
|
18
15
|
|
19
|
-
Add the following configuration to `modern.server-runtime.config.
|
16
|
+
Add the following configuration to `modern.server-runtime.config.js` to enable proxy:
|
20
17
|
|
21
18
|
```ts title="modern.server-runtime.config.ts"
|
22
19
|
import { defineConfig } from '@modern-js/app-tools/server';
|
@@ -29,41 +26,31 @@ export default defineConfig({
|
|
29
26
|
});
|
30
27
|
```
|
31
28
|
|
32
|
-
Assuming
|
29
|
+
Assuming the address of Modern.js BFF server is `localhost:8080`, all requests starting with `api` will be proxied to `https://cnodejs.org`, for example, the request to `localhost:8080/api/v1/topics` will be proxied to `https://cnodejs.org/api/v1/topics`.
|
33
30
|
|
34
|
-
|
31
|
+
import BFFProxyPathRewrite from "@site-docs/components/bff-proxy-path-rewrite";
|
35
32
|
|
36
|
-
|
37
|
-
import { defineConfig } from '@modern-js/app-tools/server';
|
38
|
-
export default defineConfig({
|
39
|
-
bff: {
|
40
|
-
proxy: {
|
41
|
-
'/api': {
|
42
|
-
target: 'https://cnodejs.org',
|
43
|
-
pathRewrite: { '/api/topics': '/api/v1/topics' },
|
44
|
-
changeOrigin: true,
|
45
|
-
},
|
46
|
-
},
|
47
|
-
},
|
48
|
-
});
|
49
|
-
```
|
33
|
+
<BFFProxyPathRewrite />
|
50
34
|
|
51
|
-
Unlike [dev.proxy](/configure/app/dev/proxy), the proxy
|
35
|
+
Unlike [dev.proxy](/configure/app/dev/proxy), the proxy here only applies to requests entering the BFF/API service; at the same time, this configuration can not only be used in the development environment, but also proxies corresponding requests in the production environment.
|
52
36
|
|
53
|
-
|
37
|
+
import BFFProxyPrinciple from "@site-docs/components/bff-proxy-principle";
|
54
38
|
|
55
|
-
|
39
|
+
<BFFProxyPrinciple />
|
56
40
|
|
57
|
-
|
41
|
+
## Common Usage
|
58
42
|
|
59
|
-
|
43
|
+
### Solving Cross-Domain Issues for APIs
|
44
|
+
|
45
|
+
During project development, cross-domain issues are often encountered because web pages and API services are not deployed under the same domain name.
|
46
|
+
There are many ways to solve cross-domain issues, and here we can easily solve them using `bff.proxy`.
|
60
47
|
|
61
48
|
:::info
|
62
|
-
|
49
|
+
Under BFF proxy mode, if you don't need to write BFF code, the API directory can be deleted; BFF proxy will still be enabled.
|
63
50
|
|
64
51
|
:::
|
65
52
|
|
66
|
-
As shown below, in
|
53
|
+
As shown below, the following configuration in `modern.server-runtime.config.ts` will proxy all web page requests starting with `/api` to a service on another domain with the same domain.
|
67
54
|
|
68
55
|
```ts title="modern.server-runtime.config.ts"
|
69
56
|
export default defineServerConfig({
|
@@ -74,3 +61,5 @@ export default defineServerConfig({
|
|
74
61
|
},
|
75
62
|
};
|
76
63
|
```
|
64
|
+
|
65
|
+
|
@@ -17,7 +17,7 @@ This option **is used to configure the Modern.js Builder plugins**. If you need
|
|
17
17
|
|
18
18
|
- Use [plugins](/configure/app/builder-plugins) to configure Modern.js framework plugins.
|
19
19
|
- Use [tools.webpack](/configure/app/tools/webpack) or [tools.webpackChain](/configure/app/tools/webpack-chain) to configure webpack plugins.
|
20
|
-
- Use [tools.babel](/configure/app/tools/babel) to configure
|
20
|
+
- Use [tools.babel](/configure/app/tools/babel) to configure Babel plugins.
|
21
21
|
|
22
22
|
## When to use
|
23
23
|
|
@@ -9,39 +9,39 @@ sidebar_position: 9
|
|
9
9
|
|
10
10
|
Used to configure custom Modern.js framework plugins.
|
11
11
|
|
12
|
-
|
12
|
+
Refer to [How to Develop Plugins](/guides/topic-detail/framework-plugin/implement) for how to write custom plugins.
|
13
13
|
|
14
|
-
##
|
14
|
+
## Note
|
15
15
|
|
16
|
-
This
|
16
|
+
This option is used to configure framework plugins. If you need to configure other types of plugins, please choose the corresponding configuration method:
|
17
17
|
|
18
|
-
-
|
19
|
-
-
|
20
|
-
-
|
18
|
+
- To configure Modern.js Builder plugins, use the [builderPlugins](/configure/app/builder-plugins) option.
|
19
|
+
- To configure webpack plugins, use the [tools.webpack](/configure/app/tools/webpack) or [tools.webpackChain](/configure/app/tools/webpack-chain) options.
|
20
|
+
- To configure Babel plugins, use the [tools.babel](/configure/app/tools/babel) option.
|
21
21
|
|
22
|
-
## Plugin
|
22
|
+
## Plugin types
|
23
23
|
|
24
|
-
|
24
|
+
Modern.js has three types of plugins:
|
25
25
|
|
26
|
-
- `CLI
|
27
|
-
- `Server
|
28
|
-
- `Runtime
|
26
|
+
- `CLI plugins`, applicable to local development, compilation and construction stages, can extend various capabilities in the command line and compilation stages.
|
27
|
+
- `Server plugins`, applicable to the server.
|
28
|
+
- `Runtime plugins`, applicable to the front-end runtime.
|
29
29
|
|
30
|
-
|
30
|
+
Currently, Modern.js has opened up the ability to customize CLI plugins, and Server plugins and Runtime plugins will be opened up later.
|
31
31
|
|
32
32
|
## Plugin execution order
|
33
33
|
|
34
|
-
By default, custom plugins are executed
|
34
|
+
By default, custom plugins are executed in the order of the `plugins` array, and the execution time of built-in Modern.js plugins is earlier than that of custom plugins.
|
35
35
|
|
36
|
-
When the plugin
|
36
|
+
When the plugin sets options that control the order, such as `pre` and `post`, the execution order will be adjusted based on the declared fields. Refer to [Relationship between plugins](/guides/topic-detail/framework-plugin/relationship) for more information.
|
37
37
|
|
38
38
|
## Example
|
39
39
|
|
40
|
-
|
40
|
+
The following is an example of using CLI plugins.
|
41
41
|
|
42
|
-
###
|
42
|
+
### Use plugins on npm
|
43
43
|
|
44
|
-
To use
|
44
|
+
To use plugins from npm registry, you need to first install the plugins , and import them in `modern.config.ts`.
|
45
45
|
|
46
46
|
```ts title="modern.config.ts"
|
47
47
|
import myPlugin from 'my-plugin';
|
@@ -53,7 +53,7 @@ export default defineConfig({
|
|
53
53
|
|
54
54
|
### Use local plugins
|
55
55
|
|
56
|
-
|
56
|
+
To use local plugins, import them directly using a relative path.
|
57
57
|
|
58
58
|
```ts title="modern.config.ts"
|
59
59
|
import myPlugin from './config/plugin/myPlugin';
|
@@ -65,7 +65,7 @@ export default defineConfig({
|
|
65
65
|
|
66
66
|
### Plugin configuration
|
67
67
|
|
68
|
-
If the plugin provides some custom configuration options,
|
68
|
+
If the plugin provides some custom configuration options, they can be passed in as parameters to the plugin function.
|
69
69
|
|
70
70
|
```ts title="modern.config.ts"
|
71
71
|
import myPlugin from 'my-plugin';
|
@@ -5,7 +5,7 @@ sidebar_position: 1
|
|
5
5
|
|
6
6
|
# Overview
|
7
7
|
|
8
|
-
This section describes
|
8
|
+
This section describes configuration of the Runtime plugin.
|
9
9
|
|
10
10
|
## Configuration
|
11
11
|
|
@@ -32,13 +32,34 @@ export default defineConfig({
|
|
32
32
|
|
33
33
|
#### DefineConfig
|
34
34
|
|
35
|
-
Configure
|
35
|
+
Configure using [`defineConfig`](/apis/app/runtime/app/define-config) API:
|
36
36
|
|
37
37
|
:::info
|
38
|
-
When there is a function in the runtime configuration, it can only be configured
|
38
|
+
When there is a function in the runtime configuration, it can only be configured this way.
|
39
39
|
|
40
40
|
:::
|
41
41
|
|
42
|
+
import { Tabs, Tab as TabItem } from "@theme";
|
43
|
+
|
44
|
+
<Tabs>
|
45
|
+
<TabItem value="layout" label="Conventional Routing" default>
|
46
|
+
|
47
|
+
```tsx title="src/routes/layout.tsx"
|
48
|
+
import type { AppConfig } from '@modern-js/runtime';
|
49
|
+
|
50
|
+
export const config = (): AppConfig => {
|
51
|
+
return {
|
52
|
+
router: {
|
53
|
+
supportHtml5History: false
|
54
|
+
}
|
55
|
+
}
|
56
|
+
};
|
57
|
+
```
|
58
|
+
|
59
|
+
</TabItem>
|
60
|
+
|
61
|
+
<TabItem value="app" label="Self-controlled Routing">
|
62
|
+
|
42
63
|
```ts title="src/App.tsx"
|
43
64
|
import { defineConfig } from '@modern-js/runtime';
|
44
65
|
|
@@ -55,6 +76,9 @@ defineConfig(App, {
|
|
55
76
|
export default App;
|
56
77
|
```
|
57
78
|
|
79
|
+
</TabItem>
|
80
|
+
</Tabs>
|
81
|
+
|
58
82
|
:::info
|
59
83
|
Using runtime configuration, you can solve the problem that runtime plugin configuration needs to be at runtime to get specific content.
|
60
84
|
|
@@ -63,7 +87,7 @@ Runtime plugin runtime configuration and configuration directly in `modern.confi
|
|
63
87
|
:::
|
64
88
|
|
65
89
|
:::warning
|
66
|
-
defineConfig
|
90
|
+
The `defineConfig` API only accepts the specific configuration of Runtime plugins. Enabling the plugin is determined through `modern.config.ts` configuration."
|
67
91
|
|
68
92
|
:::
|
69
93
|
|
@@ -35,6 +35,6 @@ interface AppInfo {
|
|
35
35
|
|
36
36
|
### Other Config
|
37
37
|
|
38
|
-
|
38
|
+
In the `masterApp` configuration, developers can pass through options supported by Garfish
|
39
39
|
|
40
40
|
All supported configuration items [see here](https://garfishjs.org/api/run/#%E5%8F%82%E6%95%B0).
|
@@ -11,14 +11,14 @@ import RouterLegacyTip from "@site-docs-en/components/router-legacy-tip"
|
|
11
11
|
- **Type:** `boolean | Object`
|
12
12
|
- **Default:** `false`
|
13
13
|
|
14
|
-
When
|
14
|
+
When enabled, the router option provides routing management for Modern.js conventional routes. It is based on [React Router 6](https://reactrouter.com/).
|
15
15
|
|
16
16
|
## basename
|
17
17
|
|
18
18
|
- **Type:** `string`
|
19
19
|
- **Default:** ``
|
20
20
|
|
21
|
-
The basename
|
21
|
+
The basename option specifies the subpath where the app is deployed, for situations where it cannot be deployed to the root domain.
|
22
22
|
|
23
23
|
## supportHtml5History
|
24
24
|
|
@@ -7,13 +7,13 @@ sidebar_label: baseUrl
|
|
7
7
|
- **Type:** `string | string[]`
|
8
8
|
- **Default:** `undefined`
|
9
9
|
|
10
|
-
Uniformly set the server-
|
10
|
+
Uniformly set the prefix of server-side routes (commonly used in situations where multiple applications share the same domain name to distinguish traffic).
|
11
11
|
|
12
12
|
```ts title="modern.config.ts"
|
13
13
|
export default defineConfig({
|
14
14
|
server: {
|
15
|
-
// All generated routes
|
16
|
-
//
|
15
|
+
// All generated routes will automatically have the prefix `/base`
|
16
|
+
// Generated server-side route file path: dist/route.json
|
17
17
|
baseUrl: '/base'
|
18
18
|
|
19
19
|
// Multiple baseUrl
|
@@ -22,7 +22,7 @@ export default defineConfig({
|
|
22
22
|
})
|
23
23
|
```
|
24
24
|
|
25
|
-
After `dev`, you
|
25
|
+
After running `dev`, you will see that the route access will have the corresponding prefix added:
|
26
26
|
|
27
27
|
```bash
|
28
28
|
App running at:
|
@@ -7,9 +7,9 @@ sidebar_label: enableFrameworkExt
|
|
7
7
|
- **Type:** `boolean`
|
8
8
|
- **Default:** `false`
|
9
9
|
|
10
|
-
By default,
|
10
|
+
By default, when the [custom Web Server feature](/guides/advanced-features/web-server) is enabled, the Middleware will use the Modern.js's syntax.
|
11
11
|
|
12
|
-
|
12
|
+
Enabling `server.enableFrameworkExt` allows the use of syntax extensions from other frameworks.
|
13
13
|
|
14
14
|
```ts title="modern.config.ts"
|
15
15
|
export default defineConfig({
|
@@ -32,7 +32,7 @@ export const middleware: Middleware = (ctx, next) => {
|
|
32
32
|
};
|
33
33
|
```
|
34
34
|
|
35
|
-
|
35
|
+
After enabling it, the Middleware type will be exported from other namespaces, and syntax extensions from frameworks can be used:
|
36
36
|
|
37
37
|
```ts title="server/index.ts"
|
38
38
|
import { SomeType } from '@modern-js/runtime/{namespace}';
|
@@ -44,6 +44,6 @@ export const middleware: SomeType = (...args) => {
|
|
44
44
|
```
|
45
45
|
|
46
46
|
:::note
|
47
|
-
The above code is
|
47
|
+
The above code is pseudocode, and the specific usage needs to refer to the corresponding framework extension.
|
48
48
|
|
49
49
|
:::
|