Skip to content

Commit 039503d

Browse files
committed
docs: translate ssr guide > structure
1 parent 9632e93 commit 039503d

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/guide/ssr/structure.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Source Code Structure
1+
# ソースコードの構造
22

3-
## Avoid Stateful Singletons
3+
## ステートフルなシングルトンの回避
44

5-
When writing client-only code, we can assume that our code will be evaluated in a fresh context every time. However, a Node.js server is a long-running process. When our code is first imported by the process, it will be evaluated once and then stay in memory. This means that if you create a singleton object, it will be shared between every incoming request, with the risk of cross-request state pollution.
5+
クライアントのみのコードを書くとき、コードは毎回新しいコンテキストで評価されると考えることができます。しかし、 Node.js サーバは長時間実行されるプロセスです。コードがプロセスにはじめて要求されるとき、コードは一度評価されメモリ内にとどまります。つまり、シングルトンのオブジェクトを作成すると、すべての受信リクエストの間で共有されることになり、リクエスト間での状態の汚染リスクがあるということです。
66

7-
Therefore, we need to **create a new root Vue instance for each request.** In order to do that, we need to write a factory function that can be repeatedly executed to create fresh app instances for each request:
7+
よって、 **リクエストごとに新しいルート Vue インスタンスを作成する** 必要があります。そのためには、リクエストごとに新しいアプリケーションのインスタンスを作成する、繰り返し実行可能なファクトリ関数を書く必要があります:
88

99
```js
1010
// app.js
@@ -22,7 +22,7 @@ function createApp() {
2222
}
2323
```
2424

25-
And our server code now becomes:
25+
そして、サーバコードはこのようになります:
2626

2727
```js
2828
// server.js
@@ -49,48 +49,48 @@ server.get('*', async (req, res) => {
4949
server.listen(8080)
5050
```
5151

52-
The same rule applies to other instances as well (such as the router or store). Instead of exporting the router or store directly from a module and importing it across your app, you should create a fresh instance in `createApp` and inject it from the root Vue instance.
52+
同じルールが他のインスタンス(ルータやストアなど)にも当てはまります。ルータやストアをモジュールから直接エクスポートしてアプリケーション全体にインポートするのではなく、 `createApp` で新しいインスタンスを作成して、ルート Vue インスタンスから注入する必要があります。
5353

54-
## Introducing a Build Step
54+
## ビルド手順の導入
5555

56-
So far, we haven't discussed how to deliver the same Vue app to the client yet. To do that, we need to use webpack to bundle our Vue app.
56+
ここまでは、同じ Vue アプリケーションをクライアントに配信する方法をまだ説明していませんでした。そのためには、 webpack Vue アプリケーションのバンドルが必要です。
5757

58-
- We need to process the server code with webpack. For example, `.vue` files need to be processed with `vue-loader`, and many webpack-specific features such as importing files via `file-loader` or importing CSS via `css-loader` do not work directly in Node.js.
58+
- サーバコードを webpack で処理する必要があります。例えば、 `.vue` ファイルは `vue-loader` の処理が必要で、 `file-loader` でのファイルのインポートや、 `css-loader` での CSS のインポートなど、多くの webpack 固有の機能は Node.js で直接動作しません。
5959

60-
- Similarly, we need a separate client-side build because although the latest version of Node.js fully supports ES2015 features, older browsers will require the code to be transpiled.
60+
- 同じように、最新の Node.js ES2015 の機能を完全にサポートしていますが、古いブラウザではコードのトランスパイルが必要で、クライアントサイドのビルドも別に行う必要があります。
6161

62-
So the basic idea is that we will use webpack to bundle our app for both client and server. The server bundle will be required on the server and used to render static HTML, while the client bundle will be sent to the browser to hydrate the static markup.
62+
基本的な考え方は、 webpack でアプリケーションをクライアントとサーバの両方にバンドルすることです。サーバ用のバンドルは、サーバ上で静的な HTML をレンダリングするために使われ、クライアント用のバンドルは、静的なマークアップを Hydrate(ハイドレート)するためにブラウザに送信されます。
6363

