Skip to content

Commit 3cd4822

Browse files
authored
docs: fix some mistakes in Environment API guides (#1995)
1 parent 23b0d59 commit 3cd4822

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

guide/api-environment-frameworks.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Vite は、`dispatchFetch` メソッドの入力と出力を検証します。
8484

8585
## Default `RunnableDevEnvironment`
8686

87-
[SSR セットアップガイド](/guide/ssr#setting-up-the-dev-server)で説明されているように、ミドルウェアモードに設定された Vite サーバーがあるとして、Environment API を使って SSR ミドルウェアを実装してみましょう。エラー処理は省略します。
87+
[SSR セットアップガイド](/guide/ssr#setting-up-the-dev-server)で説明されているように、ミドルウェアモードに設定された Vite サーバーがあるとして、Environment API を使って SSR ミドルウェアを実装してみましょう。これは `ssr` と呼ばれる必要はないので、この例では `server` と名付けます。エラー処理は省略します。
8888

8989
```js
9090
import fs from 'node:fs'
@@ -94,7 +94,7 @@ import { createServer } from 'vite'
9494

9595
const __dirname = path.dirname(fileURLToPath(import.meta.url))
9696

97-
const server = await createServer({
97+
const viteServer = await createServer({
9898
server: { middlewareMode: true },
9999
appType: 'custom',
100100
environments: {
@@ -106,7 +106,7 @@ const server = await createServer({
106106

107107
// TypeScript でこれを RunnableDevEnvironment にキャストするか、ランナーへのアクセスを
108108
// 保護するために isRunnableDevEnvironment を使用する必要があるかもしれません
109-
const environment = server.environments.node
109+
const serverEnvironment = viteServer.environments.server
110110

111111
app.use('*', async (req, res, next) => {
112112
const url = req.originalUrl
@@ -118,12 +118,14 @@ app.use('*', async (req, res, next) => {
118118
// 2. Vite HTML 変換を適用します。これにより、Vite HMR クライアントが挿入され、
119119
// Vite プラグインからの HTML 変換も適用されます。
120120
// 例: global preambles from @vitejs/plugin-react
121-
template = await server.transformIndexHtml(url, template)
121+
template = await viteServer.transformIndexHtml(url, template)
122122

123123
// 3. サーバーエントリをロードします。import(url) は、
124124
// ESM ソースコードを Node.js で使用できるように自動的に変換します。
125125
// バンドルは不要で、完全な HMR サポートを提供します。
126-
const { render } = await environment.runner.import('/src/entry-server.js')
126+
const { render } = await serverEnvironment.runner.import(
127+
'/src/entry-server.js',
128+
)
127129

128130
// 4. アプリの HTML をレンダリングします。これは、entry-server.js のエクスポートされた
129131
// `render` 関数が適切なフレームワーク SSR API を呼び出すことを前提としています。

guide/api-environment-instances.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ Environment API は実験的なものです。Vite 6 では API を安定させ
1919
// サーバーを作成するか、configureServer フックから取得する
2020
const server = await createServer(/* オプション */)
2121

22-
const environment = server.environments.client
23-
environment.transformRequest(url)
22+
const clientEnvironment = server.environments.client
23+
clientEnvironment.transformRequest(url)
2424
console.log(server.environments.ssr.moduleGraph)
2525
```
2626

guide/api-environment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Vite 6 では、環境の概念が正式化されました。Vite 5 までは、
2222
典型的なサーバーサイドレンダリング(SSR)アプリに移行すると、2 つの環境が存在することになります:
2323

2424
- `client`: ブラウザー内でアプリを実行します。
25-
- `server`: Node(または他のサーバーランタイム)内でアプリを実行し、ブラウザーに送信する前にページをレンダリングします。
25+
- `ssr`: Node(または他のサーバーランタイム)内でアプリを実行し、ブラウザーに送信する前にページをレンダリングします。
2626

2727
開発環境では、Vite は Vite 開発サーバーと同じ Node プロセスでサーバーコードを実行し、プロダクション環境に近い環境を実現します。しかし、サーバーを他の JS ランタイムで実行することも可能であり、例えば [Cloudflare の workerd](https://github.com/cloudflare/workerd) など、制約が異なるものもあります。最近のアプリケーションは、ブラウザー、Node サーバー、Edge サーバーなど、2 つ以上の環境で実行されることもあります。 Vite 5 では、これらの環境を適切に表現できませんでした。
2828

0 commit comments

Comments
 (0)