Skip to content

Commit 0f0218e

Browse files
committed
翻訳
1 parent 746a59f commit 0f0218e

File tree

6 files changed

+237
-1128
lines changed

6 files changed

+237
-1128
lines changed

.vitepress/config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,23 +331,23 @@ export default defineConfig({
331331
text: 'Environment API',
332332
items: [
333333
{
334-
text: 'Introduction',
334+
text: 'はじめに',
335335
link: '/guide/api-environment',
336336
},
337337
{
338-
text: 'Environment instances',
338+
text: '環境インスタンス',
339339
link: '/guide/api-environment-instances',
340340
},
341341
{
342-
text: 'Plugins',
342+
text: 'プラグイン',
343343
link: '/guide/api-environment-plugins',
344344
},
345345
{
346-
text: 'Frameworks',
346+
text: 'フレームワーク',
347347
link: '/guide/api-environment-frameworks',
348348
},
349349
{
350-
text: 'Runtimes',
350+
text: 'ランタイム',
351351
link: '/guide/api-environment-runtimes',
352352
},
353353
],

guide/api-environment-frameworks.md

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# Environment API for Frameworks
1+
# フレームワーク向けの Environment API
22

3-
:::warning Experimental
4-
Initial work for this API was introduced in Vite 5.1 with the name "Vite Runtime API". This guide describes a revised API, renamed to Environment API. This API will be released in Vite 6 as experimental. You can already test it in the latest `[email protected]` version.
3+
:::warning 実験的機能
4+
この API の初期研究は、Vite 5.1 で「Vite ランタイム API」という名前で導入されました。このガイドでは、Environment API と改名された改訂版 API について説明します。この API Vite 6 で実験的機能としてリリースされる予定です。すでに最新の `[email protected]` バージョンでテストできます。
55

6-
Resources:
6+
リソース:
77

8-
- [Feedback discussion](https://github.com/vitejs/vite/discussions/16358) where we are gathering feedback about the new APIs.
9-
- [Environment API PR](https://github.com/vitejs/vite/pull/16471) where the new API were implemented and reviewed.
8+
- 新しい API に関するフィードバックを収集する [Feedback discussion](https://github.com/vitejs/vite/discussions/16358)
9+
- 新しい API が実装され、レビューされる [Environment API PR](https://github.com/vitejs/vite/pull/16471)
1010

11-
Please share with us your feedback as you test the proposal.
11+
この提案をテストする際には、ぜひフィードバックをお寄せください。
1212
:::
1313

14-
## Environments and frameworks
14+
## 環境とフレームワーク {#environments-and-frameworks}
1515

16-
The implicit `ssr` environment and other non-client environments use a `RunnableDevEnvironment` by default during dev. While this requires the runtime to be the same with the one the Vite server is running in, this works similarly with `ssrLoadModule` and allows frameworks to migrate and enable HMR for their SSR dev story. You can guard any runnable environment with an `isRunnableDevEnvironment` function.
16+
暗黙的な `ssr` 環境とその他の非クライアント環境では、開発中にデフォルトで `RunnableDevEnvironment` が使用されます。これには、Vite サーバーが実行しているのと同じランタイムが必要ですが、`ssrLoadModule` と同様に動作し、フレームワークが SSR 開発ストーリーの HMR を移行して有効にできるようにします。`isRunnableDevEnvironment` 関数を使用して、実行可能な環境をすべて保護できます。
1717

1818
```ts
1919
export class RunnableDevEnvironment extends DevEnvironment {
@@ -22,12 +22,12 @@ export class RunnableDevEnvironment extends DevEnvironment {
2222

2323
class ModuleRunner {
2424
/**
25-
* URL to execute. Accepts file path, server path, or id relative to the root.
26-
* Returns an instantiated module (same as in ssrLoadModule)
25+
* 実行するURL。ルートからの相対的なファイルパス、サーバーパス、ID を受け付けます。
26+
* インスタンス化されたモジュールを返します (ssrLoadModule と同じ)
2727
*/
2828
public async import(url: string): Promise<Record<string, any>>
2929
/**
30-
* Other ModuleRunner methods...
30+
* その他の ModuleRunner メソッド...
3131
*/
3232
}
3333

@@ -37,12 +37,12 @@ if (isRunnableDevEnvironment(server.environments.ssr)) {
3737
```
3838

3939
:::warning
40-
The `runner` is evaluated eagerly 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.
40+
`runner` は、初めてアクセスされたときに即座に評価されます。Vite は、`process.setSourceMapsEnabled` を呼び出して `runner` が作成されたとき、またはそれが利用できない場合は `Error.prepareStackTrace` をオーバーライドすることによって、ソースマップのサポートを有効にすることに注意してください。
4141
:::
4242

4343
## Default `RunnableDevEnvironment`
4444

45-
Given a Vite server configured in middleware mode as described by the [SSR setup guide](/guide/ssr#setting-up-the-dev-server), let's implement the SSR middleware using the environment API. Error handling is omitted.
45+
[SSR セットアップガイド](/guide/ssr#setting-up-the-dev-server)で説明されているように、ミドルウェアモードに設定された Vite サーバーがあるとして、Environment API を使って SSR ミドルウェアを実装してみましょう。エラー処理は省略します。
4646

4747
```js
4848
import { createServer } from 'vite'
@@ -52,60 +52,60 @@ const server = await createServer({
5252
appType: 'custom',
5353
environments: {
5454
server: {
55-
// by default, the modules are run in the same process as the vite dev server during dev
55+
// デフォルトでは、開発中はモジュールは vite 開発サーバーと同じプロセスで実行されます
5656
},
5757
},
5858
})
5959

60-
// You might need to cast this to RunnableDevEnvironment in TypeScript or use
61-
// the "isRunnableDevEnvironment" function to guard the access to the runner
60+
// TypeScript では、これを RunnableDevEnvironment にキャストするか、ランナーへのアクセスを
61+
// 保護するために "isRunnableDevEnvironment" 関数を使用する必要があるかもしれません
6262
const environment = server.environments.node
6363

6464
app.use('*', async (req, res, next) => {
6565
const url = req.originalUrl
6666

67-
// 1. Read index.html
67+
// 1. index.html を読み込む
6868
let template = fs.readFileSync(path.resolve(__dirname, 'index.html'), 'utf-8')
6969

70-
// 2. Apply Vite HTML transforms. This injects the Vite HMR client,
71-
// and also applies HTML transforms from Vite plugins, e.g. global
72-
// preambles from @vitejs/plugin-react
70+
// 2. Vite HTML 変換を適用します。これにより、Vite HMR クライアントが挿入され、
71+
// Vite プラグインからの HTML 変換も適用されます。
72+
// 例: global preambles from @vitejs/plugin-react
7373
template = await server.transformIndexHtml(url, template)
7474

75-
// 3. Load the server entry. import(url) automatically transforms
76-
// ESM source code to be usable in Node.js! There is no bundling
77-
// required, and provides full HMR support.
75+
// 3. サーバーエントリをロードします。import(url) は、
76+
// ESM ソースコードを Node.js で使用できるように自動的に変換します。
77+
// バンドルは不要で、完全な HMR サポートを提供します。
7878
const { render } = await environment.runner.import('/src/entry-server.js')
7979

80-
// 4. render the app HTML. This assumes entry-server.js's exported
81-
// `render` function calls appropriate framework SSR APIs,
82-
// e.g. ReactDOMServer.renderToString()
80+
// 4. アプリの HTML をレンダリングします。これは、entry-server.js のエクスポートされた
81+
// `render` 関数が適切なフレームワーク SSR API を呼び出すことを前提としています。
82+
// 例: ReactDOMServer.renderToString()
8383
const appHtml = await render(url)
8484

85-
// 5. Inject the app-rendered HTML into the template.
85+
// 5. アプリでレンダリングされた HTML をテンプレートに挿入します。
8686
const html = template.replace(`<!--ssr-outlet-->`, appHtml)
8787

88-
// 6. Send the rendered HTML back.
88+
// 6. レンダリングされた HTML を送信します。
8989
res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
9090
})
9191
```
9292

93-
## Runtime agnostic SSR
93+
## ランタイムに依存しない SSR {#runtime-agnostic-ssr}
9494

95-
Since the `RunnableDevEnvironment` can only be used to run the code in the same runtime as the Vite server, it requires a runtime that can run the Vite Server (a runtime that is compatible with Node.js). This means that you will need to use the raw `DevEnvironment` to make it runtime agnostic.
95+
`RunnableDevEnvironment` Vite サーバーと同じランタイムでコードを実行する目的のみで使用できるため、Vite サーバーを実行できるランタイム(Node.js と互換性のあるランタイム)が必要です。つまり、ランタイムに依存しないようにするには、生の `DevEnvironment` を使用する必要があります。
9696

97-
:::info `FetchableDevEnvironment` proposal
97+
:::info `FetchableDevEnvironment` プロポーザル
9898

99-
The initial proposal had a `run` method on the `DevEnvironment` class that would allow consumers to invoke an import on the runner side by using the `transport` option. During our testing we found out that the API was not universal enough to start recommending it. At the moment, we are looking for feedback on [the `FetchableDevEnvironment` proposal](https://github.com/vitejs/vite/discussions/18191).
99+
当初の提案では、`DevEnvironment` クラスに `run` メソッドがあり、利用者は `transport` オプションを使用してランナー側でインポートを呼び出すことができました。テスト中に、この API は推奨するには汎用性が足りないことがわかりました。現在、[`FetchableDevEnvironment` プロポーザル](https://github.com/vitejs/vite/discussions/18191)に関するフィードバックを募集しています。
100100

101101
:::
102102

103-
`RunnableDevEnvironment` has a `runner.import` function that returns the value of the module. But this function is not available in the raw `DevEnvironment` and requires the code using the Vite's APIs and the user modules to be decoupled.
103+
`RunnableDevEnvironment` には、モジュールの値を返す `runner.import` 関数があります。ただし、この関数は生の `DevEnvironment` では使用できず、Vite の API を使用するコードとユーザーモジュールを分離する必要があります。
104104

105-
For example, the following example uses the value of the user module from the code using the Vite's APIs:
105+
たとえば、次の例では、Vite の API を使用するコードからユーザーモジュールの値を使用しています:
106106

107107
```ts
108-
// code using the Vite's APIs
108+
// Vite の API を使用するコード
109109
import { createServer } from 'vite'
110110

111111
const server = createServer()
@@ -125,26 +125,26 @@ export function createHandler(input) {
125125
}
126126
```
127127

128-
If your code can run in the same runtime as the user modules (i.e., it does not rely on Node.js-specific APIs), you can use a virtual module. This approach eliminates the need to access the value from the code using Vite's APIs.
128+
ユーザーモジュールと同じランタイムでコードを実行できる場合(つまり、Node.js 固有の API に依存しない場合)、仮想モジュールを使用できます。このアプローチにより、Vite の API を使用してコードから値にアクセスする必要がなくなります。
129129

130130
```ts
131-
// code using the Vite's APIs
131+
// Vite の API を使用するコード
132132
import { createServer } from 'vite'
133133

134134
const server = createServer({
135135
plugins: [
136-
// a plugin that handles `virtual:entrypoint`
136+
// `virtual:entrypoint` を処理するプラグイン
137137
{
138138
name: 'virtual-module',
139-
/* plugin implementation */
139+
/* プラグインの実装 */
140140
},
141141
],
142142
})
143143
const ssrEnvironment = server.environment.ssr
144144
const input = {}
145145

146-
// use exposed functions by each environment factories that runs the code
147-
// check for each environment factories what they provide
146+
// コードを実行する各環境ファクトリーによって公開されている関数を使用します
147+
// 各環境ファクトリーについて、それらが提供するものをチェックします
148148
if (ssrEnvironment instanceof RunnableDevEnvironment) {
149149
ssrEnvironment.runner.import('virtual:entrypoint')
150150
} else if (ssrEnvironment instanceof CustomDevEnvironment) {
@@ -168,7 +168,7 @@ export function createHandler(input) {
168168
}
169169
```
170170

171-
For example, to call `transformIndexHtml` on the user module, the following plugin can be used:
171+
たとえば、ユーザーモジュールで `transformIndexHtml` を呼び出すには、次のプラグインを使用できます:
172172

173173
```ts {13-21}
174174
function vitePluginVirtualIndexHtml(): Plugin {
@@ -199,26 +199,26 @@ function vitePluginVirtualIndexHtml(): Plugin {
199199
}
200200
```
201201

202-
If your code requires Node.js APIs, you can use `hot.send` to communicate with the code that uses Vite's APIs from the user modules. However, be aware that this approach may not work the same way after the build process.
202+
コードに Node.js API が必要な場合は、`hot.send` を使用して、ユーザーモジュールから Vite の API を使用するコードと通信できます。ただし、このアプローチはビルドプロセス後に同じように機能しない可能性があることに注意してください。
203203

204204
```ts
205-
// code using the Vite's APIs
205+
// Vite の API を使用するコード
206206
import { createServer } from 'vite'
207207

208208
const server = createServer({
209209
plugins: [
210-
// a plugin that handles `virtual:entrypoint`
210+
// `virtual:entrypoint` を処理するプラグイン
211211
{
212212
name: 'virtual-module',
213-
/* plugin implementation */
213+
/* プラグインの実装 */
214214
},
215215
],
216216
})
217217
const ssrEnvironment = server.environment.ssr
218218
const input = {}
219219

220-
// use exposed functions by each environment factories that runs the code
221-
// check for each environment factories what they provide
220+
// コードを実行する各環境ファクトリーによって公開されている関数を使用します
221+
// 各環境ファクトリーについて、それらが提供するものをチェックします
222222
if (ssrEnvironment instanceof RunnableDevEnvironment) {
223223
ssrEnvironment.runner.import('virtual:entrypoint')
224224
} else if (ssrEnvironment instanceof CustomDevEnvironment) {
@@ -262,11 +262,11 @@ export function createHandler(input) {
262262
}
263263
```
264264

265-
## Environments during build
265+
## ビルド中の環境 {#environments-during-build}
266266

267-
In the CLI, calling `vite build` and `vite build --ssr` will still build the client only and ssr only environments for backward compatibility.
267+
CLI において、`vite build` `vite build --ssr` を呼び出すと、後方互換性のためにクライアントのみの環境と ssr のみの環境がビルドされます。
268268

269-
When `builder.entireApp` is `true` (or when calling `vite build --app`), `vite build` will opt-in into building the entire app instead. This would later on become the default in a future major. A `ViteBuilder` instance will be created (build-time equivalent to a `ViteDevServer`) to build all configured environments for production. By default the build of environments is run in series respecting the order of the `environments` record. A framework or user can further configure how the environments are built using:
269+
`builder.entireApp` `true` の場合(または `vite build --app` を呼び出した場合)、`vite build` はアプリ全体のビルドを行います。これは将来のメジャーバージョンではデフォルトになる予定です。`ViteBuilder` インスタンス(ビルド時の `ViteDevServer` に相当)が作成され、プロダクション環境用に設定されたすべての環境がビルドされます。デフォルトでは、環境のビルドは `environments` レコードの順番に従って直列に実行されます。フレームワークやユーザーは環境を構築する方法を設定できます:
270270

271271
```js
272272
export default {
@@ -281,6 +281,6 @@ export default {
281281
}
282282
```
283283

284-
## Environment agnostic code
284+
## 環境に依存しないコード {#environment-agnostic-code}
285285

286-
Most of the time, the current `environment` instance will be available as part of the context of the code being run so the need to access them through `server.environments` should be rare. For example, inside plugin hooks the environment is exposed as part of the `PluginContext`, so it can be accessed using `this.environment`. See [Environment API for Plugins](./api-environment-plugins.md) to learn about how to build environment aware plugins.
286+
ほとんどの場合、現在の `environment` インスタンスは実行中のコードのコンテキストの一部として利用できるため、`server.environments` を介してアクセスする必要はほとんどありません。たとえば、プラグインフック内では、環境は `PluginContext` の一部として公開されるため、`this.environment` を使用してアクセスできます。環境対応プラグインの構築方法については、[プラグイン向けの Environment API](./api-environment-plugins.md) を参照してください。

0 commit comments

Comments
 (0)