Skip to content

Commit 5853645

Browse files
committed
docs: translate ssr guide > buide config
1 parent 60dda5c commit 5853645

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

src/guide/ssr/build-config.md

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Build Configuration
1+
# ビルド設定
22

3-
The webpack config for an SSR project will be similar to a client-only project. If you're not familiar with configuring webpack, you can find more information in the documentation for [Vue CLI](https://cli.vuejs.org/guide/webpack.html#working-with-webpack) or [configuring Vue Loader manually](https://vue-loader.vuejs.org/guide/#manual-setup).
3+
SSR プロジェクトの webpack 設定は、クライアント用のプロジェクトと似ています。 webpack の設定に慣れていなければ、 [Vue CLI](https://cli.vuejs.org/guide/webpack.html#working-with-webpack) [Vue Loader の手動設定](https://vue-loader.vuejs.org/guide/#manual-setup) のドキュメントに詳しい情報があります。
44

5-
## Key Differences with Client-Only Builds
5+
## クライアント用ビルドとの主な相違点
66

7-
1. We need to create a [webpack manifest](https://webpack.js.org/concepts/manifest/) for our server-side code. This is a JSON file that webpack keeps to track how all the modules map to the output bundles.
7+
1. サーバサイドのコード用に [webpack マニフェスト](https://webpack.js.org/concepts/manifest/) を作成する必要があります。これは、すべてのモジュールが出力されたバンドルにどのようにマッピングされるかを追跡するため、 webpack が保持している JSON ファイルです。
88

9-
2. We should [externalize application dependencies](https://webpack.js.org/configuration/externals/). This makes the server build much faster and generates a smaller bundle file. When doing this, we have to exclude dependencies that need to be processed by webpack (like `.css`. or `.vue` files).
9+
2. [アプリケーションの依存関係を外部化](https://webpack.js.org/configuration/externals/) するべきです。これにより、サーバのビルドがずっと速くなり、バンドルしたファイルサイズも小さくなります。このとき、 webpack で処理する必要のある依存関係(`.css` `.vue` ファイルなど)を除外する必要があります。
1010

11-
3. We need to change webpack [target](https://webpack.js.org/concepts/targets/) to Node.js. This allows webpack to handle dynamic imports in a Node-appropriate fashion, and also tells `vue-loader` to emit server-oriented code when compiling Vue components.
11+
3. webpack [target](https://webpack.js.org/concepts/targets/) Node.js に変更する必要があります。これによって、 webpack Node に適した方法で動的インポートを扱うことができ、また `vue-loader` Vue コンポーネントをコンパイルするとき、サーバ向けのコードを出力するように指定できます。
1212

13-
4. When building a server entry, we would need to define an environment variable to indicate we are working with SSR. It might be helpful to add a few `scripts` to the project's `package.json`:
13+
4. サーバエントリをビルドする際には、 SSR で動作することを示す環境変数を定義する必要があります。プロジェクトの `package.json` にいくつか `scripts` を追加すると便利かもしれません:
1414

1515
```json
1616
"scripts": {
@@ -20,9 +20,9 @@ The webpack config for an SSR project will be similar to a client-only project.
2020
}
2121
```
2222

23-
## Example Configuration
23+
## 設定例
2424

25-
Below is a sample `vue.config.js` that adds SSR rendering to a Vue CLI project, but it can be adapted for any webpack build.
25+
以下は Vue CLI プロジェクトに SSR を追加する `vue.config.js` の例ですが、どのような webpack ビルドにも対応できます。
2626

2727
```js
2828
const { WebpackManifestPlugin } = require('webpack-manifest-plugin')
@@ -31,33 +31,33 @@ const webpack = require('webpack')
3131

3232
module.exports = {
3333
chainWebpack: webpackConfig => {
34-
// We need to disable cache loader, otherwise the client build
35-
// will used cached components from the server build
34+
// cache-loader の無効化が必要です。そうしないと、クライアントのビルドはサーバのビルドから
35+
// キャッシュされたコンポーネントを使ってしまいます。
3636
webpackConfig.module.rule('vue').uses.delete('cache-loader')
3737
webpackConfig.module.rule('js').uses.delete('cache-loader')
3838
webpackConfig.module.rule('ts').uses.delete('cache-loader')
3939
webpackConfig.module.rule('tsx').uses.delete('cache-loader')
4040

4141
if (!process.env.SSR) {
42-
// Point entry to your app's client entry file
42+
// クライアント用エントリファイルの基点
4343
webpackConfig
4444
.entry('app')
4545
.clear()
4646
.add('./src/entry-client.js')
4747
return
4848
}
4949

50-
// Point entry to your app's server entry file
50+
// サーバ用エントリファイルの基点
5151
webpackConfig
5252
.entry('app')
5353
.clear()
5454
.add('./src/entry-server.js')
5555

56-
// This allows webpack to handle dynamic imports in a Node-appropriate
57-
// fashion, and also tells `vue-loader` to emit server-oriented code when
58-
// compiling Vue components.
56+
// これにより webpack Node に適した方法で動的インポートを扱うことができ、
57+
// Vue コンポーネントをコンパイルするときに、
58+
// サーバ向けのコードを発行するように 'vue-loader' に指示します。
5959
webpackConfig.target('node')
60-
// This tells the server bundle to use Node-style exports
60+
// これは Node スタイルのエクスポートを使うようにサーバ用のバンドルに指示します。
6161
webpackConfig.output.libraryTarget('commonjs2')
6262

6363
webpackConfig
@@ -66,11 +66,11 @@ module.exports = {
6666

6767
// https://webpack.js.org/configuration/externals/#function
6868
// https://github.com/liady/webpack-node-externals
69-
// Externalize app dependencies. This makes the server build much faster
70-
// and generates a smaller bundle file.
69+
// アプリケーションの依存関係を外部化します。
70+
// これによりサーバでのビルドがずっと速くなり、バンドルしたファイルのサイズも小さくなります。
7171

72-
// Do not externalize dependencies that need to be processed by webpack.
73-
// You should also whitelist deps that modify `global` (e.g. polyfills)
72+
// webpack で処理する必要がある依存関係を外部化しないでください。
73+
// また `global` を変更する依存を許可リスト化する必要があります(Polyfill など)
7474
webpackConfig.externals(nodeExternals({ allowlist: /\.(css|vue)$/ }))
7575

7676
webpackConfig.optimization.splitChunks(false).minimize(false)
@@ -89,18 +89,18 @@ module.exports = {
8989
}
9090
```
9191

92-
## Externals Caveats
92+
## Externals の注意点
9393

94-
Notice that in the `externals` option we are whitelisting CSS files. This is because CSS imported from dependencies should still be handled by webpack. If you are importing any other types of files that also rely on webpack (e.g. `*.vue`, `*.sass`), you should add them to the whitelist as well.
94+
`externals` オプションでは、 CSS ファイルを許可リスト化していることに気づいてください。これは依存関係にあるファイルからインポートされた CSS は、 webpack によって処理されるべきだからです。もし webpack に依存する他の種類のファイル(`*.vue``*.sass` など)をインポートしているなら、同じように許可リストへ追加する必要があります。
9595

96-
If you are using `runInNewContext: 'once'` or `runInNewContext: true`, then you also need to whitelist polyfills that modify `global`, e.g. `babel-polyfill`. This is because when using the new context mode, **code inside a server bundle has its own `global` object.** Since you don't really need it on the server, it's actually easier to just import it in the client entry.
96+
`runInNewContext: 'once'` `runInNewContext: true` を使っている場合、 `global` を変更する Polyfill、例えば `babel-polyfill` を許可リストに登録する必要があります。これは New Context モードを使っている場合に **サーバ用のバンドル内のコードは独自の `global` オブジェクト** を持っているからです。サーバ上ではまったく必要ないため、 実際はクライアントのエントリでインポートするほうが簡単です。
9797

98-
## Generating `clientManifest`
98+
## `clientManifest` の生成
9999

100-
In addition to the server bundle, we can also generate a client build manifest. With the client manifest and the server bundle, the renderer now has information of both the server _and_ client builds. This way it can automatically infer and inject [preload / prefetch directives](https://css-tricks.com/prefetching-preloading-prebrowsing/), `<link>` and `<script>` tags into the rendered HTML.
100+
サーバ用のバンドルに加えて、クライアント用のビルドマニフェストも生成できます。クライアント用マニフェストとサーバ用バンドルによって、レンダラーは _サーバとクライアント両方の_ ビルドの情報を持つことになります。これによりレンダリングされた HTML に [preload / prefetch ディレクティブ](https://css-tricks.com/prefetching-preloading-prebrowsing/) `<link>``<script>` タグを自動的に推測して注入することができます。
101101

102-
The benefits are two-fold:
102+
利点は 2 つあります:
103103

104-
1. It can replace `html-webpack-plugin` for injecting the correct asset URLs when there are hashes in your generated filenames.
104+
1. 生成されたファイル名にハッシュがある場合、正しいアセットの URL を注入するため、 `html-webpack-plugin` を置き換えることができます。
105105

106-
2. When rendering a bundle that leverages webpack's on-demand code splitting features, we can ensure the optimal chunks are preloaded / prefetched, and also intelligently inject `<script>` tags for needed async chunks to avoid waterfall requests on the client, thus improving TTI (time-to-interactive).
106+
2. webpack のオンデマンドなコード分割機能を活用したバンドルをレンダリングするときに、最適なチャンクがプリロード・プリフェッチされるようにします。また、必要な非同期チャンクに対しては賢く `<script>` タグを注入することで、クライアントでのウォーターフォールリクエストを回避し、 TTI (time-to-interactive) を向上させることができます。

0 commit comments

Comments
 (0)