Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit d27ade8

Browse files
authored
Merge pull request #75 from cosnomi/translate-static-folder
Translate docs/static-folder
2 parents c483317 + bc1481a commit d27ade8

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

docs/docs/static-folder.md

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
---
2-
title: Using the Static Folder
2+
title: static フォルダーを使う
33
---
44

5-
In general, every website needs assets: images, stylesheets, scripts, etc. When using Gatsby, we recommend
6-
[Importing Assets Directly](/docs/importing-assets-into-files/) in JavaScript files, because of the benefits it provides:
5+
通常、すべてのウェブサイトにはアセット(画像・スタイルシート・スクリプトなど)が必要です。Gatsby を使うときは、JavaScript ファイルで[アセットを直接インポートする](/docs/importing-assets-into-files/)ことをおすすめします。それは次のような利点があるためです。
76

8-
- Scripts and stylesheets are minified and bundled together to avoid extra network requests.
9-
- Missing files cause compilation errors instead of 404 errors for your users.
10-
- Result filenames include content hashes so you don’t need to worry about browsers caching their old versions.
7+
- スクリプトやスタイルシートが最小化されバンドルされます。これにより、余分なネットワークリクエストを防ぐことができます。
8+
- 存在しないファイルはコンパイルエラーを引き起こすので、ユーザーに 404 エラーを引き起こしません。
9+
- ファイル名にハッシュが付加されるので、ブラウザーの古いバージョンのキャッシュについて心配する必要がなくなります。
1110

12-
However, there is an **escape hatch** that you can use to add an asset outside of the module system.
11+
しかし、モジュールシステムを使わずにアセットを追加することもできます。
1312

14-
## Adding assets outside of the module system
13+
## モジュールシステムを使わずにアセットを追加する
1514

16-
You can create a folder named `static` at the root of your project. Every file you put into that folder will be copied into the `public` folder. E.g. if you add a file named `sun.jpg` to the static folder, it'll be copied to `public/sun.jpg`
15+
あなたのプロジェクトのルートに `static` という名前のフォルダーを作成すると、その中のすべてのファイルは `public` フォルダーにコピーされます。例えば、`sun.jpg` というファイルを static フォルダーに追加すると、それは `public/sun.jpg` にコピーされます。
1716

18-
### Referencing your static asset
17+
### static アセットを参照する
1918

20-
You can reference assets from the `static` folder in your code without anything special required:
19+
`static` フォルダーのアセットはそのまま参照できます。
2120

2221
```jsx
2322
render() {
24-
// Note: this is an escape hatch and should be used sparingly!
25-
// Normally we recommend using `import` for getting asset URLs
26-
// as described in the “Importing Assets Directly Into Files” page.
23+
// 注意: これは非推奨の方法なので、節度を持って利用されるべきです。
24+
// 通常は、`import` を利用してアセットURLを取得することをおすすめします。
25+
// その方法は、"アセットをファイルに直接インポートする"ページで説明されています。
2726
return <img src={'/logo.png'} alt="Logo" />;
2827
}
2928
```
@@ -33,24 +32,21 @@ render() {
3332
lessonTitle="Use a local image from the static folder in a Gatsby component"
3433
/>
3534

36-
### Downsides
35+
### デメリット
3736

38-
Keep in mind the downsides of this approach:
37+
この方法には以下のようなデメリットがあることを念頭に置いてください。
3938

40-
- None of the files in the `static` folder will be post-processed or minified.
41-
- Missing files will not be called at compilation time, and will cause 404 errors for your users.
42-
- Result filenames won’t include content hashes, so you’ll need to add query arguments or rename them every time they change.
39+
- `static` フォルダーの中のファイルは後処理されたり最小化されることはありません。
40+
- 存在しないファイルはコンパイルエラーを起こすことなく、ユーザーに対して 404 エラーを発生させます。
41+
- 最終的なファイル名には内容に基づくハッシュが含まれないので、中身が変わるたびにクエリ引数を加えたり、ファイル名を変更する必要があります。
4342

44-
## When to use the `static` folder
43+
## いつ `static` フォルダーを使うべきか
4544

46-
Normally we recommend importing [stylesheets, images, and font assets](/docs/importing-assets-into-files/) from JavaScript. The `static`
47-
folder is useful as a workaround for a number of less common cases:
45+
通常、私たちは [スタイルシート・画像・フォントアセット](/docs/importing-assets-into-files/)JavaScript からインポートすることを推奨します。
46+
しかし、 `static` フォルダーは多くのあまり典型的でないケースにおいて、抜け道として有効です。
4847

49-
- You need a file with a specific name in the build output, such as
50-
[`manifest.webmanifest`](https://developer.mozilla.org/en-US/docs/Web/Manifest).
51-
- You have thousands of images and need to dynamically reference their paths.
52-
- You want to include a small script like
53-
[`pace.js`](http://github.hubspot.com/pace/docs/welcome/) outside of the
54-
bundled code.
55-
- Some libraries may be incompatible with Webpack and you have no other option but to include it as a `<script>` tag.
56-
- You need to import JSON file that doesn't have a consistent schema, like [TopoJSON files](https://en.wikipedia.org/wiki/GeoJSON#TopoJSON), which is difficult to handle with GraphQL. Note that importing JSON files directly inside a page, a template, or a component using `import` syntax results in adding that file to the app bundle and increasing the size of all site's pages. Instead, it's better to place your JSON file inside the `static` folder and use the dynamic import syntax (`import('/static/myjson.json')`) within the `componentDidMount` lifecycle or the `useEffect` hook.
48+
- ビルド出力に特定の名前のファイル、例えば [`manifest.webmanifest`](https://developer.mozilla.org/en-US/docs/Web/Manifest) が必要なとき。
49+
- 数千の画像があり、それらを動的に参照しなければならないとき。
50+
- 小さなスクリプト([`pace.js`](http://github.hubspot.com/pace/docs/welcome/) など)をバンドル外で含めたいとき。
51+
- Webpack と互換性のないライブラリーを使用しており、 `<script>` タグを使用して読み込む以外の方法がないとき。
52+
- GraphQL で扱うのが難しい一貫性のないスキーマを持つ JSON ファイル([TopoJSON files](https://en.wikipedia.org/wiki/GeoJSON#TopoJSON)など)をインポートしたいとき。JSON ファイルを `import` 文を用いてページ、テンプレート、コンポーネント内に直接インポートすると、そのファイルがバンドルに追加されるので、全てのページのサイズが増加することに注意してください。代わりに、JSON ファイルを `staic` フォルダーに置いて、 `componentDidMount` ライフサイクルや `useEffect` hook 内で動的 import 文(`import('/static/myjson.json')`)を用いると良いでしょう。

0 commit comments

Comments
 (0)