Skip to content

Commit 6b5e9dd

Browse files
committed
docs(en): merging all conflicts
2 parents f091d8d + b308a00 commit 6b5e9dd

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

guide/api-environment-frameworks.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,52 @@ if (isRunnableDevEnvironment(server.environments.ssr)) {
3838
```
3939

4040
:::warning
41+
<<<<<<< HEAD
4142
首次访问 `runner` 时,它会被立即执行。请注意,当通过调用 `process.setSourceMapsEnabled` 或在不支持的情况下重写 `Error.prepareStackTrace` 创建 `runner` 时,Vite 会启用源映射支持。
43+
=======
44+
The `runner` is evaluated lazily only when it's accessed for the first time. Beware that Vite enables source map support when the `runner` is created by calling `process.setSourceMapsEnabled` or by overriding `Error.prepareStackTrace` if it's not available.
45+
:::
46+
47+
Frameworks that communicate with their runtime via the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch) can utilize the `FetchableDevEnvironment` that provides a standardized way of handling requests via the `handleRequest` method:
48+
49+
```ts
50+
import {
51+
createServer,
52+
createFetchableDevEnvironment,
53+
isFetchableDevEnvironment,
54+
} from 'vite'
55+
56+
const server = await createServer({
57+
server: { middlewareMode: true },
58+
appType: 'custom',
59+
environments: {
60+
custom: {
61+
dev: {
62+
createEnvironment(name, config) {
63+
return createFetchableDevEnvironment(name, config, {
64+
handleRequest(request: Request): Promise<Response> | Response {
65+
// handle Request and return a Response
66+
},
67+
})
68+
},
69+
},
70+
},
71+
},
72+
})
73+
74+
// Any consumer of the environment API can now call `dispatchFetch`
75+
if (isFetchableDevEnvironment(server.environments.custom)) {
76+
const response: Response = await server.environments.custom.dispatchFetch(
77+
new Request('/request-to-handle'),
78+
)
79+
}
80+
```
81+
82+
:::warning
83+
Vite validates the input and output of the `dispatchFetch` method: the request must be an instance of the global `Request` class and the response must be the instance of the global `Response` class. Vite will throw a `TypeError` if this is not the case.
84+
85+
Note that although the `FetchableDevEnvironment` is implemented as a class, it is considered an implementation detail by the Vite team and might change at any moment.
86+
>>>>>>> b308a004096a6e5c421e50c2db23f988f05db15d
4287
:::
4388

4489
## 默认 `RunnableDevEnvironment` {#default-runnabledevenvironment}

guide/env-and-mode.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ VITE_BAR=bar
108108
```typescript [vite-env.d.ts]
109109
/// <reference types="vite/client" />
110110

111+
interface ViteTypeOptions {
112+
// By adding this line, you can make the type of ImportMetaEnv strict
113+
// to disallow unknown keys.
114+
// strictImportMetaEnv: unknown
115+
}
116+
111117
interface ImportMetaEnv {
112118
readonly VITE_APP_TITLE: string
113119
// 更多环境变量...

0 commit comments

Comments
 (0)