Skip to content

Commit 321eb1a

Browse files
sugoikondosmikitky
authored andcommitted
Translate Code-Splitting (#58)
* WIP translating. * translate complete * lint * fix statements on Browserify. * delete unnessesary statements. * delete unnessesary statements. * fix typo * fix typo * Apply suggestions from code review Co-Authored-By: atsumine <[email protected]> * fix breakings. * Apply suggestions from code review Co-Authored-By: atsumine <[email protected]> * fix suggestions. * fix mistranslation on webpack configuration
1 parent f5c67a7 commit 321eb1a

File tree

1 file changed

+56
-67
lines changed

1 file changed

+56
-67
lines changed

content/docs/code-splitting.md

+56-67
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
22
id: code-splitting
3-
title: Code-Splitting
3+
title: コード分割
44
permalink: docs/code-splitting.html
55
---
66

7-
## Bundling {#bundling}
7+
## バンドル {#bundling}
88

9-
Most React apps will have their files "bundled" using tools like
10-
[Webpack](https://webpack.js.org/) or [Browserify](http://browserify.org/).
11-
Bundling is the process of following imported files and merging them into a
12-
single file: a "bundle". This bundle can then be included on a webpage to load
13-
an entire app at once.
9+
多くの React アプリケーションは、[Webpack](https://webpack.js.org/)[Browserify](http://browserify.org/) などの
10+
ツールを使ってファイルを「バンドル」しています。
11+
バンドルはインポートされたファイルをたどって、それらを 1 つのファイルにまとめるプロセスです。
12+
このバンドルされたファイルを Web ページ内に置くことによって、アプリ全体を一度に読み込むことができます。
1413

15-
#### Example {#example}
14+
#### {#example}
1615

1716
**App:**
1817

@@ -40,42 +39,36 @@ function add(a, b) {
4039
console.log(add(16, 26)); // 42
4140
```
4241

43-
> Note:
42+
> 補足:
4443
>
45-
> Your bundles will end up looking a lot different than this.
44+
> 実際のバンドルはこれとは大幅に異なった見た目になります。
4645
47-
If you're using [Create React App](https://github.com/facebookincubator/create-react-app), [Next.js](https://github.com/zeit/next.js/), [Gatsby](https://www.gatsbyjs.org/), or a similar tool, you will have a Webpack setup out of the box to bundle your
48-
app.
46+
もしあなたが [Create React App](https://github.com/facebookincubator/create-react-app)[Next.js](https://github.com/zeit/next.js/), [Gatsby](https://www.gatsbyjs.org/) またはこれらに類するツールを使用している場合、
47+
アプリケーションをバンドルするための Webpack の設定が、追加の設定なしにすぐに手に入るでしょう。
4948

50-
If you aren't, you'll need to setup bundling yourself. For example, see the
51-
[Installation](https://webpack.js.org/guides/installation/) and
52-
[Getting Started](https://webpack.js.org/guides/getting-started/) guides on the
53-
Webpack docs.
49+
そうでない場合は、自分でバンドルを設定する必要があります。
50+
設定方法に関しては、Webpack のドキュメントにある [Installation](https://webpack.js.org/guides/installation/)
51+
[Getting Started](https://webpack.js.org/guides/getting-started/) などを
52+
参照してみてください。
5453

55-
## Code Splitting {#code-splitting}
54+
## コード分割 {#code-splitting}
5655

57-
Bundling is great, but as your app grows, your bundle will grow too. Especially
58-
if you are including large third-party libraries. You need to keep an eye on
59-
the code you are including in your bundle so that you don't accidentally make
60-
it so large that your app takes a long time to load.
56+
バンドルは確かに素晴らしいですが、アプリが大きくなるにつれて、バンドルのサイズも大きくなります。
57+
特にサイズの大きなサードパーティ製のライブラリを含む場合は顕著にサイズが増大します。
58+
不用意に大きなバンドルを作成してしまいアプリの読み込みに多くの時間がかかってしまうという事態にならないためにも、
59+
常に注意を払い続けなければなりません。
6160

62-
To avoid winding up with a large bundle, it's good to get ahead of the problem
63-
and start "splitting" your bundle.
64-
[Code-Splitting](https://webpack.js.org/guides/code-splitting/) is a feature
65-
supported by bundlers like Webpack and Browserify (via
66-
[factor-bundle](https://github.com/browserify/factor-bundle)) which can create
67-
multiple bundles that can be dynamically loaded at runtime.
61+
大きなバンドルを不注意に生成してしまわないように、あらかじめコードを「分割」して問題を回避しましょう。
62+
[Code-Splitting](https://webpack.js.org/guides/code-splitting/) は、実行時にロードする複数のバンドルを生成できる Webpack や Browserify([factor-bundle](https://github.com/browserify/factor-bundle) を使用)などのバンドラによってサポートされている機能です。
6863

69-
Code-splitting your app can help you "lazy-load" just the things that are
70-
currently needed by the user, which can dramatically improve the performance of
71-
your app. While you haven't reduced the overall amount of code in your app,
72-
you've avoided loading code that the user may never need, and reduced the amount
73-
of code needed during the initial load.
64+
コード分割は、ユーザが必要とするコードだけを「遅延読み込み」する手助けとなり、
65+
アプリのパフォーマンスを劇的に向上させることができます。
66+
アプリの全体的なコード量を減らすことはできませんが、ユーザが必要としないコードを読み込まなくて済むため、
67+
初期ロードの際に読む込むコード量を削減できます。
7468

7569
## `import()` {#import}
7670

77-
The best way to introduce code-splitting into your app is through the dynamic
78-
`import()` syntax.
71+
コード分割をアプリに導入する最も良い手段は動的な `import()` 構文を使用することです。
7972

8073
**Before:**
8174

@@ -93,31 +86,29 @@ import("./math").then(math => {
9386
});
9487
```
9588

96-
> Note:
89+
> 補足:
9790
>
98-
> The dynamic `import()` syntax is a ECMAScript (JavaScript)
99-
> [proposal](https://github.com/tc39/proposal-dynamic-import) not currently
100-
> part of the language standard. It is expected to be accepted in the
101-
> near future.
91+
> `import()` 構文は ECMAScript (JavaScript) における[提案中](https://github.com/tc39/proposal-dynamic-import)の構文であり、
92+
> 現時点ではまだ言語標準となっていません。
93+
> 近い将来での標準化が期待されています。
10294
103-
When Webpack comes across this syntax, it automatically starts code-splitting
104-
your app. If you're using Create React App, this is already configured for you
105-
and you can [start using it](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting) immediately. It's also supported
106-
out of the box in [Next.js](https://github.com/zeit/next.js/#dynamic-import).
95+
Webpackがこの構文を見つけると、自動的にアプリのコードを分割します。
96+
Create React App を使用している場合はすでに設定がされているため、[すぐに使用を開始することができます。](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting)
97+
Next.jsも同様です。
10798

108-
If you're setting up Webpack yourself, you'll probably want to read Webpack's
109-
[guide on code splitting](https://webpack.js.org/guides/code-splitting/). Your Webpack config should look vaguely [like this](https://gist.github.com/gaearon/ca6e803f5c604d37468b0091d9959269).
99+
もし Webpack を自分でセットアップしていた場合には、Webpack[コード分割に関するガイド](https://webpack.js.org/guides/code-splitting/)を読むと良いでしょう。
100+
きっとあなたの Webpack の設定はだいたい[このように](https://gist.github.com/gaearon/ca6e803f5c604d37468b0091d9959269)なると思います。
110101

111-
When using [Babel](http://babeljs.io/), you'll need to make sure that Babel can
112-
parse the dynamic import syntax but is not transforming it. For that you will need [babel-plugin-syntax-dynamic-import](https://yarnpkg.com/en/package/babel-plugin-syntax-dynamic-import).
102+
もし [Babel](http://babeljs.io/) を使用している場合は、Babel が動的インポート構文をパースできても変換してしまわないようにする必要があります。
103+
そのためには [babel-plugin-syntax-dynamic-import](https://yarnpkg.com/en/package/babel-plugin-syntax-dynamic-import) を利用すると良いでしょう。
113104

114105
## `React.lazy` {#reactlazy}
115106

116-
> Note:
107+
> 補足:
117108
>
118-
> `React.lazy` and Suspense is not yet available for server-side rendering. If you want to do code-splitting in a server rendered app, we recommend [Loadable Components](https://github.com/smooth-code/loadable-components). It has a nice [guide for bundle splitting with server-side rendering](https://github.com/smooth-code/loadable-components/blob/master/packages/server/README.md).
109+
> `React.lazy` Suspense はまだサーバーサイドレンダリングには使用できません。サーバーサイドでレンダリングされたアプリでコード分割をしたい場合には、[Loadable Components](https://github.com/smooth-code/loadable-components) の使用をおすすめします。こちらは[サーバーサイドレンダリングでのバンドル分割のための素晴らしいガイド](https://github.com/smooth-code/loadable-components/blob/master/packages/server/README.md)も提供していくれているので、参考にしてみてください。
119110
120-
The `React.lazy` function lets you render a dynamic import as a regular component.
111+
`React.lazy` 関数を使用すると、動的インポートを通常のコンポーネントとしてレンダリングすることができます。
121112

122113
**Before:**
123114

@@ -147,13 +138,13 @@ function MyComponent() {
147138
}
148139
```
149140

150-
This will automatically load the bundle containing the `OtherComponent` when this component gets rendered.
141+
このコンポーネントがレンダリングされる際には、`OtherComponent` を含むバンドルを自動的にロードしてくれます。
151142

152-
`React.lazy` takes a function that must call a dynamic `import()`. This must return a `Promise` which resolves to a module with a `default` export containing a React component.
143+
`React.lazy` は動的インポート構文 `import()` を呼び出す関数を引数として取ります。この関数は React コンポーネントを含む `default` export を持つモジュールに解決される `Promise` を返さなければなりません。
153144

154145
### Suspense {#suspense}
155146

156-
If the module containing the `OtherComponent` is not yet loaded by the time `MyComponent` renders, we must show some fallback content while we're waiting for it to load - such as a loading indicator. This is done using the `Suspense` component.
147+
`MyComponent` がレンダリングされるまでに、`OtherComponent` を含むモジュールがまだロードされていない場合、例えばロードインジケータなどのようなフォールバックコンテンツをロードが完了するまで表示する必要があります。これは `Suspense` コンポーネントを使って実装することができます。
157148

158149
```js
159150
const OtherComponent = React.lazy(() => import('./OtherComponent'));
@@ -169,7 +160,7 @@ function MyComponent() {
169160
}
170161
```
171162

172-
The `fallback` prop accepts any React elements that you want to render while waiting for the component to load. You can place the `Suspense` component anywhere above the lazy component. You can even wrap multiple lazy components with a single `Suspense` component.
163+
`fallback` プロパティはコンポーネントがロードされるのを待っている間に表示したいあらゆる React 要素を受け取ります。`Suspense` コンポーネントは遅延コンポーネントより上位のどこにでも配置することができます。また、複数の遅延コンポーネントを単一の `Suspense` コンポーネントでラップすることもできます。
173164

174165
```js
175166
const OtherComponent = React.lazy(() => import('./OtherComponent'));
@@ -191,7 +182,7 @@ function MyComponent() {
191182

192183
### Error boundaries {#error-boundaries}
193184

194-
If the other module fails to load (for example, due to network failure), it will trigger an error. You can handle these errors to show a nice user experience and manage recovery with [Error Boundaries](/docs/error-boundaries.html). Once you've created your Error Boundary, you can use it anywhere above your lazy components to display an error state when there's a network error.
185+
もし他のモジュールがロードに失敗した場合(例えば、ネットワークの障害など)、エラーが発生します。その際には [Error Boundaries](/docs/error-boundaries.html) を使用することによってこれらのエラーをハンドリングし、エラーの回復やユーザ体験の向上に繋げることができます。Error Boundary を作成したら、遅延コンポーネントより上位のあらゆる場所で使用でき、ネットワークエラーが発生した際にエラー内容を表示することができます。
195186

196187
```js
197188
import MyErrorBoundary from './MyErrorBoundary';
@@ -212,19 +203,17 @@ const MyComponent = () => (
212203
);
213204
```
214205

215-
## Route-based code splitting {#route-based-code-splitting}
206+
## ルーティング単位でのコード分割 {#route-based-code-splitting}
216207

217-
Deciding where in your app to introduce code splitting can be a bit tricky. You
218-
want to make sure you choose places that will split bundles evenly, but won't
219-
disrupt the user experience.
208+
アプリ内のどこにコード分割を導入するかを決めるのは少し面倒です。
209+
バンドルを均等に分割する場所を確実に選択したいところですが、ユーザ体験を妨げてはなりません。
220210

221-
A good place to start is with routes. Most people on the web are used to
222-
page transitions taking some amount of time to load. You also tend to be
223-
re-rendering the entire page at once so your users are unlikely to be
224-
interacting with other elements on the page at the same time.
211+
コード分割を導入するにあたって適している場所はルーティングです。
212+
Web を使用するほとんどの人は、多少のロード時間がかかるページ遷移に慣れています。
213+
また、ユーザがページ上の他の要素を同時に操作する可能性を減らすよう、ページ全体を一度に再レンダーすることが多いでしょう。
225214

226-
Here's an example of how to setup route-based code splitting into your app using
227-
libraries like [React Router](https://reacttraining.com/react-router/) with `React.lazy`.
215+
これは [React Router](https://reacttraining.com/react-router/) のようなライブラリを使ったアプリに `React.lazy` を使用することで
216+
ルーティングベースのコード分割を導入する方法の例です。
228217

229218
```js
230219
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
@@ -245,9 +234,9 @@ const App = () => (
245234
);
246235
```
247236

248-
## Named Exports {#named-exports}
237+
## 名前付きエクスポート {#named-exports}
249238

250-
`React.lazy` currently only supports default exports. If the module you want to import uses named exports, you can create an intermediate module that reexports it as the default. This ensures that treeshaking keeps working and that you don't pull in unused components.
239+
`React.lazy` は現在デフォルトエクスポートのみサポートしています。インポートしたいモジュールが名前付きエクスポートを使用している場合、それをデフォルトとして再エクスポートする中間モジュールを作成できます。これにより、tree shaking が機能し未使用のコンポーネントを取り込まず済むようにできます。
251240

252241
```js
253242
// ManyComponents.js

0 commit comments

Comments
 (0)