@modern-js/main-doc 0.0.0-next-1685383616364 → 0.0.0-next-1685436485731
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 +7 -2
- package/docs/en/apis/app/commands.mdx +5 -5
- package/docs/en/apis/app/hooks/api/api.mdx +80 -0
- package/docs/en/apis/app/hooks/api/app.mdx +12 -0
- package/docs/en/apis/app/hooks/api/lambda.mdx +57 -0
- package/docs/en/apis/app/hooks/api/test.mdx +1 -1
- package/docs/en/apis/app/hooks/config/html.mdx +2 -2
- package/docs/en/apis/app/hooks/config/icon.mdx +19 -19
- package/docs/en/apis/app/hooks/config/mock.mdx +1 -1
- package/docs/en/apis/app/hooks/config/public.mdx +10 -10
- package/docs/en/apis/app/hooks/config/storybook.mdx +3 -3
- package/docs/en/apis/app/hooks/config/upload.mdx +13 -13
- package/docs/en/apis/app/hooks/modern-config.mdx +4 -4
- package/docs/en/apis/app/hooks/server/index_.mdx +2 -9
- package/docs/en/apis/app/hooks/server/test.mdx +5 -2
- package/docs/en/apis/app/hooks/shared.mdx +1 -1
- package/docs/en/apis/app/hooks/src/app.mdx +17 -27
- package/docs/en/apis/app/hooks/src/index_.mdx +6 -6
- package/docs/en/apis/app/hooks/src/pages.mdx +41 -37
- package/docs/en/apis/app/hooks/src/routes.mdx +16 -36
- package/docs/en/apis/app/hooks/src/server.mdx +1 -1
- package/docs/en/apis/app/hooks/src/stories.mdx +6 -3
- package/docs/en/apis/app/hooks/src/test.mdx +4 -3
- package/docs/en/apis/app/runtime/web-server/hook.mdx +2 -2
- package/docs/en/apis/app/runtime/web-server/middleware.mdx +2 -2
- package/docs/en/components/init-app.mdx +3 -3
- package/docs/en/components/init-rspack-app.mdx +4 -4
- package/docs/en/components/ua-polyfill.mdx +2 -2
- package/docs/en/configure/app/tools/swc.mdx +2 -2
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -2
- package/docs/en/guides/advanced-features/bff/function.mdx +4 -4
- package/docs/en/guides/advanced-features/bff/type.mdx +5 -5
- package/docs/en/guides/advanced-features/rspack-start.mdx +2 -2
- package/docs/en/guides/advanced-features/ssg.mdx +2 -2
- package/docs/en/guides/advanced-features/testing.mdx +2 -2
- package/docs/en/guides/advanced-features/web-server.mdx +2 -2
- package/docs/en/guides/basic-features/css.mdx +2 -2
- package/docs/en/guides/basic-features/routes.mdx +11 -7
- package/docs/en/guides/concept/entries.mdx +3 -3
- package/docs/en/guides/topic-detail/generator/codesmith/develop.mdx +3 -3
- package/docs/en/guides/topic-detail/generator/plugin/develop.mdx +13 -13
- package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +8 -8
- package/docs/en/tutorials/first-app/c03-css.mdx +2 -2
- package/docs/en/tutorials/first-app/c08-entries.mdx +3 -3
- package/docs/zh/apis/app/commands.mdx +3 -3
- package/docs/zh/apis/app/hooks/api/{functions/api.mdx → api.mdx} +4 -4
- package/docs/zh/apis/app/hooks/api/app.mdx +12 -0
- package/docs/zh/apis/app/hooks/api/{framework/lambda.mdx → lambda.mdx} +5 -5
- package/docs/zh/apis/app/hooks/api/test.mdx +3 -3
- package/docs/zh/apis/app/hooks/config/icon.mdx +15 -15
- package/docs/zh/apis/app/hooks/config/mock.mdx +1 -1
- package/docs/zh/apis/app/hooks/config/public.mdx +3 -3
- package/docs/zh/apis/app/hooks/config/upload.mdx +1 -1
- package/docs/zh/apis/app/hooks/modern-config.mdx +3 -3
- package/docs/zh/apis/app/hooks/server/index_.mdx +1 -6
- package/docs/zh/apis/app/hooks/shared.mdx +1 -1
- package/docs/zh/apis/app/hooks/src/app.mdx +15 -25
- package/docs/zh/apis/app/hooks/src/index_.mdx +6 -6
- package/docs/zh/apis/app/hooks/src/pages.mdx +7 -3
- package/docs/zh/apis/app/hooks/src/routes.mdx +4 -4
- package/docs/zh/apis/app/hooks/src/stories.mdx +1 -1
- package/docs/zh/components/ua-polyfill.mdx +1 -1
- package/docs/zh/configure/app/tools/swc.mdx +2 -2
- package/docs/zh/guides/advanced-features/rspack-start.mdx +2 -2
- package/docs/zh/guides/advanced-features/ssg.mdx +1 -1
- package/docs/zh/guides/advanced-features/testing.mdx +2 -2
- package/docs/zh/guides/advanced-features/web-server.mdx +1 -1
- package/docs/zh/guides/basic-features/css.mdx +1 -1
- package/docs/zh/guides/basic-features/routes.mdx +7 -4
- package/docs/zh/guides/concept/entries.mdx +3 -3
- package/docs/zh/guides/topic-detail/generator/plugin/develop.mdx +14 -14
- package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +4 -4
- package/docs/zh/guides/topic-detail/model/test-model.mdx +1 -1
- package/docs/zh/tutorials/first-app/c03-css.mdx +1 -1
- package/docs/zh/tutorials/first-app/c08-entries.mdx +1 -1
- package/package.json +5 -5
- package/docs/en/apis/app/hooks/api/framework/_category_.json +0 -4
- package/docs/en/apis/app/hooks/api/framework/lambda.mdx +0 -57
- package/docs/en/apis/app/hooks/api/functions/_category_.json +0 -4
- package/docs/en/apis/app/hooks/api/functions/api.mdx +0 -81
- package/docs/en/apis/app/hooks/api/functions/app.mdx +0 -12
- package/docs/en/apis/app/hooks/api/functions/common.mdx +0 -9
- package/docs/zh/apis/app/hooks/api/framework/_category_.json +0 -4
- package/docs/zh/apis/app/hooks/api/functions/_category_.json +0 -4
- package/docs/zh/apis/app/hooks/api/functions/app.mdx +0 -12
- package/docs/zh/apis/app/hooks/api/functions/common.mdx +0 -9
|
@@ -12,9 +12,9 @@ Modern.js provides a microgenerator to create a microgenerator project, you can
|
|
|
12
12
|
$ mkdir <projectDir>
|
|
13
13
|
$ npx @modern-js/codesmith-cli @modern-js/generator-generator
|
|
14
14
|
|
|
15
|
-
?
|
|
16
|
-
?
|
|
17
|
-
?
|
|
15
|
+
? Please fill in the project name: <generatorName>
|
|
16
|
+
? Please select the package manager: pnpm
|
|
17
|
+
? Please select the programming language: TS
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## Add template file
|
|
@@ -17,25 +17,25 @@ Different plugin types will ask different questions. You can choose the plugin t
|
|
|
17
17
|
### Extension type
|
|
18
18
|
|
|
19
19
|
```
|
|
20
|
-
? Please select the
|
|
21
|
-
? Please select the
|
|
22
|
-
?
|
|
23
|
-
?
|
|
24
|
-
?
|
|
25
|
-
?
|
|
26
|
-
?
|
|
20
|
+
? Please select the type of project you want to create: Npm Module
|
|
21
|
+
? Please select the project scenario: Generator Plugin
|
|
22
|
+
? Please fill in the package name of the generator plugin: plugin
|
|
23
|
+
? Please select the programming language: TS
|
|
24
|
+
? Please select the package manager: pnpm
|
|
25
|
+
? Please select the type of plugin: extend
|
|
26
|
+
? Please select the base type of the plugin: Web App
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
### Customized type
|
|
30
30
|
|
|
31
31
|
```
|
|
32
32
|
? Plugin Package Name: plugin
|
|
33
|
-
?
|
|
34
|
-
?
|
|
35
|
-
?
|
|
36
|
-
?
|
|
37
|
-
?
|
|
38
|
-
?
|
|
33
|
+
? Please select the programming language: TS
|
|
34
|
+
? Please select the package manager: pnpm
|
|
35
|
+
? Please fill in the plugin keyword: custom
|
|
36
|
+
? Please fill in the plugin keyword: mobile-app
|
|
37
|
+
? Please fill in the display name of the plugin: Mobile App
|
|
38
|
+
? Please select the base type of the plugin: Web App
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
After the execution of the create project command is completed, a project for developing the generator plugin will be generated accordingly, and the `meta` information will also be generated according to your selection in the `package.json`.
|
|
@@ -33,8 +33,8 @@ npx @modern-js/create@latest
|
|
|
33
33
|
After the project is created, we can enable the `micro frontend` through `pnpm run new`:
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
|
-
?
|
|
37
|
-
?
|
|
36
|
+
? Please select the operation you want: Enable features
|
|
37
|
+
? Please select the feature name: Enable Micro Front-end Feature
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
Next, let's register the micro frontend plugin and add the main micro frontend app and add the list of sub-apps:
|
|
@@ -115,8 +115,8 @@ npx @modern-js/create@latest
|
|
|
115
115
|
After the project is created, we can enable the `micro frontend` function through `pnpm run new`:
|
|
116
116
|
|
|
117
117
|
```bash
|
|
118
|
-
?
|
|
119
|
-
?
|
|
118
|
+
? Please select the operation you want: Enable features
|
|
119
|
+
? Please select the feature name: Enable Micro Front-end Feature
|
|
120
120
|
```
|
|
121
121
|
|
|
122
122
|
Next, let's register the micro frontend plugin and add the main micro frontend app and add the list of sub-apps:
|
|
@@ -143,8 +143,8 @@ npx @modern-js/create@latest
|
|
|
143
143
|
After create sub-app. We execute `pnpm run new` to enable the `micro frontend` function:
|
|
144
144
|
|
|
145
145
|
```bash
|
|
146
|
-
?
|
|
147
|
-
?
|
|
146
|
+
? Please select the operation you want: Enable features
|
|
147
|
+
? Please select the feature name: Enable Micro Front-end Feature
|
|
148
148
|
```
|
|
149
149
|
|
|
150
150
|
Next, let's register the micro frontend plugin and modify `modern.config.ts` to add the configuration of the micro frontend sub-app `deploy.microFrontend`:
|
|
@@ -192,8 +192,8 @@ npx @modern-js/create@latest
|
|
|
192
192
|
After create sub-app. We execute `pnpm run new` to enable the `micro frontend` function:
|
|
193
193
|
|
|
194
194
|
```bash
|
|
195
|
-
?
|
|
196
|
-
?
|
|
195
|
+
? Please select the operation you want: Enable features
|
|
196
|
+
? Please select the feature name: Enable Micro Front-end Feature
|
|
197
197
|
```
|
|
198
198
|
|
|
199
199
|
Next, let's register the micro frontend plugin and modify `modern.config.ts` to add the configuration of the micro frontend sub-app `deploy.microFrontend`:
|
|
@@ -114,8 +114,8 @@ Modern.js integrates the mainstream, light, general-purpose Utility Class librar
|
|
|
114
114
|
Execute `pnpm run new` and select the following to start Tailwind CSS:
|
|
115
115
|
|
|
116
116
|
```bash
|
|
117
|
-
?
|
|
118
|
-
?
|
|
117
|
+
? Please select the operation you want: Enable features
|
|
118
|
+
? Please select the feature name: Enable Tailwind CSS
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
Register the Tailwind plugin in `modern.config.ts`:
|
|
@@ -14,9 +14,9 @@ A complete project may require multiple entries, Modern.js supports the automati
|
|
|
14
14
|
We can also use it to create new project elements and execute `pnpm run new` in the project root directory:
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
?
|
|
18
|
-
?
|
|
19
|
-
?
|
|
17
|
+
? Please select the operation you want: Create Element
|
|
18
|
+
? Please select the type of element to create: New "entry"
|
|
19
|
+
? Please fill in the entry name: landing-page
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
When created, the project will look like this:
|
|
@@ -126,7 +126,7 @@ Options:
|
|
|
126
126
|
```bash
|
|
127
127
|
$ npx modern new
|
|
128
128
|
? 请选择你想要的操作 创建工程元素
|
|
129
|
-
?
|
|
129
|
+
? 请选择创建元素类型 新建「应用入口」
|
|
130
130
|
? 请填写入口名称 entry
|
|
131
131
|
```
|
|
132
132
|
|
|
@@ -137,8 +137,8 @@ $ npx modern new
|
|
|
137
137
|
```bash
|
|
138
138
|
$ npx modern new
|
|
139
139
|
? 请选择你想要的操作 启用可选功能
|
|
140
|
-
?
|
|
141
|
-
❯ 启用 Tailwind CSS 支持
|
|
140
|
+
? 请选择功能名称 (Use arrow keys)
|
|
141
|
+
❯ 启用 「Tailwind CSS」 支持
|
|
142
142
|
启用「BFF」功能
|
|
143
143
|
启用「微前端」模式
|
|
144
144
|
启用「单元测试 / 集成测试」功能
|
|
@@ -4,7 +4,7 @@ sidebar_position: 1
|
|
|
4
4
|
---
|
|
5
5
|
# **/*.[tj]s
|
|
6
6
|
|
|
7
|
-
在 BFF
|
|
7
|
+
在 [BFF 函数写法](/guides/advanced-features/bff/type.html#函数写法)下,声明 API 路由的文件。除了[某些约定文件](/apis/app/hooks/api/api#白名单)外,`api` 目录下的文件会被注册为接口的路由。
|
|
8
8
|
|
|
9
9
|
:::info
|
|
10
10
|
使用 `api` 目录需要开启 BFF 功能,需要在项目下执行 new 命令启用「BFF」功能。
|
|
@@ -31,7 +31,7 @@ sidebar_position: 1
|
|
|
31
31
|
|
|
32
32
|
### 动态路由
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
路由系统支持通过 `[]` 命名的文件目录生成动态路由。
|
|
35
35
|
|
|
36
36
|
- `api/user/[username]/info.ts` -> `$BASENAME/user/:username/info`
|
|
37
37
|
- `api/user/[username]/delete.ts` -> `$BASENAME/user/:username/delete`
|
|
@@ -64,7 +64,7 @@ export const get = async () => {
|
|
|
64
64
|
};
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
这样导出函数,则会得到一个 `
|
|
67
|
+
这样导出函数,则会得到一个 `GET` 接口。
|
|
68
68
|
|
|
69
69
|
应用工程中支持了 9 个 Method 定义,即:`GET`、`POST`、`PUT`、`DELETE`、`CONNECT`、`TRACE`、`PATCH`、`OPTION`、`HEAD`,即可以用这些 Method 作为函数导出的名字。
|
|
70
70
|
|
|
@@ -75,6 +75,6 @@ export const get = async () => {
|
|
|
75
75
|
可以在一个文件中定义多个不同 Method 的函数,但如果定义多个相同 Method 的函数,则只有第一个会生效。
|
|
76
76
|
|
|
77
77
|
:::info
|
|
78
|
-
|
|
78
|
+
需要注意的是,定义的函数都应该是异步的,这个与函数调用时类型有关。
|
|
79
79
|
|
|
80
80
|
:::
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: lambda/*.[tj]s
|
|
3
|
-
sidebar_position:
|
|
3
|
+
sidebar_position: 3
|
|
4
4
|
---
|
|
5
5
|
# lambda/*.[tj]s
|
|
6
6
|
|
|
7
|
-
在 BFF
|
|
7
|
+
在 [BFF 框架写法](/guides/advanced-features/bff/type.html#框架写法)下,声明 API 路由的文件。除了[某些约定文件](/apis/app/hooks/api/lambda#白名单)外,`lambda/` 目录下的文件会被注册为接口的路由。
|
|
8
8
|
|
|
9
9
|
:::info
|
|
10
10
|
使用 `api` 目录需要开启 BFF 功能,需要在项目下执行 new 命令启用「BFF」功能。
|
|
@@ -34,7 +34,7 @@ sidebar_position: 1
|
|
|
34
34
|
|
|
35
35
|
### 动态路由
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
路由系统支持通过 `[]` 命名的文件目录生成动态路由。
|
|
38
38
|
|
|
39
39
|
- `api/lambda/user/[username]/info.ts` -> `$BASENAME/user/:username/info`
|
|
40
40
|
- `api/lambda/user/[username]/delete.ts` -> `$BASENAME/user/:username/delete`
|
|
@@ -44,7 +44,7 @@ sidebar_position: 1
|
|
|
44
44
|
|
|
45
45
|
### 白名单
|
|
46
46
|
|
|
47
|
-
默认 `
|
|
47
|
+
默认 `lambda` 目录下所有文件都会当作 BFF 函数文件去解析,但同样我们也设置了白名单,这些文件不被被解析:
|
|
48
48
|
|
|
49
49
|
- 命名以 `_` 开头的文件。例如:`_utils.ts`。
|
|
50
50
|
- 命名以 `_` 开头的文件夹下所有文件。例如:`_utils/index.ts`、`_utils/cp.ts`。
|
|
@@ -54,4 +54,4 @@ sidebar_position: 1
|
|
|
54
54
|
|
|
55
55
|
## 函数定义
|
|
56
56
|
|
|
57
|
-
和函数写法下[函数定义](/apis/app/hooks/api/
|
|
57
|
+
和函数写法下[函数定义](/apis/app/hooks/api/api#函数定义)完全一致。
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: test.[tj]s
|
|
3
|
-
sidebar_position:
|
|
3
|
+
sidebar_position: 4
|
|
4
4
|
---
|
|
5
5
|
# test.[tj]s
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The BFF test file of the application supports writing test cases in files with the suffix `.test.[tj]sx?` under the `api/` directory.
|
|
8
8
|
|
|
9
9
|
:::info
|
|
10
|
-
|
|
10
|
+
Enabling unit testing and integration testing requires running the new command to enable the "Unit Testing/Integration Testing" function under the project first.
|
|
11
11
|
|
|
12
12
|
:::
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: icon
|
|
2
|
+
title: icon/
|
|
3
3
|
sidebar_position: 2
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# icon/
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Favicon
|
|
9
9
|
|
|
10
10
|
当项目根目录的 `config` 目录下存在 `favicon.*` 文件时,Modern.js 会自动将该文件设置到 [html.favicon](/configure/app/html/favicon) 配置项中,用于生成页面的 favicon 图标:
|
|
11
11
|
|
|
@@ -24,15 +24,15 @@ sidebar_position: 2
|
|
|
24
24
|
|
|
25
25
|
在设置 app icon 时,Modern.js 会按以下顺序寻找文件:
|
|
26
26
|
|
|
27
|
-
- favicon.png
|
|
28
|
-
- favicon.jpg
|
|
29
|
-
- favicon.jpeg
|
|
30
|
-
- favicon.svg
|
|
31
|
-
- favicon.ico
|
|
27
|
+
- `favicon.png`
|
|
28
|
+
- `favicon.jpg`
|
|
29
|
+
- `favicon.jpeg`
|
|
30
|
+
- `favicon.svg`
|
|
31
|
+
- `favicon.ico`
|
|
32
32
|
|
|
33
|
-
##
|
|
33
|
+
## Apple Touch Icon
|
|
34
34
|
|
|
35
|
-
当项目根目录的 `config` 目录下存在 `icon.*` 文件时,Modern.js 会自动将该文件设置到 [html.appIcon](/configure/app/html/app-icon) 配置项中,用于生成 iOS 系统下的
|
|
35
|
+
当项目根目录的 `config` 目录下存在 `icon.*` 文件时,Modern.js 会自动将该文件设置到 [html.appIcon](/configure/app/html/app-icon) 配置项中,用于生成 iOS 系统下的 Apple Touch Icon 图标。
|
|
36
36
|
|
|
37
37
|
```
|
|
38
38
|
./config
|
|
@@ -49,8 +49,8 @@ sidebar_position: 2
|
|
|
49
49
|
|
|
50
50
|
在设置 app icon 时,Modern.js 会按以下顺序寻找文件:
|
|
51
51
|
|
|
52
|
-
- icon.png
|
|
53
|
-
- icon.jpg
|
|
54
|
-
- icon.jpeg
|
|
55
|
-
- icon.svg
|
|
56
|
-
- icon.ico
|
|
52
|
+
- `icon.png`
|
|
53
|
+
- `icon.jpg`
|
|
54
|
+
- `icon.jpeg`
|
|
55
|
+
- `icon.svg`
|
|
56
|
+
- `icon.ico`
|
|
@@ -4,13 +4,13 @@ sidebar_position: 3
|
|
|
4
4
|
---
|
|
5
5
|
# public/
|
|
6
6
|
|
|
7
|
-
`public/`
|
|
7
|
+
`public/` 目录中可以放置任意格式的静态资源文件,文件会被服务端部署到对应的应用域名下。
|
|
8
8
|
|
|
9
9
|
## 说明
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
文件路由基于目录结构的约定,其中,`public/` 为根目录,对应 Web 应用根路径。
|
|
12
12
|
|
|
13
|
-
例如 `config/public/sdk/index.js`
|
|
13
|
+
例如 `config/public/sdk/index.js` 文件,在部署后将会被部署在 `${domain}/sdk/index.js` 下。
|
|
14
14
|
|
|
15
15
|
## 场景
|
|
16
16
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: modern.config.
|
|
2
|
+
title: modern.config.[tj]s
|
|
3
3
|
sidebar_position: 8
|
|
4
4
|
---
|
|
5
|
-
# modern.config.
|
|
5
|
+
# modern.config.[tj]s
|
|
6
6
|
|
|
7
7
|
Modern.js 配置文件, 通过该文件可以对当前项目的各个方面进行个性化配置。
|
|
8
8
|
|
|
9
|
-
了解配置的具体用法,请参考
|
|
9
|
+
了解配置的具体用法,请参考[配置使用](/configure/app/usage)。
|
|
@@ -4,11 +4,6 @@ sidebar_position: 1
|
|
|
4
4
|
---
|
|
5
5
|
# index.[tj]s
|
|
6
6
|
|
|
7
|
-
扩展 Modern.js Web Server 的文件,在此文件中可以给应用工程启动的 Web Server 添加 Hook 或 Middleware。
|
|
7
|
+
扩展 Modern.js Web Server 的文件,在此文件中可以给应用工程启动的 Web Server 添加 [Hook](/apis/app/runtime/web-server/hook) 或 [Middleware](/apis/app/runtime/web-server/middleware)。
|
|
8
8
|
|
|
9
9
|
可以对请求和响应进行拦截处理,鉴权与角色、请求预处理、异常兜底等。也可在内置处理逻辑(包括路由匹配、资源寻址、头部注入、页面渲染,静态 Web 托管)插入特定的业务逻辑。
|
|
10
|
-
|
|
11
|
-
:::info
|
|
12
|
-
具体使用示例可查看 [Hook](/apis/app/runtime/web-server/hook) & [Middleware](/apis/app/runtime/web-server/middleware)。
|
|
13
|
-
|
|
14
|
-
:::
|
|
@@ -4,46 +4,36 @@ sidebar_position: 1
|
|
|
4
4
|
---
|
|
5
5
|
# App.[tj]sx
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
应用使用[自控路由](/guides/basic-features/routes.html#self-controlled-routing)时的入口标识符。
|
|
8
8
|
|
|
9
9
|
`App.[tj]sx` 并不是实际的应用入口,Modern.js 会自动生成真正的构建打包的入口文件, 内容大致如下:
|
|
10
10
|
|
|
11
11
|
```js
|
|
12
12
|
import React from 'react';
|
|
13
|
+
import ReactDOM from 'react-dom/client';
|
|
13
14
|
import { createApp, bootstrap } from '@modern-js/runtime';
|
|
14
15
|
// App.[jt]sx
|
|
15
16
|
import App from '@_modern_js_src/App';
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from '@modern-js/runtime/model';
|
|
23
|
-
|
|
24
|
-
const createStatePlugins = config => {
|
|
25
|
-
const plugins = [];
|
|
26
|
-
plugins.push(immer(config['immer']));
|
|
27
|
-
plugins.push(effects(config['effects']));
|
|
28
|
-
plugins.push(autoActions(config['autoActions']));
|
|
29
|
-
plugins.push(devtools(config['devtools']));
|
|
30
|
-
return plugins;
|
|
31
|
-
};
|
|
17
|
+
// runtime plugin
|
|
18
|
+
import { router } from '@modern-js/runtime/plugins';
|
|
19
|
+
|
|
20
|
+
const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
|
|
21
|
+
const MOUNT_ID = 'root';
|
|
22
|
+
|
|
32
23
|
let AppWrapper = null;
|
|
24
|
+
|
|
33
25
|
function render() {
|
|
34
26
|
AppWrapper = createApp({
|
|
35
27
|
plugins: [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}),
|
|
40
|
-
],
|
|
41
|
-
})(App);
|
|
28
|
+
router({...{"serverBase":["/"]}, ...App.config?.router}),
|
|
29
|
+
]
|
|
30
|
+
})(App)
|
|
42
31
|
if (IS_BROWSER) {
|
|
43
|
-
bootstrap(AppWrapper, MOUNT_ID);
|
|
32
|
+
bootstrap(AppWrapper, MOUNT_ID, null, ReactDOM);
|
|
44
33
|
}
|
|
45
|
-
return AppWrapper
|
|
34
|
+
return AppWrapper
|
|
46
35
|
}
|
|
36
|
+
|
|
47
37
|
AppWrapper = render();
|
|
48
38
|
export default AppWrapper;
|
|
49
39
|
```
|
|
@@ -4,13 +4,13 @@ sidebar_position: 4
|
|
|
4
4
|
---
|
|
5
5
|
# index.[tj]s
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
应用使用自定义 `bootstrap` 时的入口标识。
|
|
8
8
|
|
|
9
|
-
通常情况下 [`
|
|
9
|
+
通常情况下 [`App.[tj]sx`](/apis/app/hooks/src/app) 钩子文件已经能满足我们的需求,当我们需要在 `bootstrap` 之前添加自定义行为或者完全接管 webpack 打包入口时,可以在 `src` 或者入口目录下放置 `index.[tj]s`。 下面有分两种情况进行讨论:
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## 在 bootstrap 之前添加自定义行为
|
|
12
12
|
|
|
13
|
-
只需要 `src/index.[tj]s`
|
|
13
|
+
只需要 `src/index.[tj]s` 默认导出函数:
|
|
14
14
|
|
|
15
15
|
```js title=src/index.js
|
|
16
16
|
import ReactDOM from 'react-dom/client';
|
|
@@ -22,9 +22,9 @@ export default (App: React.ComponentType) => {
|
|
|
22
22
|
};
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
## 完全接管 webpack 入口
|
|
26
26
|
|
|
27
|
-
当 `src/index.[tj]sx?` 下没有默认导出函数时,该文件即为真正的 webpack 打包入口文件, 可以直接像使用 create-react-app
|
|
27
|
+
当 `src/index.[tj]sx?` 下没有默认导出函数时,该文件即为真正的 webpack 打包入口文件, 可以直接像使用 create-react-app 等脚手架一样组织代码:
|
|
28
28
|
|
|
29
29
|
```js title=src/index.jsx
|
|
30
30
|
import React from 'react';
|
|
@@ -4,9 +4,13 @@ sidebar_position: 3
|
|
|
4
4
|
---
|
|
5
5
|
# pages/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
应用使用 [`Pages` 入口](https://modernjs.dev/v1/docs/guides/usages/entries#pages-%E5%85%A5%E5%8F%A3)时的入口标识。
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
:::info
|
|
10
|
+
兼容 Modern.js 1.0 `Pages` 入口,推荐使用[约定式路由](guides/basic-features/routes.html#约定式路由)。
|
|
11
|
+
:::
|
|
12
|
+
|
|
13
|
+
当项目结构为 `Pages 入口`类型时, 会分析 `src/pages` 目录下的文件得到客户端路由配置。
|
|
10
14
|
|
|
11
15
|
举例说明,例如以下目录结构:
|
|
12
16
|
|
|
@@ -20,7 +24,7 @@ sidebar_position: 3
|
|
|
20
24
|
└── info.jsx
|
|
21
25
|
```
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
对应生成的路由配置为:
|
|
24
28
|
|
|
25
29
|
```bash
|
|
26
30
|
[
|
|
@@ -4,13 +4,13 @@ sidebar_position: 2
|
|
|
4
4
|
---
|
|
5
5
|
# routes/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
应用使用[约定式路由](guides/basic-features/routes.html#约定式路由)时的入口标识。
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
约定式路由以 `routes/` 为约定的入口, 会分析 `src/routes` 目录下的文件得到客户端路由配置。
|
|
10
10
|
|
|
11
11
|
任何在 `src/routes` 下的 `layout.[tj]sx` 和 `page.[tj]sx` 都会作为应用的路由:
|
|
12
12
|
|
|
13
|
-
```bash {3}
|
|
13
|
+
```bash {3,4}
|
|
14
14
|
.
|
|
15
15
|
└── routes
|
|
16
16
|
├── layout.tsx
|
|
@@ -54,7 +54,7 @@ sidebar_position: 2
|
|
|
54
54
|
|
|
55
55
|
在组件中,可以通过 [useParams](/apis/app/runtime/router/router#useparams) 获取对应命名的参数。
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
在使用 [loader](/guides/basic-features/data-fetch#loader-函数) 函数获取数据时,`params` 会作为 `loader` 函数的入参,通过 `params` 的属性可以获取到对应的参数。
|
|
58
58
|
|
|
59
59
|
## 布局组件
|
|
60
60
|
|
|
@@ -8,7 +8,7 @@ sidebar_position: 7
|
|
|
8
8
|
|
|
9
9
|
可以在项目源码目录 `src/` 下创建 `*.stories.[tj]sx` 格式的文件作为 Storybook 的调试文件。
|
|
10
10
|
|
|
11
|
-
在项目下执行 dev story 命令,支持使用这些文件在 Storybook 中对相关内容进行调试。
|
|
11
|
+
在项目下执行 `npm run dev story` 命令,支持使用这些文件在 Storybook 中对相关内容进行调试。
|
|
12
12
|
|
|
13
13
|
:::info
|
|
14
14
|
使用 Storybook 需要提前在项目下执行 new 命令启用「Visual Testing (Storybook)」模式。
|
|
@@ -22,8 +22,8 @@ import SWC from '@modern-js/builder-doc/docs/zh/shared/swc.md';
|
|
|
22
22
|
首先,你需要执行 `pnpm run new` 启用 SWC 编译:
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
?
|
|
26
|
-
?
|
|
25
|
+
? 请选择你想要的操作 启用可选功能
|
|
26
|
+
? 请选择功能名称 启用「SWC 编译」
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
执行完成后,你只需在 `modern.config.ts` 文件中注册 SWC 插件,即可启用 SWC 编译和压缩能力。
|
|
@@ -37,8 +37,8 @@ import InitRspackApp from '@site-docs/components/init-rspack-app';
|
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
39
|
$ pnpm run new
|
|
40
|
-
?
|
|
41
|
-
?
|
|
40
|
+
? 请选择你想要的操作 启用可选功能
|
|
41
|
+
? 请选择功能名称 启用「Rspack 构建」
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
执行以上命令后,在 `modern.config.ts` 中添加 Rspack 相关配置即可:
|
|
@@ -9,8 +9,8 @@ Modern.js 默认集成了 [Jest](https://jestjs.io/) 的测试能力。
|
|
|
9
9
|
我们首先需要执行 `pnpm run new` 启用「单元测试 / 集成测试」功能:
|
|
10
10
|
|
|
11
11
|
```
|
|
12
|
-
?
|
|
13
|
-
?
|
|
12
|
+
? 请选择你想要的操作 启用可选功能
|
|
13
|
+
? 请选择功能名称 启用「单元测试 / 集成测试」功能
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
执行上述命令后,`package.json` 中将会自动生成 `"test": "modern test"` 命令。
|