-
Notifications
You must be signed in to change notification settings - Fork 87
Guide> Production Deployment の翻訳 #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e7da364
feat: add guide > production deployment
naokie 85bb0ca
feat: activate link to guide > production deployment
naokie f0a5eb4
docs: translate guide > production deployment
naokie dda1137
Merge branch 'lang-ja' into guide/tooling/deployment
naokie c5f4be3
fix: translate 'minified version'
naokie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# 実運用への展開 | ||
|
||
::: info | ||
以下のヒントのほとんどは、 [Vue CLI](https://cli.vuejs.org) を使っている場合、デフォルトで有効になっています。このセクションは、カスタムビルドのセットアップを使っている場合にのみ関連します。 | ||
::: | ||
|
||
## プロダクションモードをオンにする | ||
|
||
開発中、 Vue は一般的なエラーや落とし穴に役立つたくさんの警告を提供しています。しかし、これらの警告文は実運用では役に立たず、アプリケーションのペイロードの大きさを肥大化させてしまいます。 さらに、これらの警告チェックの中には、 [プロダクションモード](https://cli.vuejs.org/guide/mode-and-env.html#modes) では避けることのできる小さなランタイムコストがあります。 | ||
|
||
### ビルドツールなし | ||
|
||
フルビルドを使う場合、つまりビルドツールを使わずに script タグで Vue を直接含める場合は、必ず 縮小バージョン (minified version:コードが小さくされたバージョン) を本番で使ってください。これは、 [インストールガイド](/guide/installation.html#cdn) に記載されています。 | ||
|
||
### ビルドツールあり | ||
|
||
Webpack や Browserify などのビルドツールを使う場合は、プロダクションモードは Vue のソースコード内の `process.env.NODE_ENV` で決定され、デフォルトでは開発モードになります。どちらのビルドツールも、 Vue のプロダクションモードを有効にするために、この変数を上書きする方法を提供しており、警告はビルド中に Minifier (圧縮・軽量化) によって取り除かれます。Vue CLI では事前設定されていますが、どのように行われているか知っておくことはよいでしょう: | ||
|
||
#### Webpack | ||
|
||
Webpack 4+ では、 `mode` オプションを使えます: | ||
|
||
```js | ||
module.exports = { | ||
mode: 'production' | ||
} | ||
``` | ||
|
||
#### Browserify | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 独り言: |
||
|
||
- 実際の `NODE_ENV` 環境変数に `"production"` を設定して、バンドルコマンドを実行してください。これは `vueify` にホットリロードや開発関連のコードを含まないように指示します。 | ||
|
||
- バンドルにグローバルな [envify](https://github.com/hughsk/envify) の変換を適用します。これにより、 Minifier は環境変数の条件ブロックに含まれた Vue のソースコードのすべての警告を取り除くことができます。例えば: | ||
|
||
```bash | ||
NODE_ENV=production browserify -g envify -e main.js | uglifyjs -c -m > build.js | ||
``` | ||
|
||
- または、 [envify](https://github.com/hughsk/envify) を Gulp で使うと: | ||
|
||
```js | ||
// envify のカスタムモジュールで環境変数を指定 | ||
const envify = require('envify/custom') | ||
|
||
browserify(browserifyOptions) | ||
.transform(vueify) | ||
.transform( | ||
// node_modules ファイルを処理するために必要 | ||
{ global: true }, | ||
envify({ NODE_ENV: 'production' }) | ||
) | ||
.bundle() | ||
``` | ||
|
||
- または、 [envify](https://github.com/hughsk/envify) を Grunt と [grunt-browserify](https://github.com/jmreidy/grunt-browserify) で使うと: | ||
|
||
```js | ||
// envify のカスタムモジュールで環境変数を指定 | ||
const envify = require('envify/custom') | ||
|
||
browserify: { | ||
dist: { | ||
options: { | ||
// grunt-browserify のデフォルトの順序からはずれる関数 | ||
configure: (b) => | ||
b | ||
.transform('vueify') | ||
.transform( | ||
// node_modules ファイルを処理するために必要 | ||
{ global: true }, | ||
envify({ NODE_ENV: 'production' }) | ||
) | ||
.bundle() | ||
} | ||
} | ||
} | ||
``` | ||
|
||
#### Rollup | ||
|
||
[@rollup/plugin-replace](https://github.com/rollup/plugins/tree/master/packages/replace) を使ってください: | ||
|
||
```js | ||
const replace = require('@rollup/plugin-replace') | ||
|
||
rollup({ | ||
// ... | ||
plugins: [ | ||
replace({ | ||
'process.env.NODE_ENV': JSON.stringify( 'production' ) | ||
}) | ||
] | ||
}).then(...) | ||
``` | ||
|
||
## テンプレートのプリコンパイル | ||
|
||
DOM 内のテンプレートや、 JavaScript 内のテンプレートリテラルを使う場合、テンプレートからレンダリング関数へのコンパイルは実行時に行われます。ほとんどの場合、この方法で十分な速度が得られますが、アプリケーションがパフォーマンスを重視される場合は避けたほうがよいです。 | ||
naokie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
テンプレートをプリコンパイルする最も簡単な方法は、 [単一ファイルコンポーネント](/guide/single-file-component.html) を使うことです。これは関連するビルドセットアップが自動的にプリコンパイルを行います。これにより、ビルドされたコードは生のテンプレート文字列ではなく、すでにコンパイルされたレンダリング関数が含まれることになります。 | ||
|
||
Webpack を使っていて、 JavaScript とテンプレートファイルを分離したい場合は、 [vue-template-loader](https://github.com/ktsn/vue-template-loader) を使うと、ビルドステップでテンプレートファイルを JavaScript のレンダリング関数に変換することもできます。 | ||
|
||
## コンポーネントの CSS を抽出 | ||
|
||
単一ファイルコンポーネントを使う場合、コンポーネント内の CSS は JavaScript を介して `<style>` タグとして動的に差し込まれます。これにはわずかなランタイムコストがかかります。また、サーバーサイドレンダリングを使っている場合は、「瞬間的にスタイルのないコンテンツ」を引き起こします。同じファイルにすべてのコンポーネントの CSS を抽出することで、このような問題を回避して、よりよい CSS の最小化やキャッシュ化をすることができます。 | ||
naokie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
その方法については、各ビルドツールのドキュメントを参照してください: | ||
|
||
- [Webpack + vue-loader](https://vue-loader.vuejs.org/en/configurations/extract-css.html) (`vue-cli` の Webpack テンプレートには、これがあらかじめ設定されています) | ||
- [Browserify + vueify](https://github.com/vuejs/vueify#css-extraction) | ||
- [Rollup + rollup-plugin-vue](https://rollup-plugin-vue.vuejs.org/) | ||
|
||
## ランタイムエラーの追跡 | ||
|
||
コンポーネントのレンダリング中にランタイムエラーが発生した場合、グローバルの `app.config.errorHandler` に設定した関数があれば、それに渡されます。Vue の [公式インテグレーション](https://sentry.io/for/vue/) を提供している [Sentry](https://sentry.io) のようなエラー追跡サービスと一緒にこのフックを活用するのはよいアイデアかもしれません。 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
独り言:
原文も
Browserify
って書いてあるのか。(今、Vue アプリケーションを Browserify でバンドルしているのないと思うんだけど... vueify もメンテしてないし https://github.com/vuejs/vueify)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
自分も翻訳していて、まだ Browserify?って思っちゃいました。
バンドラーもメンテしてないんですね。これはちょと本家に提案をコミットするチャンスかな。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
そうですね。これはコミットチャンスですね。
結構、大きく変わる部分なので、英語でやり取りが大変だと思いますが。
Browserify の代わりの載せるとしたら、Vite でしょうかね。