6464
![architecture](https://cloud.githubusercontent.com/assets/499550/17607895/786a415a-5fee-11e6-9c11-45a2cfdf085c.png)
6565

66-
We will discuss the details of the setup in later sections - for now, let's just assume we've got the build setup figured out and we can write our Vue app code with webpack enabled.
66+
セットアップの詳細については後のセクションで説明しますが、ここではビルドのセットアップが完了して、 webpack を有効にした Vue アプリケーションのコードが書けるようになったと仮定してみます。
6767

68-
## Code Structure with webpack
68+
## webpack によるコード構造
6969

70-
Now that we are using webpack to process the app for both server and client, the majority of our source code can be written in a universal fashion, with access to all the webpack-powered features. At the same time, there are a number of things you should keep in mind when [writing universal code](./universal.html).
70+
サーバとクライアントの両方のアプリケーションを処理するのに webpack を使うようになったため、ソースコードの大部分はユニバーサルな方法で書くことができ、すべての webpack の機能にアクセスすることができます。同時に、 [ユニバーサルなコードを書く](./universal.html) ときに留意すべき点がいくつかあります。
7171

72-
A simple project would look like this:
72+
簡単なプロジェクトはこのようなものです:
7373

7474
```bash
7575
src
7676
├── components
7777
│ ├── MyUser.vue
7878
│ └── MyTable.vue
7979
├── App.vue
80-
├── app.js # universal entry
81-
├── entry-client.js # runs in browser only
82-
└── entry-server.js # runs on server only
80+
├── app.js # 共通のエントリ
81+
├── entry-client.js # ブラウザでのみ実行
82+
└── entry-server.js # サーバでのみ実行
8383
```
8484

8585
### `app.js`
8686

87-
`app.js` is the universal entry to our app. In a client-only app, we would create the Vue application instance right in this file and mount directly to DOM. However, for SSR that responsibility is moved into the client-only entry file. `app.js` instead creates an application instance and exports it:
87+
`app.js` は、アプリケーションの共通のエントリです。クライアント専用のアプリケーションでは、このファイルの中で Vue アプリケーションのインスタンスを作成して、 DOM に直接マウントします。しかし SSR では、その責務はクライアント専用のエントリファイルに移されます。代わりに `app.js` でアプリケーションのインスタンスを作成して、エクスポートします:
8888

8989
```js
9090
import { createSSRApp } from 'vue'
9191
import App from './App.vue'
9292

93-
// export a factory function for creating a root component
93+
// ルートコンポーネントを作成するためのファクトリ関数をエクスポート
9494
export default function(args) {
9595
const app = createSSRApp(App)
9696

@@ -102,24 +102,24 @@ export default function(args) {
102102

103103
### `entry-client.js`
104104

105-
The client entry creates the application using the root component factory and mounts it to the DOM:
105+
クライアント用のエントリは、ルートコンポーネントのファクトリを使ってアプリケーションを作成し、 DOM にマウントします:
106106

107107
```js
108108
import createApp from './app'
109109

110-
// client-specific bootstrapping logic...
110+
// クライアント固有の初回起動ロジック
111111

112112
const { app } = createApp({
113-
// here we can pass additional arguments to app factory
113+
// ここでアプリケーションのファクトリに追加の引数を渡すことが可能
114114
})
115115

116-
// this assumes App.vue template root element has `id="app"`
116+
// これは App.vue テンプレートのルート要素に `id="app"` が前提
117117
app.mount('#app')
118118
```
119119

120120
### `entry-server.js`
121121

122-
The server entry uses a default export which is a function that can be called repeatedly for each render. At this moment, it doesn't do much other than returning the app instance - but later we will perform server-side route matching and data pre-fetching logic here.
122+
サーバ用のエントリは、レンダリングごとに繰り返し呼び出される関数を default でエクスポートします。いまのところは、アプリケーションのインスタンスを返す以外の機能はありませんが、あとでサーバサイドのルートマッチングやデータのプリフェッチのロジックをここに加えます。
123123

124124
```js
125125
import createApp from './app'

0 commit comments

Comments
 (0)