@modern-js/main-doc 3.0.0-alpha.2 → 3.0.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/docs/en/apis/app/hooks/api/lambda.mdx +3 -3
- package/docs/en/apis/app/hooks/modern-config.mdx +2 -2
- package/docs/en/apis/app/hooks/server/server.mdx +2 -2
- package/docs/en/apis/app/hooks/src/app.mdx +3 -3
- package/docs/en/apis/app/hooks/src/entry.mdx +6 -6
- package/docs/en/apis/app/hooks/src/entry.server.mdx +2 -2
- package/docs/en/apis/app/hooks/src/modern.runtime.mdx +2 -2
- package/docs/en/apis/app/hooks/src/routes.mdx +1 -1
- package/docs/en/apis/app/hooks/src/server.mdx +2 -2
- package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +2 -2
- package/docs/en/apis/app/runtime/core/runtime-context.mdx +160 -0
- package/docs/en/community/blog/2022-0708-updates.md +1 -1
- package/docs/en/components/default-browserslist.mdx +7 -0
- package/docs/en/components/enable-bff.mdx +1 -1
- package/docs/en/components/enable-ssg.mdx +1 -1
- package/docs/en/components/extend-bff-function.mdx +1 -1
- package/docs/en/components/hono.mdx +3 -2
- package/docs/en/components/ssr-monitor.mdx +2 -2
- package/docs/en/configure/app/dev/server.mdx +9 -92
- package/docs/en/configure/app/output/assets-retry.mdx +1 -1
- package/docs/en/configure/app/source/alias-strategy.mdx +4 -0
- package/docs/en/configure/app/source/alias.mdx +4 -0
- package/docs/en/configure/app/source/entries.mdx +2 -2
- package/docs/en/configure/app/tools/dev-server.mdx +6 -93
- package/docs/en/guides/advanced-features/bff/function.mdx +1 -1
- package/docs/en/guides/advanced-features/bff/operators.mdx +2 -1
- package/docs/en/guides/advanced-features/compatibility.mdx +6 -9
- package/docs/en/guides/advanced-features/page-performance/react-compiler.mdx +2 -2
- package/docs/en/guides/advanced-features/server-monitor/logger.mdx +0 -7
- package/docs/en/guides/advanced-features/server-monitor/metrics.mdx +2 -2
- package/docs/en/guides/basic-features/data/data-cache.mdx +1 -1
- package/docs/en/guides/basic-features/data/data-fetch.mdx +11 -22
- package/docs/en/guides/basic-features/debug/mock.mdx +1 -1
- package/docs/en/guides/basic-features/debug/proxy.mdx +7 -9
- package/docs/en/guides/basic-features/debug/rsdoctor.mdx +2 -14
- package/docs/en/guides/basic-features/html.mdx +4 -4
- package/docs/en/guides/basic-features/render/rsc.mdx +3 -3
- package/docs/en/guides/basic-features/routes/config-routes.mdx +5 -5
- package/docs/en/guides/basic-features/testing/jest.mdx +11 -11
- package/docs/en/guides/basic-features/testing/rstest.mdx +94 -0
- package/docs/en/guides/concept/entries.mdx +4 -4
- package/docs/en/guides/get-started/introduction.mdx +3 -7
- package/docs/en/guides/troubleshooting/dependencies.mdx +1 -1
- package/docs/en/guides/upgrade/config.mdx +5 -9
- package/docs/en/guides/upgrade/entry.mdx +6 -6
- package/docs/en/guides/upgrade/other.mdx +42 -0
- package/docs/en/guides/upgrade/tailwindcss.mdx +0 -38
- package/docs/en/guides/upgrade/{web-server.mdx → web-server.md} +19 -1
- package/docs/en/plugin/cli-plugins/api.mdx +2 -2
- package/docs/en/plugin/official/cli-plugins/plugin-styled-components.mdx +2 -2
- package/docs/zh/apis/app/hooks/api/lambda.mdx +2 -2
- package/docs/zh/apis/app/hooks/modern-config.mdx +2 -2
- package/docs/zh/apis/app/hooks/server/server.mdx +2 -2
- package/docs/zh/apis/app/hooks/src/app.mdx +4 -4
- package/docs/zh/apis/app/hooks/src/entry.mdx +6 -6
- package/docs/zh/apis/app/hooks/src/entry.server.mdx +2 -2
- package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +2 -2
- package/docs/zh/apis/app/hooks/src/routes.mdx +1 -1
- package/docs/zh/apis/app/hooks/src/server.mdx +2 -2
- package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +2 -2
- package/docs/zh/apis/app/runtime/core/runtime-context.mdx +160 -0
- package/docs/zh/components/default-browserslist.mdx +7 -0
- package/docs/zh/components/enable-bff.mdx +1 -1
- package/docs/zh/components/enable-ssg.mdx +1 -1
- package/docs/zh/components/extend-bff-function.mdx +1 -1
- package/docs/zh/components/hono.mdx +3 -2
- package/docs/zh/components/ssr-monitor.mdx +2 -2
- package/docs/zh/configure/app/dev/server.mdx +8 -91
- package/docs/zh/configure/app/output/assets-retry.mdx +1 -1
- package/docs/zh/configure/app/source/alias-strategy.mdx +4 -0
- package/docs/zh/configure/app/source/alias.mdx +4 -0
- package/docs/zh/configure/app/source/entries.mdx +2 -2
- package/docs/zh/configure/app/tools/dev-server.mdx +5 -92
- package/docs/zh/guides/advanced-features/bff/extend-server.mdx +1 -1
- package/docs/zh/guides/advanced-features/bff/function.mdx +1 -1
- package/docs/zh/guides/advanced-features/bff/operators.mdx +2 -1
- package/docs/zh/guides/advanced-features/build-performance.mdx +1 -1
- package/docs/zh/guides/advanced-features/compatibility.mdx +5 -9
- package/docs/zh/guides/advanced-features/page-performance/react-compiler.mdx +2 -2
- package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +0 -7
- package/docs/zh/guides/advanced-features/server-monitor/metrics.mdx +3 -3
- package/docs/zh/guides/basic-features/data/data-cache.mdx +10 -10
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +12 -23
- package/docs/zh/guides/basic-features/debug/mock.mdx +1 -1
- package/docs/zh/guides/basic-features/debug/proxy.mdx +7 -10
- package/docs/zh/guides/basic-features/debug/rsdoctor.mdx +2 -14
- package/docs/zh/guides/basic-features/html.mdx +4 -4
- package/docs/zh/guides/basic-features/render/rsc.mdx +1 -1
- package/docs/zh/guides/basic-features/routes/config-routes.mdx +13 -13
- package/docs/zh/guides/basic-features/testing/jest.mdx +1 -1
- package/docs/zh/guides/basic-features/testing/rstest.mdx +94 -0
- package/docs/zh/guides/concept/entries.mdx +5 -5
- package/docs/zh/guides/get-started/introduction.mdx +2 -6
- package/docs/zh/guides/troubleshooting/dependencies.mdx +1 -1
- package/docs/zh/guides/upgrade/config.mdx +72 -76
- package/docs/zh/guides/upgrade/entry.mdx +12 -12
- package/docs/zh/guides/upgrade/other.md +42 -0
- package/docs/zh/guides/upgrade/tailwindcss.mdx +0 -41
- package/docs/zh/guides/upgrade/web-server.md +19 -1
- package/docs/zh/plugin/cli-plugins/api.mdx +2 -2
- package/docs/zh/plugin/official/cli-plugins/plugin-styled-components.mdx +2 -2
- package/package.json +4 -4
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: lambda/*.
|
|
2
|
+
title: lambda/*.ts
|
|
3
3
|
sidebar_position: 3
|
|
4
4
|
---
|
|
5
|
-
# lambda/*.
|
|
5
|
+
# lambda/*.ts
|
|
6
6
|
|
|
7
7
|
After enabling BFF, the files under the `lambda/` directory will be registered as BFF routes according to conventions.
|
|
8
8
|
|
|
@@ -10,4 +10,4 @@ After enabling BFF, the files under the `lambda/` directory will be registered a
|
|
|
10
10
|
The files can be written in `js` or `ts` languages, but they must use `esm` syntax to export functions.
|
|
11
11
|
:::
|
|
12
12
|
|
|
13
|
-
For detailed information, refer to [BFF API Routes](/guides/advanced-features/bff/function.html#api-routes).
|
|
13
|
+
For detailed information, refer to [BFF API Routes](/guides/advanced-features/bff/function.html#api-routes).
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: modern.config.
|
|
2
|
+
title: modern.config.ts
|
|
3
3
|
sidebar_position: 8
|
|
4
4
|
---
|
|
5
|
-
# modern.config.
|
|
5
|
+
# modern.config.ts
|
|
6
6
|
|
|
7
7
|
The Modern.js configuration file. Through this file, you can personalize the configuration of various aspects of the current project.
|
|
8
8
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: modern.server.
|
|
2
|
+
title: modern.server.ts
|
|
3
3
|
sidebar_position: 1
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# modern.server.
|
|
6
|
+
# modern.server.ts
|
|
7
7
|
|
|
8
8
|
This file extends the Modern.js Server. In this file, you can configure [Middleware](/guides/advanced-features/web-server.html#middleware), [RenderMiddleware](/guides/advanced-features/web-server.html#rendermiddleware), or [Plugin](/guides/advanced-features/web-server.html#plugin) for the Server that starts with the Modern.js project.
|
|
9
9
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# App.
|
|
1
|
+
# App.tsx
|
|
2
2
|
|
|
3
3
|
The entry identifier when using [Self-controlled Routing](/guides/concept/entries.html#self-controlled-routing) in the application.
|
|
4
4
|
|
|
5
|
-
`App.
|
|
5
|
+
`App.tsx` is not the actual application entry; Modern.js will automatically generate the real entry file, which is roughly as follows:
|
|
6
6
|
|
|
7
7
|
```js
|
|
8
8
|
// runtime-global-context
|
|
@@ -26,5 +26,5 @@ render(<ModernRoot />, 'root');
|
|
|
26
26
|
When `createRoot` is executed, it will retrieve the registered Global App and generate the actual React component.
|
|
27
27
|
|
|
28
28
|
:::note
|
|
29
|
-
In scenarios with multiple entry points, each entry can have its own independent `App.
|
|
29
|
+
In scenarios with multiple entry points, each entry can have its own independent `App.tsx`. For more details, see [Entry Points](/guides/concept/entries).
|
|
30
30
|
:::
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: entry.
|
|
2
|
+
title: entry.ts
|
|
3
3
|
sidebar_position: 4
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# entry.
|
|
6
|
+
# entry.tsx
|
|
7
7
|
|
|
8
|
-
Normally, the [`routes/`](/apis/app/hooks/src/routes.html) and [`App.
|
|
8
|
+
Normally, the [`routes/`](/apis/app/hooks/src/routes.html) and [`App.tsx`](/apis/app/hooks/src/app) hook files can meet our needs. When we need to add custom behavior before component rendering or take full control of the Rspack packaging entry, we can create `entry.ts` file in the src or entry directory. Here are two cases for discussion。
|
|
9
9
|
|
|
10
10
|
## Add custom behavior before Render
|
|
11
11
|
|
|
12
|
-
This is implemented in `src/entry.
|
|
12
|
+
This is implemented in `src/entry.ts` as follows:
|
|
13
13
|
|
|
14
14
|
```js title=src/entry.tsx
|
|
15
15
|
import { createRoot } from '@modern-js/runtime/react';
|
|
@@ -26,9 +26,9 @@ beforeRender().then(() => {
|
|
|
26
26
|
});
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
## Take full control of the
|
|
29
|
+
## Take full control of the Rspack entry
|
|
30
30
|
|
|
31
|
-
When the project does not install the `@modern-js/runtime` dependency, `src/entry.
|
|
31
|
+
When the project does not install the `@modern-js/runtime` dependency, `src/entry.tsx?` is the real Rspack packaging entry file, and you can directly organize the code like using create-react-app and other scaffolds:
|
|
32
32
|
|
|
33
33
|
```js title=src/entry.jsx
|
|
34
34
|
import React from 'react';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: entry.server.
|
|
2
|
+
title: entry.server.tsx
|
|
3
3
|
sidebar_position: 5
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# entry.server.
|
|
6
|
+
# entry.server.tsx
|
|
7
7
|
|
|
8
8
|
When the project initiates `server.ssr`, Modern.js generates a default Server-Side entry. The sample code is as follows:
|
|
9
9
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: modern.runtime.
|
|
2
|
+
title: modern.runtime.ts
|
|
3
3
|
sidebar_position: 4
|
|
4
4
|
---
|
|
5
|
-
# modern.runtime.
|
|
5
|
+
# modern.runtime.ts
|
|
6
6
|
|
|
7
7
|
The Modern.js Runtime configuration file allows for personalized configuration of the Runtime capabilities for the current project.
|
|
8
8
|
|
|
@@ -8,7 +8,7 @@ The identifier for the entry point when the application uses [Conventional Routi
|
|
|
8
8
|
|
|
9
9
|
Conventional routing uses `routes/` as the convention for the entry point and analyzes the files in the `src/routes` directory to obtain the client-side routing configuration.
|
|
10
10
|
|
|
11
|
-
Any `layout.
|
|
11
|
+
Any `layout.tsx` and `page.tsx` under `src/routes` will be used as the application's routes:
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: '*.[server|node].
|
|
2
|
+
title: '*.[server|node].tsx'
|
|
3
3
|
sidebar_position: 8
|
|
4
4
|
---
|
|
5
|
-
# *.[server|node].
|
|
5
|
+
# *.[server|node].tsx
|
|
6
6
|
|
|
7
7
|
Used in the application project to place server-side code. When `*.tsx` and `*.[server|node].tsx` coexist, SSR will prefer to use the `*.[server|node].tsx` file instead of the `*.tsx` file when rendering on the server.
|
|
@@ -8,7 +8,7 @@ Used to obtain Hono context in an integrated BFF function.
|
|
|
8
8
|
## Usage
|
|
9
9
|
|
|
10
10
|
```ts
|
|
11
|
-
import { useHonoContext } from '@modern-js/
|
|
11
|
+
import { useHonoContext } from '@modern-js/server-runtime';
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
## Function Signature
|
|
@@ -20,7 +20,7 @@ import { useHonoContext } from '@modern-js/plugin-bff/server';
|
|
|
20
20
|
Developers can use `context` to obtain more request information, such as setting response headers:
|
|
21
21
|
|
|
22
22
|
```ts
|
|
23
|
-
import { useHonoContext } from '@modern-js/
|
|
23
|
+
import { useHonoContext } from '@modern-js/server-runtime';
|
|
24
24
|
|
|
25
25
|
export async function get() {
|
|
26
26
|
const c = useHonoContext();
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: RuntimeContext
|
|
3
|
+
---
|
|
4
|
+
# RuntimeContext
|
|
5
|
+
|
|
6
|
+
`RuntimeContext` is a React Context used to get Runtime context information in components. This Context can be accessed through React's `use` or `useContext` API.
|
|
7
|
+
|
|
8
|
+
:::warning
|
|
9
|
+
|
|
10
|
+
The `useRuntimeContext` Hook has been deprecated. Please use `use(RuntimeContext)` instead. `useRuntimeContext` is internally implemented as `useContext(RuntimeContext)`, while `use(RuntimeContext)` is the recommended new approach in React 19.
|
|
11
|
+
|
|
12
|
+
:::
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { use } from 'react';
|
|
18
|
+
import { RuntimeContext } from '@modern-js/runtime';
|
|
19
|
+
|
|
20
|
+
export function App() {
|
|
21
|
+
const runtimeContext = use(RuntimeContext); // You can also use useContext(RuntimeContext)
|
|
22
|
+
return <div>Hello World</div>
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Type Definition
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
type TRuntimeContext = {
|
|
30
|
+
initialData?: Record<string, unknown>;
|
|
31
|
+
isBrowser: boolean;
|
|
32
|
+
routes?: RouteObject[];
|
|
33
|
+
requestContext: RequestContext;
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated Use `requestContext` instead
|
|
36
|
+
*/
|
|
37
|
+
context: RequestContext;
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
};
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Property Description
|
|
43
|
+
|
|
44
|
+
- `isBrowser`: Indicates whether the current runtime environment is a browser
|
|
45
|
+
- `routes`: Route configuration information
|
|
46
|
+
- `requestContext`: Request context, containing `request` and `response` objects
|
|
47
|
+
- `context`: Deprecated, please use `requestContext` instead
|
|
48
|
+
|
|
49
|
+
### RequestContext
|
|
50
|
+
|
|
51
|
+
`RequestContext` is the type of the `requestContext` property, containing request and response related information:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
type RequestContext = {
|
|
55
|
+
request: {
|
|
56
|
+
params: Record<string, string>; // Route parameters
|
|
57
|
+
pathname: string; // Pathname
|
|
58
|
+
query: Record<string, string>; // Query parameters
|
|
59
|
+
headers: IncomingHttpHeaders; // Request headers
|
|
60
|
+
host: string; // Hostname
|
|
61
|
+
url: string; // Full URL
|
|
62
|
+
referer?: string; // Referrer page
|
|
63
|
+
userAgent?: string; // User agent
|
|
64
|
+
cookie?: string; // Cookie string
|
|
65
|
+
cookieMap?: Record<string, string>; // Cookie map object
|
|
66
|
+
};
|
|
67
|
+
response: {
|
|
68
|
+
setHeader: (key: string, value: string) => void; // Set response header (server-side only)
|
|
69
|
+
status: (code: number) => void; // Set status code (server-side only)
|
|
70
|
+
locals: Record<string, any>; // Local data
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**Notes**:
|
|
76
|
+
|
|
77
|
+
- `response.setHeader` and `response.status` are only available on the server-side (SSR)
|
|
78
|
+
- On the browser side, the `response` object may not contain these methods
|
|
79
|
+
- The `request` object is available on both server and browser, but server-side information is more complete
|
|
80
|
+
|
|
81
|
+
## Usage Examples
|
|
82
|
+
|
|
83
|
+
### Distinguishing Runtime Environment
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
import { use } from 'react';
|
|
87
|
+
import { RuntimeContext } from '@modern-js/runtime';
|
|
88
|
+
|
|
89
|
+
function App() {
|
|
90
|
+
const { context, isBrowser } = use(RuntimeContext);
|
|
91
|
+
|
|
92
|
+
if (isBrowser === true) {
|
|
93
|
+
// Browser-side execution logic
|
|
94
|
+
console.log('browser render')
|
|
95
|
+
} else {
|
|
96
|
+
// Server-side execution logic
|
|
97
|
+
// Note: Functions like logger need to be injected into context through Runtime plugins
|
|
98
|
+
console.log('server render')
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Getting Request Context
|
|
104
|
+
|
|
105
|
+
When SSR is enabled, isomorphic request context can be obtained in both Node environment and browser environment.
|
|
106
|
+
|
|
107
|
+
The slight difference is that the Node environment also supports setting response headers, response codes, and provides Logger logging and Metrics tracking.
|
|
108
|
+
|
|
109
|
+
:::tip
|
|
110
|
+
|
|
111
|
+
When SSR is not enabled, only the information that can be obtained on the browser side is included.
|
|
112
|
+
|
|
113
|
+
:::
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
import { use } from 'react';
|
|
117
|
+
import { RuntimeContext } from '@modern-js/runtime';
|
|
118
|
+
|
|
119
|
+
function App() {
|
|
120
|
+
const runtimeContext = use(RuntimeContext);
|
|
121
|
+
const { request, response } = runtimeContext.requestContext || {};
|
|
122
|
+
|
|
123
|
+
// Access request information
|
|
124
|
+
const userAgent = request?.userAgent || request?.headers?.['user-agent'];
|
|
125
|
+
const url = request?.url;
|
|
126
|
+
const query = request?.query;
|
|
127
|
+
const params = request?.params;
|
|
128
|
+
|
|
129
|
+
// Server-side can set response headers
|
|
130
|
+
if (!runtimeContext.isBrowser && response) {
|
|
131
|
+
response.setHeader('X-Custom-Header', 'value');
|
|
132
|
+
response.status(200);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<div>
|
|
137
|
+
<div>User Agent: {userAgent}</div>
|
|
138
|
+
<div>URL: {url}</div>
|
|
139
|
+
<div>Query: {JSON.stringify(query)}</div>
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Accessing Injected Global Data
|
|
146
|
+
|
|
147
|
+
Global data can be injected into `RuntimeContext` through the `onBeforeRender` hook of Runtime plugins:
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
import { use } from 'react';
|
|
151
|
+
import { RuntimeContext } from '@modern-js/runtime';
|
|
152
|
+
|
|
153
|
+
export default function MyComponent() {
|
|
154
|
+
const context = use(RuntimeContext);
|
|
155
|
+
const { message } = context;
|
|
156
|
+
|
|
157
|
+
return <div>{message}</div>;
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
@@ -74,7 +74,7 @@ Reduck 作为 Modern.js 的第一方状态管理方案,发布 v1.1 版本,
|
|
|
74
74
|
**新增命令**
|
|
75
75
|
|
|
76
76
|
- [`upgrade`](https://modernjs.dev/v1/docs/apis/app/commands/upgrade):自动升级 Modern.js 版本。功能同执行 `npx @modern-js/upgrade` 命令。
|
|
77
|
-
- [`inspect`](https://modernjs.dev/v1/docs/apis/app/commands/inspect):通过该命令可以输出当前项目使用的完整
|
|
77
|
+
- [`inspect`](https://modernjs.dev/v1/docs/apis/app/commands/inspect):通过该命令可以输出当前项目使用的完整 rspack 配置。
|
|
78
78
|
- [`gen-release-note`](https://modernjs.dev/v1/docs/apis/module/commands/gen-release-note):自动根据当前仓库的 [changesets](https://github.com/changesets/changesets) 信息生成发布日志。此外,我们提供了[包版本管理专题文档](https://modernjs.dev/v1/docs/guides/features/changesets/introduce),方便大家更好的认识和使用 changesets 及相关功能。
|
|
79
79
|
|
|
80
80
|
**新增配置**
|
|
@@ -25,7 +25,7 @@ pnpm add @modern-js/plugin-bff@<version>
|
|
|
25
25
|
|
|
26
26
|
2. Configure `modern.config.ts`
|
|
27
27
|
|
|
28
|
-
Import and add the BFF plugin in the `modern.config.
|
|
28
|
+
Import and add the BFF plugin in the `modern.config.ts` file:
|
|
29
29
|
|
|
30
30
|
```ts title="modern.config.ts"
|
|
31
31
|
import { defineConfig, appTools } from '@modern-js/app-tools';
|
|
@@ -26,7 +26,7 @@ pnpm add @modern-js/plugin-ssg@<version>
|
|
|
26
26
|
|
|
27
27
|
2. Configure modern.config.ts
|
|
28
28
|
|
|
29
|
-
Import and add the SSG plugin in the `modern.config.
|
|
29
|
+
Import and add the SSG plugin in the `modern.config.ts` file, and configure `output.ssg`:
|
|
30
30
|
|
|
31
31
|
```ts title="modern.config.ts"
|
|
32
32
|
import { defineConfig, appTools } from '@modern-js/app-tools';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
The standard BFF function writing method may not always meet your needs. For example, complex TS type requirements in business scenarios.
|
|
1
|
+
The standard BFF function writing method may not always meet your needs. For example, complex TS type requirements in business scenarios. Modern.js provides a more powerful BFF function writing method.
|
|
2
2
|
|
|
3
3
|
For more details, please refer to - [Creating Extensible BFF Functions](/guides/advanced-features/bff/operators).
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Sometimes in BFF functions, it's necessary to obtain the request context to handle more logic. In such cases, you can use `useHonoContext` to get it:
|
|
4
4
|
|
|
5
5
|
```ts title="api/lambda/hello.ts"
|
|
6
|
-
import { useHonoContext } from '@modern-js/
|
|
6
|
+
import { useHonoContext } from '@modern-js/server-runtime';
|
|
7
7
|
|
|
8
8
|
export const get = async () => {
|
|
9
9
|
const c = useHonoContext();
|
|
@@ -21,7 +21,8 @@ For more details, refer to [useHonoContext](/apis/app/runtime/bff/use-hono-conte
|
|
|
21
21
|
When getting cookies in BFF functions, you need to get the request context through `useHonoContext`, then use `c.req.header('cookie')` to get the Cookie string and parse it manually:
|
|
22
22
|
|
|
23
23
|
```ts title="api/lambda/cookies.ts"
|
|
24
|
-
import { Api, Get
|
|
24
|
+
import { Api, Get } from '@modern-js/plugin-bff/server';
|
|
25
|
+
import { useHonoContext } from '@modern-js/server-runtime';
|
|
25
26
|
|
|
26
27
|
// Helper function to parse Cookie string
|
|
27
28
|
function parseCookies(
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
:::
|
|
2
|
-
|
|
1
|
+
:::tip
|
|
2
|
+
SSR monitoring has been integrated into the Monitors module, see [Monitors](/guides/advanced-features/server-monitor/monitors) for details.
|
|
3
3
|
:::
|
|
@@ -96,7 +96,7 @@ const defaultOptions = {
|
|
|
96
96
|
// - localhost
|
|
97
97
|
// - 127.0.0.1
|
|
98
98
|
// - [::1]
|
|
99
|
-
origin: defaultAllowedOrigins
|
|
99
|
+
origin: defaultAllowedOrigins,
|
|
100
100
|
};
|
|
101
101
|
```
|
|
102
102
|
|
|
@@ -104,108 +104,25 @@ For more configuration options and detailed usage, please refer to the [Rsbuild
|
|
|
104
104
|
|
|
105
105
|
### proxy
|
|
106
106
|
|
|
107
|
-
- **Type:** `Record<string, string
|
|
107
|
+
- **Type:** `ProxyOptions[] | Record<string, string | ProxyOptions>`
|
|
108
108
|
- **Default:** `undefined`
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
Configure proxy rules for the dev server, and forward requests to the specified service.
|
|
111
111
|
|
|
112
112
|
```js
|
|
113
113
|
export default {
|
|
114
114
|
dev: {
|
|
115
115
|
server: {
|
|
116
116
|
proxy: {
|
|
117
|
-
|
|
117
|
+
// http://localhost:8080/api -> https://example.com/api
|
|
118
|
+
// http://localhost:8080/api/foo -> https://example.com/api/foo
|
|
119
|
+
'/api': 'https://example.com/api',
|
|
118
120
|
},
|
|
119
121
|
},
|
|
120
122
|
},
|
|
121
123
|
};
|
|
122
124
|
```
|
|
123
125
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
```js
|
|
129
|
-
export default {
|
|
130
|
-
dev: {
|
|
131
|
-
server: {
|
|
132
|
-
proxy: {
|
|
133
|
-
'/api': {
|
|
134
|
-
target: 'http://localhost:3000',
|
|
135
|
-
pathRewrite: { '^/api': '' },
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
DevServer Proxy is implemented based on [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware/tree/2.x). You can use all configuration items of http-proxy-middleware, see the documentation for details.
|
|
144
|
-
|
|
145
|
-
The full type definition of DevServer Proxy is:
|
|
146
|
-
|
|
147
|
-
```ts
|
|
148
|
-
import type { Options as HttpProxyOptions } from 'http-proxy-middleware';
|
|
149
|
-
|
|
150
|
-
type Filter = string | string[] | ((pathname: string, req: Request) => boolean);
|
|
151
|
-
|
|
152
|
-
type ProxyDetail = HttpProxyOptions & {
|
|
153
|
-
bypass?: (
|
|
154
|
-
req: IncomingMessage,
|
|
155
|
-
res: ServerResponse,
|
|
156
|
-
proxyOptions: ProxyOptions,
|
|
157
|
-
) => string | undefined | null | false;
|
|
158
|
-
context?: Filter;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
type ProxyOptions =
|
|
162
|
-
| Record<string, string>
|
|
163
|
-
| Record<string, ProxyDetail>
|
|
164
|
-
| ProxyDetail[]
|
|
165
|
-
| ProxyDetail;
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
In addition to the http-proxy-middleware options, two configuration items are also supported: bypass and context:
|
|
169
|
-
|
|
170
|
-
- bypass: Bypass the proxy based on the return value of the function.
|
|
171
|
-
- Returning `null` or `undefined` will continue to process the request with proxy.
|
|
172
|
-
- Returning `false` will return a 404 error.
|
|
173
|
-
- Returning a specific service path will use this path to replace the original request path.
|
|
174
|
-
- context: If you want to proxy multiple specific paths to the same target, you can use the context configuration item.
|
|
175
|
-
|
|
176
|
-
```js
|
|
177
|
-
// Custom bypass method
|
|
178
|
-
export default {
|
|
179
|
-
dev: {
|
|
180
|
-
server: {
|
|
181
|
-
proxy: {
|
|
182
|
-
'/api': {
|
|
183
|
-
target: 'http://localhost:3000',
|
|
184
|
-
bypass: function (req, res, proxyOptions) {
|
|
185
|
-
if (req.headers.accept.indexOf('html') !== -1) {
|
|
186
|
-
console.log('Skipping proxy for browser request.');
|
|
187
|
-
return '/index.html';
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
```js
|
|
198
|
-
// Proxy multiple paths to the same target
|
|
199
|
-
export default {
|
|
200
|
-
dev: {
|
|
201
|
-
server: {
|
|
202
|
-
proxy: [
|
|
203
|
-
{
|
|
204
|
-
context: ['/auth', '/api'],
|
|
205
|
-
target: 'http://localhost:3000',
|
|
206
|
-
},
|
|
207
|
-
],
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
};
|
|
211
|
-
```
|
|
126
|
+
:::tip
|
|
127
|
+
This option is the same as Rsbuild's `server.proxy` option, see [Rsbuild - server.proxy](https://v2.rsbuild.rs/config/server/proxy) for detailed usage.
|
|
128
|
+
:::
|
|
@@ -78,4 +78,4 @@ export default {
|
|
|
78
78
|
|
|
79
79
|
With the configuration above, if an asset fails to load from `cdn1.com`, requests will automatically fall back to `cdn2.com`. If `cdn2.com` also fails, the request will continue to `cdn3.com`.
|
|
80
80
|
|
|
81
|
-
`assetsRetry` is implemented based on the Assets Retry plugin of Rsbuild and provides the same configuration options. You can refer to [Rsbuild - Assets Retry Plugin](https://
|
|
81
|
+
`assetsRetry` is implemented based on the Assets Retry plugin of Rsbuild and provides the same configuration options. You can refer to [Rsbuild - Assets Retry Plugin](https://github.com/rstackjs/rsbuild-plugin-assets-retry) to understand all available configuration options.
|
|
@@ -4,6 +4,10 @@ title: aliasStrategy
|
|
|
4
4
|
|
|
5
5
|
# source.aliasStrategy
|
|
6
6
|
|
|
7
|
+
:::warning Deprecation Warning
|
|
8
|
+
`source.aliasStrategy` is deprecated, please use [resolve.aliasStrategy](/configure/app/resolve/alias-strategy) instead.
|
|
9
|
+
:::
|
|
10
|
+
|
|
7
11
|
- **Type:** `'prefer-tsconfig' | 'prefer-alias'`
|
|
8
12
|
- **Default:** `'prefer-tsconfig'`
|
|
9
13
|
|
|
@@ -46,7 +46,7 @@ export default defineConfig({
|
|
|
46
46
|
});
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
By default, the configured entry is equivalent to `App.
|
|
49
|
+
By default, the configured entry is equivalent to `App.tsx`, which means that the specified entry file **only needs to export the root component of the application**.
|
|
50
50
|
|
|
51
51
|
For example, the following directory structure:
|
|
52
52
|
|
|
@@ -102,7 +102,7 @@ export default defineConfig({
|
|
|
102
102
|
|
|
103
103
|
### Disable entry file generation
|
|
104
104
|
|
|
105
|
-
By default, the configured entry is equivalent to `App.
|
|
105
|
+
By default, the configured entry is equivalent to `App.tsx`, and Modern.js will automatically generate an entry file to reference the entry you configured.
|
|
106
106
|
|
|
107
107
|
If you want to disable the logic of Modern.js automatically generating entry files, you can set the `disableMount` property to `true`.
|
|
108
108
|
|