@modern-js/main-doc 2.12.0 → 2.13.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +21 -0
- package/docs/en/apis/app/commands.mdx +1 -1
- package/docs/en/apis/app/hooks/api/framework/lambda.mdx +2 -2
- package/docs/en/apis/app/hooks/api/functions/api.mdx +3 -3
- package/docs/en/apis/app/hooks/api/functions/app.mdx +1 -1
- package/docs/en/apis/app/hooks/api/test.mdx +2 -1
- package/docs/en/apis/app/hooks/config/mock.mdx +1 -1
- package/docs/en/apis/app/hooks/config/upload.mdx +1 -1
- package/docs/en/apis/app/hooks/server/test.mdx +1 -1
- package/docs/en/apis/app/hooks/src/app.mdx +1 -1
- package/docs/en/apis/app/hooks/src/pages.mdx +1 -1
- package/docs/en/apis/app/runtime/app/define-config.mdx +1 -1
- package/docs/en/apis/app/runtime/core/bootstrap.mdx +2 -2
- package/docs/en/apis/app/runtime/core/use-loader.mdx +6 -2
- package/docs/en/apis/app/runtime/model/auto-actions.mdx +6 -6
- package/docs/en/apis/app/runtime/model/connect.mdx +2 -1
- package/docs/en/apis/app/runtime/model/create-app.mdx +1 -1
- package/docs/en/apis/app/runtime/model/handle-effect.mdx +3 -3
- package/docs/en/apis/app/runtime/model/model_.mdx +2 -2
- package/docs/en/apis/app/runtime/model/use-model.mdx +2 -2
- package/docs/en/apis/app/runtime/model/use-static-model.mdx +2 -2
- package/docs/en/apis/app/runtime/model/use-store.mdx +1 -1
- package/docs/en/apis/app/runtime/router/router.mdx +1 -0
- package/docs/en/apis/app/runtime/ssr/pre-render.mdx +2 -2
- package/docs/en/apis/app/runtime/testing/render.mdx +1 -1
- package/docs/en/components/enable-bff.mdx +2 -2
- package/docs/en/configure/app/html/script-loading.mdx +13 -0
- package/docs/en/configure/app/output/ssg.mdx +1 -1
- package/docs/en/configure/app/plugins.mdx +3 -3
- package/docs/en/configure/app/source/disable-entry-dirs.mdx +1 -1
- package/docs/en/configure/app/tools/swc.mdx +1 -1
- package/docs/en/configure/app/usage.mdx +65 -23
- package/docs/en/guides/advanced-features/bff/function.mdx +3 -3
- package/docs/en/guides/advanced-features/code-split.mdx +2 -2
- package/docs/en/guides/advanced-features/eslint.mdx +1 -1
- package/docs/en/guides/advanced-features/ssg.mdx +2 -2
- package/docs/en/guides/advanced-features/ssr.mdx +45 -8
- package/docs/en/guides/basic-features/alias.mdx +1 -1
- package/docs/en/guides/basic-features/env-vars.mdx +5 -5
- package/docs/en/guides/basic-features/html.mdx +0 -4
- package/docs/en/guides/basic-features/routes.mdx +48 -28
- package/docs/en/guides/concept/entries.mdx +3 -3
- package/docs/en/guides/get-started/introduction.mdx +21 -1
- package/docs/en/guides/get-started/quick-start.mdx +6 -23
- package/docs/en/guides/get-started/upgrade.mdx +7 -7
- package/docs/en/guides/topic-detail/framework-plugin/hook.mdx +1 -1
- package/docs/en/guides/topic-detail/generator/codesmith/api/json.mdx +3 -3
- package/docs/en/guides/topic-detail/generator/config/app.mdx +1 -1
- package/docs/en/guides/topic-detail/generator/config/monorepo.mdx +1 -1
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addHelper.mdx +1 -1
- package/docs/en/guides/topic-detail/model/manage-effects.mdx +2 -1
- package/docs/en/guides/topic-detail/model/model-communicate.mdx +1 -1
- package/docs/en/tutorials/foundations/introduction.mdx +0 -2
- package/docs/zh/apis/app/hooks/src/pages.mdx +1 -1
- package/docs/zh/apis/app/runtime/core/use-loader.mdx +4 -0
- package/docs/zh/apis/app/runtime/model/handle-effect.mdx +2 -1
- package/docs/zh/apis/app/runtime/model/model_.mdx +4 -2
- package/docs/zh/blog/updates/2022-0708-updates.md +1 -2
- package/docs/zh/components/enable-bff.mdx +2 -2
- package/docs/zh/configure/app/html/script-loading.mdx +13 -0
- package/docs/zh/configure/app/source/disable-entry-dirs.mdx +2 -2
- package/docs/zh/configure/app/usage.mdx +66 -24
- package/docs/zh/guides/advanced-features/ssr.mdx +74 -36
- package/docs/zh/guides/basic-features/html.mdx +0 -4
- package/docs/zh/guides/basic-features/routes.mdx +64 -24
- package/docs/zh/guides/concept/entries.mdx +4 -4
- package/docs/zh/guides/get-started/introduction.mdx +21 -1
- package/docs/zh/guides/get-started/upgrade.mdx +3 -3
- package/docs/zh/guides/topic-detail/changesets/release.mdx +2 -2
- package/package.json +5 -5
- package/src/components/SolutionCards/index.module.scss +62 -0
- package/src/components/SolutionCards/index.tsx +26 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
# @modern-js/main-doc
|
2
2
|
|
3
|
+
## 2.13.1
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- @modern-js/builder-doc@2.13.1
|
8
|
+
|
9
|
+
## 2.13.0
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- e91ec97: feat(app-tools): export mergeConfig function
|
14
|
+
|
15
|
+
feat(app-tools): 导出 mergeConfig 函数
|
16
|
+
|
17
|
+
- 42700c1: chore: improve ssr docs, add more use case for node/web code split
|
18
|
+
chore: 优化 ssr 文档,为 node/web 代码分割添加更多使用场景
|
19
|
+
- Updated dependencies [1feacdc]
|
20
|
+
- Updated dependencies [348306d]
|
21
|
+
- Updated dependencies [42700c1]
|
22
|
+
- @modern-js/builder-doc@2.13.0
|
23
|
+
|
3
24
|
## 2.12.0
|
4
25
|
|
5
26
|
### Patch Changes
|
@@ -84,7 +84,7 @@ Options:
|
|
84
84
|
|
85
85
|
### Analyze Bundle
|
86
86
|
|
87
|
-
execute `npx modern build --analyze` command
|
87
|
+
execute `npx modern build --analyze` command, can produce an HTML file that analyzes the volume of the bundle while packaging the production code:
|
88
88
|
|
89
89
|
```
|
90
90
|
Bundle Analyzer saved report to /example/dist/report.html
|
@@ -4,7 +4,7 @@ sidebar_position: 1
|
|
4
4
|
---
|
5
5
|
# lambda/*.[tj]s
|
6
6
|
|
7
|
-
Declaring API routing in BFF framework mode. Except [some files](/apis/app/hooks/api/framework/lambda#allow-list)
|
7
|
+
Declaring API routing in BFF framework mode. Except [some files](/apis/app/hooks/api/framework/lambda#allow-list), files in `api/` are registered as routes.
|
8
8
|
|
9
9
|
:::info
|
10
10
|
use `api/` need execute new command to enable the 「BFF」 feature.
|
@@ -40,7 +40,7 @@ Dynamic named routing parameters can be supported by creating folders or files w
|
|
40
40
|
- `api/lambda/user/[username]/delete.ts` -> `$BASENAME/user/:username/delete`
|
41
41
|
- `api/lambda/article/[id]/info.ts` -> `$BASENAME/article/:id/info`
|
42
42
|
|
43
|
-
the `$BASENAME` can be configured in `modern.config.js
|
43
|
+
the `$BASENAME` can be configured in `modern.config.js`, the default value is `/api`.
|
44
44
|
|
45
45
|
### Allow List
|
46
46
|
|
@@ -4,7 +4,7 @@ sidebar_position: 1
|
|
4
4
|
---
|
5
5
|
# **/*.[tj]s
|
6
6
|
|
7
|
-
Declaring API routing in BFF function mode. Except [some files](/apis/app/hooks/api/functions/api#allow-list)
|
7
|
+
Declaring API routing in BFF function mode. Except [some files](/apis/app/hooks/api/functions/api#allow-list), files in `api/` are registered as routes.
|
8
8
|
|
9
9
|
:::info
|
10
10
|
use `api/` need execute new command to enable the 「BFF」 feature.
|
@@ -40,7 +40,7 @@ Dynamic named routing parameters can be supported by creating folders or files w
|
|
40
40
|
- `api/user/[username]/delete.ts` -> `$BASENAME/user/:username/delete`
|
41
41
|
- `api/article/[id]/info.ts` -> `$BASENAME/article/:id/info`
|
42
42
|
|
43
|
-
the `$BASENAME` can be configured in `modern.config.js
|
43
|
+
the `$BASENAME` can be configured in `modern.config.js`, the default value is `/api`.
|
44
44
|
|
45
45
|
### Allow List
|
46
46
|
|
@@ -56,7 +56,7 @@ By default, all files in the `api/` will be parsed as BFF function. but we also
|
|
56
56
|
|
57
57
|
In addition to the above routing rules, the function definition and export in the code also have conventions.
|
58
58
|
|
59
|
-
function need named exports
|
59
|
+
function need named exports, and the name of the exported function is the HTTP Method:
|
60
60
|
|
61
61
|
```ts
|
62
62
|
export const get = async () => {
|
@@ -4,7 +4,7 @@ sidebar_position: 3
|
|
4
4
|
---
|
5
5
|
# _app.[tj]s
|
6
6
|
|
7
|
-
in BFF function mode
|
7
|
+
in BFF function mode, this file can add middleware before [BFF 函数](/apis/app/hooks/api/functions/api).
|
8
8
|
|
9
9
|
:::note
|
10
10
|
For detail, see [hook](/apis/app/runtime/bff/hook)
|
@@ -2,9 +2,10 @@
|
|
2
2
|
title: test.[tj]s
|
3
3
|
sidebar_position: 2
|
4
4
|
---
|
5
|
+
|
5
6
|
# test.[tj]s
|
6
7
|
|
7
|
-
App's BFF test file
|
8
|
+
App's BFF test file, support for writing test cases in the `api/` directory which file with suffix `.test.[tj]s`.
|
8
9
|
|
9
10
|
:::info
|
10
11
|
To use unit test and integration test, you need to execute the `new` command in advance to enable the `unit test/integration test`.
|
@@ -42,7 +42,7 @@ Whether in [custom HTML](/guides/basic-features/html), or in any HTML file under
|
|
42
42
|
<script src="/upload/index.js"></script>
|
43
43
|
```
|
44
44
|
|
45
|
-
if [`output.assetPrefix`](/configure/app/output/asset-prefix) is configured
|
45
|
+
if [`output.assetPrefix`](/configure/app/output/asset-prefix) is configured, add this prefix directly using template syntax:
|
46
46
|
|
47
47
|
```html
|
48
48
|
<script src="<%=assetPrefix %>/upload/index.js"></script>
|
@@ -4,7 +4,7 @@ sidebar_position: 2
|
|
4
4
|
---
|
5
5
|
# test.[tj]s
|
6
6
|
|
7
|
-
App's Web Server test file
|
7
|
+
App's Web Server test file, support for writing test cases in the `server/` directory which file with suffix `.test.[tj]s`.
|
8
8
|
|
9
9
|
:::info
|
10
10
|
To use unit test and integration test, you need to execute the `new` command in advance to enable the `unit test/integration test`.
|
@@ -49,6 +49,6 @@ export default AppWrapper;
|
|
49
49
|
```
|
50
50
|
|
51
51
|
:::note
|
52
|
-
In multi-entry App
|
52
|
+
In multi-entry App, each entry can have a `App.[jt]sx`, for detail, see [Entry](/guides/concept/entries).
|
53
53
|
|
54
54
|
:::
|
@@ -84,7 +84,7 @@ When the entire App needs a global `layout`, it can be achieved through `pages/_
|
|
84
84
|
import React from 'react';
|
85
85
|
import UserLayout from 'xxxx';
|
86
86
|
|
87
|
-
export
|
87
|
+
export const App = ({Component, ...pageProps}:{ Component: React.ComponentType}) => {
|
88
88
|
return (
|
89
89
|
<UserLayout>
|
90
90
|
<Component {...pageProps} />
|
@@ -13,7 +13,7 @@ import { defineConfig } from '@modern-js/runtime';
|
|
13
13
|
|
14
14
|
Runtime configurations can usually be configured under the `runtime` of the `modern.config.js`, such as the [router](/configure/app/runtime/router) configuration.
|
15
15
|
|
16
|
-
The configuration in `modern.config.js` is determined at build time
|
16
|
+
The configuration in `modern.config.js` is determined at build time, If some configuration parameters are obtained at runtime, or if the configuration parameters are from a module (such as a component), then need use `defineConfig` API configuration on runtime.
|
17
17
|
|
18
18
|
:::info
|
19
19
|
`@modern-js/app-tools` has the same name API, Used to provide **TS type for configuration**, please distinguish them.
|
@@ -33,7 +33,7 @@ type BootStrap<T = unknown> = (
|
|
33
33
|
### Input
|
34
34
|
|
35
35
|
- `AppComponent`: reactElement instance created by [`createApp`](./create-app).
|
36
|
-
- `rootId`: DOM root element id to mount
|
36
|
+
- `rootId`: DOM root element id to mount, like `"root"`.
|
37
37
|
- `root`: ReactDOM.create the return value, which is used in the scenario where the root needs to destroy the component outside the bootstrap function.
|
38
38
|
- `ReactDOM`: ReactDOM object for distinguishing between React 18 and React 17 APIs.
|
39
39
|
|
@@ -56,7 +56,7 @@ bootstrap(WrappedApp, 'root', undefined, ReactDOM);
|
|
56
56
|
```
|
57
57
|
|
58
58
|
:::info
|
59
|
-
since `@modern-js/runtime/plugins` is a alias
|
59
|
+
since `@modern-js/runtime/plugins` is a alias, when used in a ts project, its type needs to be declared, Just add the following type declarations to `src/modern-app-env.d.ts`:
|
60
60
|
|
61
61
|
```ts
|
62
62
|
declare module '@modern-js/runtime/plugins';
|
@@ -3,7 +3,11 @@ title: useLoader
|
|
3
3
|
---
|
4
4
|
# useLoader
|
5
5
|
|
6
|
-
Isomorphic API
|
6
|
+
Isomorphic API, usually used to make asynchronous requests. When SSR, the server level uses `useLoader` to prefetch the data, and the browser side also reuses this part of the data.
|
7
|
+
|
8
|
+
:::tip
|
9
|
+
When using Rspack as the bundler, the useLoader API is not currently supported.
|
10
|
+
:::
|
7
11
|
|
8
12
|
## Usage
|
9
13
|
|
@@ -47,7 +51,7 @@ function useLoader(loaderFn: LoaderFn, options: Options): ReturnData;
|
|
47
51
|
- `onError`: error callback.
|
48
52
|
- `initialData`: the initial data before the first execution,.
|
49
53
|
- `skip`: when the value is `true`, the function does not execute.
|
50
|
-
- `params`: when the result of the `params` serialization changes
|
54
|
+
- `params`: when the result of the `params` serialization changes, the function is re-executed. `params` is also passed in as the second argument of the function.
|
51
55
|
- `static`: when the value is `true`, `useLoader` is used for [SSG](/guides/advanced-features/ssg).
|
52
56
|
|
53
57
|
### Return Value
|
@@ -8,7 +8,7 @@ import ReduckTip from "@site-docs-en/components/reduck-tip"
|
|
8
8
|
|
9
9
|
<ReduckTip />
|
10
10
|
|
11
|
-
Reduck can automatically generate Actions according to the type of State
|
11
|
+
Reduck can automatically generate Actions according to the type of State, for easy to modify State.
|
12
12
|
|
13
13
|
:::tip
|
14
14
|
can use [`runtime.state.autoActions`](/configure/app/runtime/state#autoactions) close auto actions feature.
|
@@ -19,7 +19,7 @@ can use [`runtime.state.autoActions`](/configure/app/runtime/state#autoactions)
|
|
19
19
|
|
20
20
|
### Basic Data Type
|
21
21
|
|
22
|
-
State type in `string`、`number`、`boolean`、`null
|
22
|
+
State type in `string`、`number`、`boolean`、`null`, generate `setState` Action.
|
23
23
|
|
24
24
|
```tsx title="example"
|
25
25
|
const fooModel = model('foo').define({
|
@@ -48,7 +48,7 @@ function App() {
|
|
48
48
|
|
49
49
|
### Array
|
50
50
|
|
51
|
-
State type is Array
|
51
|
+
State type is Array, generate the following Actions:
|
52
52
|
|
53
53
|
- `push`: adds one or more elements to the end of the array.
|
54
54
|
- `pop`: removes the last element from the array.
|
@@ -57,9 +57,9 @@ State type is Array,generate the following Actions:
|
|
57
57
|
- usage: `arr.unshift(element1, ..., elementN)`
|
58
58
|
- `elementN`: the element or elements to add to the beginning of the array.
|
59
59
|
- `filter`: filter element.
|
60
|
-
{/*
|
60
|
+
{/* 语义与原生方法不同, 待修改 API */}
|
61
61
|
- `concat`: concat array.
|
62
|
-
{/*
|
62
|
+
{/* 语义与原生方法不同, 待修改 API */}
|
63
63
|
- `splice`: modify the array by deleting or replacing existing elements or adding new elements in place, and return the modified array(Note that it is different from the native `splice` return value).
|
64
64
|
- usage: `splice(start[, deleteCount[, item1[, item2[, ...]]]])`
|
65
65
|
- `start`: specifies the start position of the modification(counting from 0).
|
@@ -93,7 +93,7 @@ function App() {
|
|
93
93
|
|
94
94
|
### PlainObject
|
95
95
|
|
96
|
-
State type is PlainObject
|
96
|
+
State type is PlainObject, base on the names contained in State, generate `set${key}`(Camel-Case) Actions.
|
97
97
|
|
98
98
|
```tsx title="example"
|
99
99
|
const fooModel = model('foo').define({
|
@@ -30,7 +30,7 @@ function createApp(config: AppConfig): object;
|
|
30
30
|
|
31
31
|
- `config`
|
32
32
|
- `StoreConfig`: the same as [`createStore`](./create-store.mdx) params.
|
33
|
-
- `devTools`: the default value is `true`. when it is an object type
|
33
|
+
- `devTools`: the default value is `true`. when it is an object type, configuring [Options](https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Arguments.md) of Redux DevTools.
|
34
34
|
- `autoActions`: the default value is `true`.if [auto generate Actions](./auto-actions.mdx).
|
35
35
|
|
36
36
|
### Return Value
|
@@ -65,7 +65,7 @@ interface State {
|
|
65
65
|
}
|
66
66
|
```
|
67
67
|
|
68
|
-
if `result` is `false
|
68
|
+
if `result` is `false`, then returned State has no `result`:
|
69
69
|
|
70
70
|
```ts
|
71
71
|
interface State {
|
@@ -80,13 +80,13 @@ interface State {
|
|
80
80
|
|
81
81
|
- `combineMode`: the default value is `"merge"`. Get fulfilled state results. There are two ways to deal with it (The data types that can be automatically processed here are also limited to simple object or array types):
|
82
82
|
|
83
|
-
- `"merge"`: the previous data is merged with the current data. the data is an array type, operation is similar to `[].concat(lastData, currentData)`. the data is an object
|
83
|
+
- `"merge"`: the previous data is merged with the current data. the data is an array type, operation is similar to `[].concat(lastData, currentData)`. the data is an object, operation is similar to `{...lastData, ...curData}`.
|
84
84
|
- `"replace"`: the current data directly replaces the previous data.
|
85
85
|
|
86
86
|
- `omitResultNamespace`: the default value is `false`. When the result is an object type, you want to mount the result directly on the State of the Model, rather than on "result", you can set it to true. For example:
|
87
87
|
|
88
88
|
```ts
|
89
|
-
// the result: {user: 'xx', email: 'xx'}
|
89
|
+
// the result: {user: 'xx', email: 'xx'},
|
90
90
|
// config handleEffect({ omitResultNamespace: true })
|
91
91
|
// get State like follows:
|
92
92
|
{
|
@@ -33,7 +33,7 @@ Used to define the detailed structure of the Model, supporting passing in an obj
|
|
33
33
|
|
34
34
|
`function define(modelDesc: ModelDesc): Model;`
|
35
35
|
|
36
|
-
- modelDesc: `ModelDesc
|
36
|
+
- modelDesc: `ModelDesc`, definition of Model structure, includes `state`、`computed`、`actions`、`effects` etc. props.
|
37
37
|
|
38
38
|
```tsx title="example"
|
39
39
|
const fooModel = model('foo').define({
|
@@ -59,7 +59,7 @@ const fooModel = model('foo').define({
|
|
59
59
|
`function define((context: Context, utils: Utils) => ModelDesc): Model;`
|
60
60
|
|
61
61
|
- `context`: Reduck Context, can get underlying `store` object. `store` support all Redux Store [API](https://redux.js.org/api/store), also mounts the `use` method for consuming the Model, and the `unmount` method for unmounting the Model.
|
62
|
-
- utils: commonly used tool like `use`、`onMount`. `use` is the same as `store.use
|
62
|
+
- utils: commonly used tool like `use`、`onMount`. `use` is the same as `store.use`, `onMount` is the hook function after the Model is mounted.
|
63
63
|
|
64
64
|
{/* TODO: @anchao 调整类型 */}
|
65
65
|
```ts
|
@@ -38,8 +38,8 @@ function useModel(
|
|
38
38
|
|
39
39
|
Returns an array with each value:
|
40
40
|
|
41
|
-
- state: return value of `stateSelector`. if there is no `stateSelector
|
42
|
-
- actions: return value of `actionSelector`. if there is no `actionSelector
|
41
|
+
- state: return value of `stateSelector`. if there is no `stateSelector`, will combine all incoming Model States(including derived states) and return them. If there is an attribute of the same name in the State of different Models, the following State will override the previous State. when `state` changes, the component call `useModel` will re-render.
|
42
|
+
- actions: return value of `actionSelector`. if there is no `actionSelector`, will combine all incoming Model Action(including Effect) and return them. If there is an attribute of the same name in the Action of different Models, the following Action will override the previous Action.
|
43
43
|
- subscribe: A function that subscribes to State changes. This function is called when the State of any Model passed in changes.
|
44
44
|
|
45
45
|
## Example
|
@@ -8,7 +8,7 @@ import ReduckTip from "@site-docs-en/components/reduck-tip"
|
|
8
8
|
|
9
9
|
<ReduckTip />
|
10
10
|
|
11
|
-
If want to consume a Model in the form of React Hook in the component
|
11
|
+
If want to consume a Model in the form of React Hook in the component, and can get the current latest state at any time, but you don't want the Model state to be updated, which will cause the component to be re-rendered, we can use `useStaticModel`.
|
12
12
|
|
13
13
|
`useStaticModel` API is same as `useModel`.For detail, see [`useModel`](./use-model.mdx).
|
14
14
|
|
@@ -16,7 +16,7 @@ To ensure that the latest state is always available, be careful not to deconstru
|
|
16
16
|
|
17
17
|
```tsx
|
18
18
|
function App() {
|
19
|
-
// ❌ Do not deconstruct state
|
19
|
+
// ❌ Do not deconstruct state, but can deconstruct actions.
|
20
20
|
const [{ username }, { logout }] = useStaticModel(userModel);
|
21
21
|
|
22
22
|
// ✅ True Usage.
|
@@ -18,7 +18,7 @@ function useStore(): ReduckStore;
|
|
18
18
|
|
19
19
|
### Return Type
|
20
20
|
|
21
|
-
- ReduckStore: Reduck Store
|
21
|
+
- ReduckStore: Reduck Store, type refer to the return type of [createStore](./create-store.mdx).
|
22
22
|
|
23
23
|
:::info More
|
24
24
|
[Use Model](/guides/topic-detail/model/use-model).
|
@@ -35,8 +35,8 @@ function PreRender(props: Props): React.Component
|
|
35
35
|
|
36
36
|
### Input
|
37
37
|
|
38
|
-
- `interval`: set the time the cache keep fresh
|
39
|
-
- `staleLimit`: sets the time when the cache is completely expired
|
38
|
+
- `interval`: set the time the cache keep fresh, seconds. During this time, the cache will be used directly and not invoke asynchronous rendering.
|
39
|
+
- `staleLimit`: sets the time when the cache is completely expired, seconds.During this time, The cache can be returned and asynchronous rendering will be invoke, otherwise must wait for the re-rendered result.
|
40
40
|
- `level`: sets the calculation rule level for the cache identity, usually used with `includes` and `matches`. The default value is `0`.
|
41
41
|
|
42
42
|
```bash
|
@@ -39,7 +39,7 @@ function render(ui: React.ReactElement<any>, options: Options): RenderResult;
|
|
39
39
|
|
40
40
|
- `ui`: the React component that needs to be rendered.
|
41
41
|
- `options`: render options.
|
42
|
-
- `container`: the dom which component mounted. by default create a `div` element
|
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
44
|
- `hydrate`: If set to `true`, the [ReactDOM.hydrate](https://reactjs.org/docs/react-dom.html#hydrate) rendering component is used. The default value is `false`.
|
45
45
|
- `wrapper`: a react component that can be used to customize rendering logic.
|
@@ -6,7 +6,7 @@ import { Tabs, Tab as TabItem } from "@theme";
|
|
6
6
|
<Tabs>
|
7
7
|
<TabItem value="express" label="Express.js" default>
|
8
8
|
|
9
|
-
```ts title="
|
9
|
+
```ts title="modern.config.ts"
|
10
10
|
import expressPlugin from '@modern-js/plugin-express';
|
11
11
|
import bffPlugin from '@modern-js/plugin-bff';
|
12
12
|
|
@@ -18,7 +18,7 @@ export default defineConfig({
|
|
18
18
|
</TabItem>
|
19
19
|
<TabItem value="koa" label="Koa.js">
|
20
20
|
|
21
|
-
```ts title="
|
21
|
+
```ts title="modern.config.ts"
|
22
22
|
import koaPlugin from '@modern-js/plugin-koa';
|
23
23
|
import bffPlugin from '@modern-js/plugin-bff';
|
24
24
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
sidebar_label: scriptLoading
|
3
|
+
---
|
4
|
+
|
5
|
+
# html.scriptLoading
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
This config is provided by Modern.js Builder, more detail can see [html.scriptLoading](https://modernjs.dev/builder/en/api/config-html.html#htmlscriptloading).
|
9
|
+
:::
|
10
|
+
|
11
|
+
import Main from '@modern-js/builder-doc/docs/en/config/html/scriptLoading.md';
|
12
|
+
|
13
|
+
<Main />
|
@@ -143,7 +143,7 @@ The `headers` set in the route override the `headers` set in the entry.
|
|
143
143
|
|
144
144
|
By default, **Conventional Routing** all turn on SSG. Modern.js provides another field to prevent the default SSG behavior.
|
145
145
|
|
146
|
-
For example, the following directory structure
|
146
|
+
For example, the following directory structure , `/`、`/user` and `/user/profle` all have SSG enabled:
|
147
147
|
|
148
148
|
```bash
|
149
149
|
.
|
@@ -23,9 +23,9 @@ This config **is used to configure the Modern.js framework plugin**. If you need
|
|
23
23
|
|
24
24
|
There are three different type of framework plugins built into the Modern.js:
|
25
25
|
|
26
|
-
- `CLI Plugin
|
27
|
-
- `Server Plugin
|
28
|
-
- `Runtime Plugin
|
26
|
+
- `CLI Plugin`, for local development, compilation and build phases, can extend various capabilities on the command line and compilation phases.
|
27
|
+
- `Server Plugin`, for server-level.
|
28
|
+
- `Runtime Plugin`, for runtime.
|
29
29
|
|
30
30
|
The ability to customize CLI plugins is currently open Modern.js, and the Server plugin and Runtime plugin will be available in the future.
|
31
31
|
|
@@ -26,7 +26,7 @@ First, you need to execute `pnpm run new` to enable the SWC compile:
|
|
26
26
|
? Enable features: Enable SWC Compile
|
27
27
|
```
|
28
28
|
|
29
|
-
After the installation
|
29
|
+
After the installation, please register the SWC plugin in the `modern.config.ts` file, then the SWC compilation and compression will be enabled.
|
30
30
|
|
31
31
|
```ts title="modern.config.ts"
|
32
32
|
import appTools, { defineConfig } from '@modern-js/app-tools';
|
@@ -19,17 +19,33 @@ Server runtime configuration can be configured in the `modern.server-runtime.con
|
|
19
19
|
|
20
20
|
## Configure in the configuration file
|
21
21
|
|
22
|
-
Modern.js configuration files are defined in the root path of the project, and supports `.
|
22
|
+
Modern.js configuration files are defined in the root path of the project, and supports `.ts`, `.js` and `.mjs` formats:
|
23
23
|
|
24
|
-
- `modern.config.js`
|
25
24
|
- `modern.config.ts`
|
25
|
+
- `modern.config.js`
|
26
26
|
- `modern.config.mjs`
|
27
27
|
|
28
|
-
### modern.config.
|
28
|
+
### modern.config.ts (recommended)
|
29
29
|
|
30
|
-
|
30
|
+
We recommend using configuration files in `.ts` format, which provides friendly TypeScript type hints to help you avoid configuration errors.
|
31
31
|
|
32
|
-
|
32
|
+
Import the `defineConfig` tool function from `@modern-js/app-tools`, which will help you with configuration type derivation and type completion:
|
33
|
+
|
34
|
+
```ts title="modern.config.ts"
|
35
|
+
import { defineConfig } from '@modern-js/app-tools';
|
36
|
+
|
37
|
+
export default defineConfig({
|
38
|
+
source: {
|
39
|
+
alias: {
|
40
|
+
'@common': './src/common',
|
41
|
+
},
|
42
|
+
},
|
43
|
+
});
|
44
|
+
```
|
45
|
+
|
46
|
+
### modern.config.js
|
47
|
+
|
48
|
+
If you are developing a non-TypeScript project, you can use the configuration file in .js format:
|
33
49
|
|
34
50
|
```js title="modern.config.js"
|
35
51
|
export default {
|
@@ -51,24 +67,6 @@ export default {
|
|
51
67
|
};
|
52
68
|
```
|
53
69
|
|
54
|
-
### modern.config.ts (recommended)
|
55
|
-
|
56
|
-
We recommend using configuration files in `.ts` format, which provides friendly TypeScript type hints to help you avoid configuration errors.
|
57
|
-
|
58
|
-
Import the `defineConfig` tool function from `@modern-js/app-tools`, which will help you with configuration type derivation and type completion:
|
59
|
-
|
60
|
-
```ts title="modern.config.ts"
|
61
|
-
import { defineConfig } from '@modern-js/app-tools';
|
62
|
-
|
63
|
-
export default defineConfig({
|
64
|
-
source: {
|
65
|
-
alias: {
|
66
|
-
'@common': './src/common',
|
67
|
-
},
|
68
|
-
},
|
69
|
-
});
|
70
|
-
```
|
71
|
-
|
72
70
|
### Export Configuration Function
|
73
71
|
|
74
72
|
Modern.js supports exporting a function in the configuration file, and you can dynamically compute the configuration in the function and return it to Modern.js.
|
@@ -200,3 +198,47 @@ modern.config.local.ts
|
|
200
198
|
modern.config.local.js
|
201
199
|
modern.config.local.mjs
|
202
200
|
```
|
201
|
+
|
202
|
+
## Merge Multiple Configurations
|
203
|
+
|
204
|
+
In some cases, you may need to merge multiple configurations into one configuration. You can use the `mergeConfig` util to merge multiple configurations.
|
205
|
+
|
206
|
+
The `mergeConfig` function accepts an array as a parameter, and each item in the array is a configuration object. `mergeConfig` will deeply merge each configuration object in the array, automatically merge multiple functions into an array, and returns a merged configuration object.
|
207
|
+
|
208
|
+
### Example
|
209
|
+
|
210
|
+
```ts title="modern.config.ts"
|
211
|
+
import { mergeConfig } from '@modern-js/app-tools';
|
212
|
+
|
213
|
+
const config1 = {
|
214
|
+
dev: {
|
215
|
+
port: 3000,
|
216
|
+
},
|
217
|
+
tools: {
|
218
|
+
postcss: () => console. log('config1');
|
219
|
+
},
|
220
|
+
};
|
221
|
+
const config2 = {
|
222
|
+
dev: {
|
223
|
+
port: 3001,
|
224
|
+
},
|
225
|
+
tools: {
|
226
|
+
postcss: () => console. log('config2');
|
227
|
+
},
|
228
|
+
};
|
229
|
+
|
230
|
+
const mergedConfig = mergeConfig([config1, config2]);
|
231
|
+
```
|
232
|
+
|
233
|
+
In the above example, the merged configuration object is:
|
234
|
+
|
235
|
+
```ts
|
236
|
+
const mergedConfig = {
|
237
|
+
dev: {
|
238
|
+
port: 3001,
|
239
|
+
},
|
240
|
+
tools: {
|
241
|
+
postcss: [() => console.log('config1'), () => console.log('config2')],
|
242
|
+
},
|
243
|
+
};
|
244
|
+
```
|
@@ -114,7 +114,7 @@ For example, following the example, a `GET` interface can be exported.
|
|
114
114
|
export const get = async () => {
|
115
115
|
return {
|
116
116
|
name: 'Modern.js',
|
117
|
-
desc: '
|
117
|
+
desc: 'Web engineering system',
|
118
118
|
};
|
119
119
|
};
|
120
120
|
```
|
@@ -125,14 +125,14 @@ Following the example below, a `POST` interface can be exported.
|
|
125
125
|
export const post = async () => {
|
126
126
|
return {
|
127
127
|
name: 'Modern.js',
|
128
|
-
desc: '
|
128
|
+
desc: 'Web engineering system',
|
129
129
|
};
|
130
130
|
};
|
131
131
|
```
|
132
132
|
|
133
133
|
- Modern.js supports 9 definitions for HTTP Method: `GET`、`POST`、`PUT`、`DELETE`、`CONNECT`、`TRACE`、`PATCH`、`OPTION`、`HEAD`, can be exported using these methods as functions.
|
134
134
|
|
135
|
-
- The name is size insensitive
|
135
|
+
- The name is size insensitive, if `GET`, can write `get`、`Get`、`GEt`、`GET`, can be accurately identified. But default export as `export default xxx` will be map to `Get`.
|
136
136
|
|
137
137
|
- Multiple functions of different Methods can be defined in one file, but if multiple functions of the same Method are defined, only the first will take effect.
|
138
138
|
|
@@ -17,7 +17,7 @@ When you use Modern.js [Conventional routing](/guides/basic-features/routes#conv
|
|
17
17
|
|
18
18
|
## import
|
19
19
|
|
20
|
-
use dynamic `import()
|
20
|
+
use dynamic `import()`, `import` The JS modules pass to this API will be packaged into a separate JS file as a new packaging entry, for example:
|
21
21
|
|
22
22
|
```ts
|
23
23
|
import('./math').then(math => {
|
@@ -60,7 +60,7 @@ For detail, see [React lazy](https://reactjs.org/docs/code-splitting.html#reactl
|
|
60
60
|
|
61
61
|
## loadable
|
62
62
|
|
63
|
-
use `loadable` API
|
63
|
+
use `loadable` API, for example:
|
64
64
|
|
65
65
|
```ts
|
66
66
|
import loadable from '@modern-js/runtime/loadable';
|
@@ -4,7 +4,7 @@ sidebar_position: 8
|
|
4
4
|
---
|
5
5
|
# ESLint
|
6
6
|
|
7
|
-
**Modern.js ESLint Rules** is the full set of **ESLint** rules
|
7
|
+
**Modern.js ESLint Rules** is the full set of **ESLint** rules, includes `@modern-js` (Lint rules for Node.js projects) and `@modern-js-app` (Lint rules for web projects).
|
8
8
|
|
9
9
|
More ESLint usage is described below with specific questions.
|
10
10
|
|