@modern-js/main-doc 0.0.0-next-20221123182933 → 0.0.0-next-20221124071519
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 +3 -2
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/_category_.json +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/build.md +10 -10
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/dev.md +7 -7
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/index.md +2 -2
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/inspect.md +15 -15
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/lint.md +2 -2
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/new.md +15 -15
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/start.md +5 -5
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/test.md +5 -5
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/upgrade.md +7 -9
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/_category_.json +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/framework/lambda.md +22 -47
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/functions/api.md +46 -18
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/functions/app.md +2 -2
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/functions/common.md +4 -4
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/test.md +2 -4
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/html.md +2 -4
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/icon.md +3 -5
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/mock.md +1 -7
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/public.md +11 -13
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/storybook.md +3 -5
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/config/upload.md +14 -20
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/index.md +2 -7
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/modern-config.md +2 -4
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/server/index_.md +5 -3
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/server/test.md +2 -4
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/shared.md +1 -3
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/app.md +7 -3
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/index_.md +7 -8
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/pages.md +40 -43
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/stories.md +3 -5
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/test.md +3 -3
- package/en/docusaurus-plugin-content-docs/current/apis/app/overview.md +3 -2
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/app/define-config.md +2 -2
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/default-alias.md +0 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/env.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/model_.md +2 -2
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/testing/act.md +1 -1
- package/en/docusaurus-plugin-content-docs/current.json +10 -10
- package/package.json +3 -3
- package/zh/apis/app/commands/build.md +1 -1
- package/zh/apis/app/commands/index.md +1 -1
- package/zh/apis/app/commands/lint.md +1 -1
- package/zh/apis/app/commands/upgrade.md +0 -2
- package/zh/apis/app/hooks/api/framework/_category_.json +1 -1
- package/zh/apis/app/hooks/api/framework/lambda.md +7 -32
- package/zh/apis/app/hooks/api/functions/_category_.json +1 -1
- package/zh/apis/app/hooks/api/functions/api.md +28 -1
- package/zh/apis/app/hooks/api/functions/common.md +2 -4
- package/zh/apis/app/hooks/api/test.md +1 -3
- package/zh/apis/app/hooks/config/html.md +0 -2
- package/zh/apis/app/hooks/config/icon.md +1 -1
- package/zh/apis/app/hooks/config/mock.md +1 -7
- package/zh/apis/app/hooks/config/public.md +1 -3
- package/zh/apis/app/hooks/config/storybook.md +1 -3
- package/zh/apis/app/hooks/config/upload.md +0 -6
- package/zh/apis/app/hooks/modern-config.md +1 -3
- package/zh/apis/app/hooks/server/index_.md +4 -4
- package/zh/apis/app/hooks/server/test.md +1 -1
- package/zh/apis/app/hooks/shared.md +1 -2
- package/zh/apis/app/hooks/src/app.md +7 -3
- package/zh/apis/app/hooks/src/index_.md +1 -1
- package/zh/apis/app/hooks/src/pages.md +2 -3
- package/zh/apis/app/hooks/src/stories.md +1 -1
- package/zh/apis/app/overview.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/api/framework/app.md +0 -100
- package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/eslint.md +0 -9
- package/zh/apis/app/hooks/api/framework/app.md +0 -100
- package/zh/apis/app/hooks/src/eslint.md +0 -9
package/CHANGELOG.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# @modern-js/main-doc
|
2
2
|
|
3
|
-
## 0.0.0-next-
|
3
|
+
## 0.0.0-next-20221124071519
|
4
4
|
|
5
5
|
### Patch Changes
|
6
6
|
|
@@ -11,6 +11,7 @@
|
|
11
11
|
- Updated dependencies [2bc090c0]
|
12
12
|
- Updated dependencies [f96a7252]
|
13
13
|
- Updated dependencies [57077b2c]
|
14
|
+
- Updated dependencies [2ff6167b]
|
14
15
|
- Updated dependencies [5402fdb0]
|
15
16
|
- Updated dependencies [10d08a48]
|
16
17
|
- Updated dependencies [5d67c26c]
|
@@ -19,4 +20,4 @@
|
|
19
20
|
- Updated dependencies [3fae2d03]
|
20
21
|
- Updated dependencies [df41d71a]
|
21
22
|
- Updated dependencies [14b712da]
|
22
|
-
- @modern-js/builder-doc@0.0.0-next-
|
23
|
+
- @modern-js/builder-doc@0.0.0-next-20221124071519
|
@@ -8,18 +8,18 @@ Usage: modern build [options]
|
|
8
8
|
build application
|
9
9
|
|
10
10
|
Options:
|
11
|
-
-c --config <config>
|
12
|
-
-h, --help
|
13
|
-
--analyze
|
11
|
+
-c --config <config> configuration file path, which can be a relative path or an absolute path
|
12
|
+
-h, --help show command help
|
13
|
+
--analyze analyze the bundle and view size of each module
|
14
14
|
```
|
15
15
|
|
16
|
-
`modern build`
|
16
|
+
`modern build` command will by default build production in `dist/`.
|
17
17
|
|
18
|
-
|
18
|
+
you can configure the [`output.distPath`](/docs/configure/app/output/dist-path) specifies the output directory for the product.
|
19
19
|
|
20
|
-
##
|
20
|
+
## Analyze Bundle
|
21
21
|
|
22
|
-
|
22
|
+
execute `npx modern build --analyze` command,can produce an HTML file that analyzes the volume of the bundle while packaging the production code:
|
23
23
|
|
24
24
|
```
|
25
25
|
Bundle Analyzer saved report to /example/dist/report.html
|
@@ -31,13 +31,13 @@ File sizes after production build:
|
|
31
31
|
645 B dist/static/css/main.0dd3ecc1.css
|
32
32
|
```
|
33
33
|
|
34
|
-
|
34
|
+
Open the above HTML file in the browser, you can see the tile diagram of the packaged product, and perform package volume analysis and optimization:
|
35
35
|
|
36
36
|
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/mwa-build-analyze-8784f762c1ab0cb20935829d5f912c4c.png" />
|
37
37
|
|
38
|
-
>
|
38
|
+
> this features based on [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer).
|
39
39
|
|
40
|
-
##
|
40
|
+
## Command Arguments
|
41
41
|
|
42
42
|
import CommandTip from '@site-docs/components/command-tip.md'
|
43
43
|
|
@@ -7,17 +7,17 @@ sidebar_position: 1
|
|
7
7
|
```bash
|
8
8
|
Usage: modern dev [options]
|
9
9
|
|
10
|
-
|
10
|
+
Development commands
|
11
11
|
|
12
12
|
Options:
|
13
|
-
-e --entry <entry>
|
14
|
-
-c --config <config>
|
15
|
-
-h, --help
|
16
|
-
--analyze
|
17
|
-
--api-only
|
13
|
+
-e --entry <entry> compiler by entry
|
14
|
+
-c --config <config> configuration file path, which can be a relative path or an absolute path
|
15
|
+
-h, --help show command help
|
16
|
+
--analyze analyze the bundle and view size of each module
|
17
|
+
--api-only only start API service
|
18
18
|
```
|
19
19
|
|
20
|
-
`modern dev`
|
20
|
+
`modern dev` start a development server,watch file change,default support React Fast Refresh:
|
21
21
|
|
22
22
|
```bash
|
23
23
|
App running at:
|
@@ -8,32 +8,32 @@ Usage: modern inspect [options]
|
|
8
8
|
inspect internal webpack config
|
9
9
|
|
10
10
|
Options:
|
11
|
-
--env <env>
|
12
|
-
--output <output>
|
13
|
-
--no-console
|
14
|
-
--verbose
|
15
|
-
-c --config <config>
|
16
|
-
-h, --help
|
11
|
+
--env <env> view the configuration in the target environment (default: "development")
|
12
|
+
--output <output> Specify the path to output in the dist (default: "/")
|
13
|
+
--no-console Do not output the full result in shell
|
14
|
+
--verbose Show the full function in the result
|
15
|
+
-c --config <config> configuration file path, which can be a relative path or an absolute path
|
16
|
+
-h, --help show command help
|
17
17
|
```
|
18
18
|
|
19
|
-
`modern inspect`
|
19
|
+
`modern inspect` command used to view the full webpack configuration of the project.
|
20
20
|
|
21
|
-
|
21
|
+
Executing the command `npx modern inspect` in the project will output the webpack configuration on the shell, and will also generate a `webpack.client.inspect.js` file in the project's `dist` directory, which developers can open and view manually.
|
22
22
|
|
23
|
-
##
|
23
|
+
## Configuration Env
|
24
24
|
|
25
|
-
|
25
|
+
By default, the webpack configuration of the development environment is output. And the `env` option can be used to output the configuration of the production environment:
|
26
26
|
|
27
27
|
```bash
|
28
28
|
modern inspect --env production
|
29
29
|
```
|
30
30
|
|
31
|
-
##
|
31
|
+
## Configuration Type
|
32
32
|
|
33
|
-
### SSR
|
33
|
+
### SSR Configuration
|
34
34
|
|
35
|
-
|
35
|
+
If the project has SSR enable, an additional `webpack.ssr.inspect.js` file will be generated in the `dist/`, corresponding to the webpack configuration at SSR build time.
|
36
36
|
|
37
|
-
### Modern
|
37
|
+
### Modern Configuration
|
38
38
|
|
39
|
-
|
39
|
+
if project enable [enableModernMode](/docs/configure/app/output/enable-modern-mode), an additional `webpack.modern.inspect.js` file will be generated in the `dist/`corresponding to the webpack configuration at modern web build.
|
@@ -13,9 +13,9 @@ Options:
|
|
13
13
|
-h, --help display help for command
|
14
14
|
```
|
15
15
|
|
16
|
-
|
16
|
+
Run ESLint to check the syntax of the code. Normally, only the part of the code modified by this commit needs to be checked by `lint-staged` during the `git commit` phase.
|
17
17
|
|
18
|
-
* `--no-fix`
|
18
|
+
* `--no-fix` close auto fix by lint.
|
19
19
|
|
20
20
|
import CommandTip from '@site-docs/components/command-tip.md'
|
21
21
|
|
@@ -5,27 +5,27 @@ sidebar_position: 2
|
|
5
5
|
```bash
|
6
6
|
Usage: modern new [options]
|
7
7
|
|
8
|
-
|
8
|
+
Execution Generator in App
|
9
9
|
|
10
10
|
Options:
|
11
|
-
-d, --debug
|
12
|
-
-c, --config <config>
|
13
|
-
--dist-tag <tag>
|
14
|
-
--registry
|
15
|
-
-h, --help
|
11
|
+
-d, --debug using debug mode to log something (default: false)
|
12
|
+
-c, --config <config> set default generator config(json string)
|
13
|
+
--dist-tag <tag> use specified tag version for its generator
|
14
|
+
--registry set npm registry url to run npm command
|
15
|
+
-h, --help show command help
|
16
16
|
```
|
17
17
|
|
18
|
-
`modern new`
|
18
|
+
The `modern new` command is used to enable features to an existing project.
|
19
19
|
|
20
|
-
|
20
|
+
For example, add application entry, enable some optional features such as Tailwind CSS, micro frontend, etc.
|
21
21
|
|
22
22
|
import CommandTip from '@site-docs/components/command-tip.md'
|
23
23
|
|
24
24
|
<CommandTip />
|
25
25
|
|
26
|
-
###
|
26
|
+
### Add Entry
|
27
27
|
|
28
|
-
|
28
|
+
In the project, execute the `new` command to add entries as follows:
|
29
29
|
|
30
30
|
```bash
|
31
31
|
$ npx modern new
|
@@ -35,9 +35,9 @@ $ npx modern new
|
|
35
35
|
? 是否需要调整默认配置? 否
|
36
36
|
```
|
37
37
|
|
38
|
-
###
|
38
|
+
### Enable Features
|
39
39
|
|
40
|
-
|
40
|
+
In the project, execute the `new` command to enable features as follows:
|
41
41
|
|
42
42
|
```bash
|
43
43
|
$ npx modern new
|
@@ -52,8 +52,8 @@ $ npx modern new
|
|
52
52
|
启用「Visual Testing (Storybook)」模式
|
53
53
|
```
|
54
54
|
|
55
|
-
:::caution
|
56
|
-
`--config`
|
55
|
+
:::caution
|
56
|
+
The `--config` parameter needs to use a JSON string.
|
57
57
|
|
58
|
-
pnpm
|
58
|
+
pnpm does not support the use of JSON strings as parameter values currently. Use `npm new` to turn on.【[Relate Issue](https://github.com/pnpm/pnpm/issues/3876)】
|
59
59
|
:::
|
@@ -8,14 +8,14 @@ Usage: modern start [options]
|
|
8
8
|
start server
|
9
9
|
|
10
10
|
Options:
|
11
|
-
-c --config <config>
|
12
|
-
-h, --help
|
13
|
-
--api-only
|
11
|
+
-c --config <config> configuration file path, which can be a relative path or an absolute path
|
12
|
+
-h, --help show command help
|
13
|
+
--api-only only start API service
|
14
14
|
```
|
15
15
|
|
16
|
-
|
16
|
+
Usually use the `modern start` command to enable project start in the production environment, and you need to execute the [`build'](/docs/apis/app/commands/build) command in advance to build the product.
|
17
17
|
|
18
|
-
|
18
|
+
By default, the project will start in `localhost:8080`, you can modify the Server port number with `server.port`:
|
19
19
|
|
20
20
|
```js
|
21
21
|
export default defineConfig({
|
@@ -6,14 +6,14 @@ sidebar_position: 3
|
|
6
6
|
Usage: modern test [options]
|
7
7
|
|
8
8
|
Options:
|
9
|
-
-h, --help
|
9
|
+
-h, --help show command help
|
10
10
|
```
|
11
11
|
|
12
|
-
:::caution
|
13
|
-
`modern test`
|
12
|
+
:::caution
|
13
|
+
`modern test` command need to execute the `new` command in advance to enable the `unit test/integration test`.
|
14
14
|
:::
|
15
15
|
|
16
|
-
`modern test`
|
16
|
+
`modern test` command will automatically run the test cases, the effect is as follows:
|
17
17
|
|
18
18
|
```bash
|
19
19
|
$ npx modern test
|
@@ -28,7 +28,7 @@ Time: 0.994 s, estimated 1 s
|
|
28
28
|
```
|
29
29
|
|
30
30
|
:::info
|
31
|
-
|
31
|
+
files match `*.test.(js|ts)` in `api/` or `src/` will be recognized as test cases by default。
|
32
32
|
:::
|
33
33
|
|
34
34
|
import CommandTip from '@site-docs/components/command-tip.md'
|
@@ -5,19 +5,17 @@ sidebar_position: 8
|
|
5
5
|
```
|
6
6
|
Usage: modern upgrade [options]
|
7
7
|
|
8
|
-
|
8
|
+
upgrade Modern.js to latest version.
|
9
9
|
|
10
10
|
Options:
|
11
|
-
--registry <registry>
|
12
|
-
-d,--debug
|
13
|
-
--cwd <cwd>
|
14
|
-
-h, --help
|
11
|
+
--registry <registry> specify npm registry (default: "")
|
12
|
+
-d,--debug using debug mode to log something (default: false)
|
13
|
+
--cwd <cwd> app directory (default: "")
|
14
|
+
-h, --help show command help
|
15
15
|
```
|
16
16
|
|
17
|
-
`modern upgrade`
|
18
|
-
|
19
|
-
在项目根目录下执行命令 `npx modern upgrade`,会默认将当前执行命令项目的 `package.json` 中的 Modern.js 相关依赖更新至最新版本。
|
17
|
+
Execute the command `npx modern upgrade` in the project, by default, dependencies in the `package.json` are updated to the latest version.
|
20
18
|
|
21
19
|
:::info
|
22
|
-
|
20
|
+
the command is available in `@modern-js/app-tools` version >= 1.17.0, previous versions can be upgraded with `npx @modern-js/upgrade`.
|
23
21
|
:::
|
@@ -3,77 +3,52 @@ title: lambda/*.[tj]s
|
|
3
3
|
sidebar_position: 1
|
4
4
|
---
|
5
5
|
|
6
|
-
|
6
|
+
Declaring API routing in BFF framework mode. Except [some files](/docs/apis/app/hooks/api/framework/lambda#allow-list),files in `api/` are registered as routes.
|
7
7
|
|
8
8
|
:::info
|
9
|
-
|
9
|
+
use `api/` need execute new command to enable the 「BFF」 feature.
|
10
|
+
:::
|
10
11
|
|
11
|
-
|
12
|
+
:::tip
|
13
|
+
this file supports the use `js` or `ts`, but the functions must be exported using the ESM syntax.
|
12
14
|
:::
|
13
15
|
|
14
|
-
##
|
16
|
+
## Routing Rule
|
15
17
|
|
16
|
-
###
|
18
|
+
### Default Route
|
17
19
|
|
18
|
-
|
20
|
+
The files named `index` will be upper level routing:
|
19
21
|
|
20
22
|
* `api/lambda/index.ts` -> `$BASENAME/`
|
21
23
|
* `api/lambda/user/index.ts` -> `$BASENAME/user`
|
22
24
|
|
23
|
-
###
|
25
|
+
### Multi Level Route
|
24
26
|
|
25
|
-
|
27
|
+
The routing system also supports parsing multiple levels of files. and if you create a folder, the files will still be automatically parsed in the same way.
|
26
28
|
|
27
29
|
* `api/lambda/hello.ts` -> `$BASENAME/hello`
|
28
30
|
* `api/lambda/user/list.ts` -> `$BASENAME/user/list`
|
29
31
|
|
30
|
-
###
|
32
|
+
### Dynamic Route
|
31
33
|
|
32
|
-
|
34
|
+
Dynamic named routing parameters can be supported by creating folders or files with `[xxx]`.
|
33
35
|
|
34
36
|
* `api/lambda/user/[username]/info.ts` -> `$BASENAME/user/:username/info`
|
35
37
|
* `api/lambda/user/[username]/delete.ts` -> `$BASENAME/user/:username/delete`
|
36
38
|
* `api/lambda/article/[id]/info.ts` -> `$BASENAME/article/:id/info`
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
### 白名单
|
41
|
-
|
42
|
-
默认 `api` 目录下所有文件都会当作 BFF 函数文件去解析,但同样我们也设置了白名单,这些文件不被被解析:
|
43
|
-
|
44
|
-
* 命名以 `_` 开头的文件。例如:`_utils.ts`。
|
45
|
-
* 命名以 `_` 开头的文件夹下所有文件。例如:`_utils/index.ts`、`_utils/cp.ts`。
|
46
|
-
* 测试文件。例如:`foo.test.ts`。
|
47
|
-
* TypeScript 类型文件。例如:`hello.d.ts`。
|
48
|
-
* `node_module` 下的文件。
|
49
|
-
|
50
|
-
## 函数定义
|
51
|
-
|
52
|
-
除了上面的路由规则之外,代码中函数定义与导出也有相应的约定。
|
40
|
+
the `$BASENAME` can be configured in `modern.config.js`,the default value is `/api`。
|
53
41
|
|
54
|
-
|
42
|
+
### Allow List
|
55
43
|
|
56
|
-
|
44
|
+
By default, all files in the `api/` will be parsed as BFF function. but we also set a allow list, and these files will not be parsed:
|
57
45
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
};
|
64
|
-
};
|
65
|
-
```
|
46
|
+
* file name start with `_`, for example: `_utils.ts`.
|
47
|
+
* files in directory that name start with `_`, for example:`_utils/index.ts`、`_utils/cp.ts`.
|
48
|
+
* test files, for example:`foo.test.ts`.
|
49
|
+
* TypeScript define files, for example:`hello.d.ts`.
|
50
|
+
* files in `node_module`.
|
66
51
|
|
67
|
-
|
52
|
+
## Define Function
|
68
53
|
|
69
|
-
|
70
|
-
|
71
|
-
名字是大小不敏感的,就是说,如果是 `GET`,写成 `get`、`Get`、`GEt`、`GET`,都可以准确识别。而默认导出,即 `export default xxx` 则会被映射为 `Get`。
|
72
|
-
|
73
|
-
因为 `delete` 是 `javascript` 中的关键字,可以使用 `del` 或者 `DELETE` 代替。
|
74
|
-
|
75
|
-
可以在一个文件中定义多个不同 Method 的函数,但如果定义多个相同 Method 的函数,则只有第一个会生效。
|
76
|
-
|
77
|
-
:::info
|
78
|
-
需要注意的是,定义的函数都应该是异步的,这个与函数调用时类型有关,这个后面会提到。
|
79
|
-
:::
|
54
|
+
the same as [Define Function](/docs/apis/app/hooks/api/functions/api#define-function).
|
@@ -3,48 +3,76 @@ title: "**/*.[tj]s"
|
|
3
3
|
sidebar_position: 1
|
4
4
|
---
|
5
5
|
|
6
|
-
|
6
|
+
Declaring API routing in BFF function mode. Except [some files](/docs/apis/app/hooks/api/functions/api#allow-list),files in `api/` are registered as routes.
|
7
7
|
|
8
8
|
:::info
|
9
|
-
|
9
|
+
use `api/` need execute new command to enable the 「BFF」 feature.
|
10
|
+
:::
|
10
11
|
|
11
|
-
|
12
|
+
:::tip
|
13
|
+
this file supports the use `js` or `ts`, but the functions must be exported using the ESM syntax.
|
12
14
|
:::
|
13
15
|
|
14
|
-
##
|
16
|
+
## Routing Rule
|
15
17
|
|
16
|
-
###
|
18
|
+
### Default Route
|
17
19
|
|
18
|
-
|
20
|
+
The files named `index` will be upper level routing:
|
19
21
|
|
20
22
|
* `api/index.ts` -> `$BASENAME/`
|
21
23
|
* `api/user/index.ts` -> `$BASENAME/user`
|
22
24
|
|
23
|
-
###
|
25
|
+
### Multi Level Route
|
24
26
|
|
25
|
-
|
27
|
+
The routing system also supports parsing multiple levels of files. and if you create a folder, the files will still be automatically parsed in the same way.
|
26
28
|
|
27
29
|
* `api/hello.ts` -> `$BASENAME/hello`
|
28
30
|
* `api/user/list.ts` -> `$BASENAME/user/list`
|
29
31
|
|
30
|
-
###
|
32
|
+
### Dynamic Route
|
31
33
|
|
32
|
-
|
34
|
+
Dynamic named routing parameters can be supported by creating folders or files with `[xxx]`.
|
33
35
|
|
34
36
|
* `api/user/[username]/info.ts` -> `$BASENAME/user/:username/info`
|
35
37
|
* `api/user/[username]/delete.ts` -> `$BASENAME/user/:username/delete`
|
36
38
|
* `api/article/[id]/info.ts` -> `$BASENAME/article/:id/info`
|
37
39
|
|
38
|
-
|
40
|
+
the `$BASENAME` can be configured in `modern.config.js`,the default value is `/api`。
|
41
|
+
|
42
|
+
### Allow List
|
43
|
+
|
44
|
+
By default, all files in the `api/` will be parsed as BFF function. but we also set a allow list, and these files will not be parsed:
|
45
|
+
|
46
|
+
* file name start with `_`, for example: `_utils.ts`.
|
47
|
+
* files in directory that name start with `_`, for example:`_utils/index.ts`、`_utils/cp.ts`.
|
48
|
+
* test files, for example:`foo.test.ts`.
|
49
|
+
* TypeScript define files, for example:`hello.d.ts`.
|
50
|
+
* files in `node_module`.
|
51
|
+
|
52
|
+
## Define Function
|
39
53
|
|
40
|
-
|
54
|
+
In addition to the above routing rules, the function definition and export in the code also have conventions.
|
41
55
|
|
42
|
-
|
56
|
+
function need named exports,and the name of the exported function is the HTTP Method:
|
43
57
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
58
|
+
```ts
|
59
|
+
export const get = async () => {
|
60
|
+
return {
|
61
|
+
name: 'Modern.js',
|
62
|
+
desc: 'Modern web Solutions',
|
63
|
+
};
|
64
|
+
};
|
65
|
+
```
|
49
66
|
|
67
|
+
Export the function like above will generate a `POST` interface.
|
50
68
|
|
69
|
+
App support 9 Method definitions: `GET`、`POST`、`PUT`、`DELETE`、`CONNECT`、`TRACE`、`PATCH`、`OPTION`、`HEAD`. so App can use these name as function export nane.
|
70
|
+
|
71
|
+
The name is insensitive, whaterver `get`、`Get`、`GEt`、`GET`, can be accurately identified. And default export, `export default xxx` will be `Get` method.
|
72
|
+
|
73
|
+
because `delete` is a keyword in JavaScript, use `del` or `DELETE` instead.
|
74
|
+
|
75
|
+
Multiple functions of different Methods can be defined in one file, but if multiple functions of the same Method are defined, only the first can work.
|
76
|
+
|
77
|
+
:::info
|
78
|
+
It should be noted that the defined functions should be asynchronous, which is related to the type when the function is called.
|
@@ -3,10 +3,10 @@ title: _app.[tj]s
|
|
3
3
|
sidebar_position: 3
|
4
4
|
---
|
5
5
|
|
6
|
-
|
6
|
+
in BFF function mode,this file can add middleware before [BFF 函数](/docs/apis/app/hooks/api/functions/api).
|
7
7
|
|
8
8
|
:::note
|
9
|
-
|
9
|
+
For detail, see [hook](/docs/apis/app/runtime/bff/hook)
|
10
10
|
:::
|
11
11
|
|
12
12
|
|
@@ -3,8 +3,8 @@ title: "**/_*.[tj]s, _*/**"
|
|
3
3
|
sidebar_position: 2
|
4
4
|
---
|
5
5
|
|
6
|
-
|
6
|
+
under BFF function mode, these files are not registered as routes.
|
7
|
+
|
8
|
+
Any files that not routes, but required in the project can be named in this way.
|
9
|
+
|
7
10
|
|
8
|
-
:::info
|
9
|
-
使用 `api` 目录的开启 BFF 功能,需要在项目下执行 new 命令启用「BFF」功能。
|
10
|
-
:::
|
@@ -3,10 +3,8 @@ title: test.[tj]s
|
|
3
3
|
sidebar_position: 2
|
4
4
|
---
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
应用项目支持在项目 API 目录下创建后缀为 `.test.[tj]sx?` 文件进行编写测试用例。
|
6
|
+
App's BFF test file,support for writing test cases in the `api/` directory which file with suffix `.test.[tj]s`.
|
9
7
|
|
10
8
|
:::info
|
11
|
-
|
9
|
+
To use unit test and integration test, you need to execute the `new` command in advance to enable the `unit test/integration test`.
|
12
10
|
:::
|
@@ -3,8 +3,6 @@ title: html/
|
|
3
3
|
sidebar_position: 1
|
4
4
|
---
|
5
5
|
|
6
|
-
|
6
|
+
The `config/html` directory allows you to inject custom html snippets in different places in the default html template.
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
具体使用方式请参考: [自定义 HTML](/docs/guides/basic-features/html)
|
8
|
+
For detail, see [HTML](/docs/guides/basic-features/html).
|
@@ -3,15 +3,13 @@ title: icon.png
|
|
3
3
|
sidebar_position: 2
|
4
4
|
---
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
项目根目录下 `config/icon.png` 时,可以在构建时在 html 页面注入 app icon 信息, 如下:
|
6
|
+
When `config/icon.png` exist, it can inject app icon information into the html page at build time:
|
9
7
|
|
10
8
|
```
|
11
|
-
|
9
|
+
.config
|
12
10
|
└── icon.png
|
13
11
|
```
|
14
12
|
|
15
|
-
|
13
|
+
the app icon `link` meta will be injected into the html, as follows:
|
16
14
|
|
17
15
|

|
@@ -3,10 +3,4 @@ title: mock/
|
|
3
3
|
sidebar_position: 5
|
4
4
|
---
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
项目根目录下存在 `config/mock/index.js` 时,在本地开发调试环节自动启用快速 Mock 数据的功能。
|
9
|
-
|
10
|
-
:::caution 注意
|
11
|
-
为避免 Mock API 不生效, 请注意不要与配置 [tools.devServer.proxy](/docs/configure/app/tools/dev-server) 的 API 有冲突。
|
12
|
-
:::
|
6
|
+
when `config/mock/index.js` exist,Modernjs auto start the Mock service in the development.
|