Skip to content

Commit 1d7aa24

Browse files
authored
Cookbook の翻訳を追従 (#394)
* Debugging in VS Code Cookbook Recipe vuejs/docs@572b3cc#diff-b0e55b2e7066b952316301f7d1ca92884bcf4587ecb8899b43161ec6754e3fb3 * fix: change the language on some code blocks to match the code vuejs/docs@0391e2e#diff-b0e55b2e7066b952316301f7d1ca92884bcf4587ecb8899b43161ec6754e3fb3 * docs: use local copies of images rather than external URLs vuejs/docs@4b0baab#diff-b0e55b2e7066b952316301f7d1ca92884bcf4587ecb8899b43161ec6754e3fb3 * docs: add automatic global registration to cookbook vuejs/docs@6de305a#diff-b0e55b2e7066b952316301f7d1ca92884bcf4587ecb8899b43161ec6754e3fb3 * fix: markdown syntax * docs: translate cookbook > editable svg icon systems * docs: translate cookbook > debugging in vscode * docs: translate cookbook > automatic global registration of base components
1 parent 53fb728 commit 1d7aa24

11 files changed

+236
-35
lines changed

src/.vuepress/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const sidebar = {
66
children: [
77
'/cookbook/',
88
'/cookbook/editable-svg-icons',
9-
// '/cookbook/debugging-in-vscode'
9+
'/cookbook/debugging-in-vscode',
10+
'/cookbook/automatic-global-registration-of-base-components'
1011
]
1112
}
1213
],
610 KB
Loading
536 KB
Loading
518 KB
Loading
Loading
Loading
Loading
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# ベースコンポーネントの自動グローバル登録
2+
3+
## 基本的な例
4+
5+
多くのコンポーネントは割と一般的なもので、あるいは入力やボタンをラップするだけのものかもしれません。わたしたちは、このようなコンポーネントを [ベースコンポーネント](../style-guide/#base-component-names-strongly-recommended) と呼ぶことがあって、コンポーネント全体に渡ってとても頻繁に使われる傾向があります。
6+
7+
8+
その結果、多くのコンポーネントはベースコンポーネントの長いリストに含まれていることがあります:
9+
10+
```js
11+
import BaseButton from './BaseButton.vue'
12+
import BaseIcon from './BaseIcon.vue'
13+
import BaseInput from './BaseInput.vue'
14+
export default {
15+
components: {
16+
BaseButton,
17+
BaseIcon,
18+
BaseInput
19+
}
20+
}
21+
```
22+
23+
テンプレート内の比較的小さなマークアップをサポートするためだけのものです:
24+
25+
```html
26+
<BaseInput v-model="searchText" @keydown.enter="search" />
27+
<BaseButton @click="search">
28+
<BaseIcon name="search" />
29+
</BaseButton>
30+
```
31+
32+
幸いなことに、webpack(または [Vue CLI](https://github.com/vuejs/vue-cli)、これは内部的に webpack を使っています)を使う場合、これらのとても汎用的なベースコンポーネントだけをグローバルに登録するのに `require.context` を使うことができます。このコード例は、アプリケーションのエントリファイル(例えば `src/main.js`)でベースコンポーネントをグローバルにインポートするのに使えるでしょう:
33+
34+
```js
35+
import { createApp } from 'vue'
36+
import upperFirst from 'lodash/upperFirst'
37+
import camelCase from 'lodash/camelCase'
38+
import App from './App.vue'
39+
40+
const app = createApp(App)
41+
42+
const requireComponent = require.context(
43+
// コンポーネントフォルダの相対パス
44+
'./components',
45+
// サブフォルダ内を探すかどうか
46+
false,
47+
// ベースコンポーネントのファイル名とマッチさせるための正規表現
48+
/Base[A-Z]\w+\.(vue|js)$/
49+
)
50+
51+
requireComponent.keys().forEach(fileName => {
52+
// コンポーネント設定の取得
53+
const componentConfig = requireComponent(fileName)
54+
55+
// コンポーネントのパスカルケースでの名前を取得
56+
const componentName = upperFirst(
57+
camelCase(
58+
// フォルダの深さに関わらずファイル名を取得
59+
fileName
60+
.split('/')
61+
.pop()
62+
.replace(/\.\w+$/, '')
63+
)
64+
)
65+
66+
app.component(
67+
componentName,
68+
// `.default` にあるコンポーネントのオプションを探す。
69+
// コンポーネントが `export default` でエクスポートされていれば存在して、
70+
// そうでなければモジュールのルートのフォールバックする。
71+
componentConfig.default || componentConfig
72+
)
73+
})
74+
75+
app.mount('#app')
76+
```

src/cookbook/debugging-in-vscode.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# VS Code でのデバッグ
2+
3+
あらゆるアプリケーションは、小さなものから大きなものまでエラーを理解する必要がある段階に到達します。このレシピでは、 VS Code ユーザがブラウザでアプリケーションをデバッグするためのワークフローをいくつか紹介します。
4+
5+
このレシピでは、 [Vue CLI](https://github.com/vuejs/vue-cli) アプリケーションをブラウザで実行しながら、 VS Code でデバッグする方法を紹介します。
6+
7+
## 必要なもの
8+
9+
VS Code と好みのブラウザがインストールされていて、対応するデバッガー拡張機能の最新バージョンがインストールされ、有効化されていることを確認してください:
10+
11+
- [Debugger for Chrome](https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome)
12+
- [Debugger for Firefox](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-firefox-debug)
13+
14+
[Vue CLI ガイド](https://cli.vuejs.org/) の説明にしたがって、 [vue-cli](https://github.com/vuejs/vue-cli) をインストールしてプロジェクトを作成します。新しく作成したアプリケーションのディレクトリに移動して、 VS Code を開きます。
15+
16+
### ブラウザにソースコードを表示
17+
18+
VS Code で Vue コンポーネントをデバッグできるようにする前に、生成された Webpack の設定を更新してソースマップをビルドする必要があります。これはデバッガが圧縮ファイルの中のコードを、元のファイルの位置に一致させる方法を持つためです。これにより、アセットが Webpack で最適化された後でも、アプリケーションのデバッグが可能になります。
19+
20+
Vue CLI 2 を使っているならば、`config/index.js` 内の `devtool` プロパティを設定、または更新してください:
21+
22+
```json
23+
devtool: 'source-map',
24+
```
25+
26+
使っているのが Vue CLI 3 ならば、`vue.config.js` 内の `devtool` プロパティを設定、または更新してください:
27+
28+
```js
29+
module.exports = {
30+
configureWebpack: {
31+
devtool: 'source-map',
32+
},
33+
}
34+
```
35+
36+
### VS Code からアプリケーションを起動
37+
38+
::: info
39+
ここではポートを `8080` と仮定します。そうでない場合(例えば `8080` が使われていて、Vue CLI が自動的に別のポートを選択したとき)は、適宜設定を変更してください。
40+
:::
41+
42+
アクティビティバーのデバッグアイコンをクリックして、デバッグ表示に切り替え、歯車アイコンをクリックして launch.json ファイルを設定したら、環境として **Chrome/Firefox: Launch** を選択します。生成された launch.json の内容を対応する設定に置き換えます:
43+
44+
![Add Chrome Configuration](/images/config_add.png)
45+
46+
```json
47+
{
48+
"version": "0.2.0",
49+
"configurations": [
50+
{
51+
"type": "chrome",
52+
"request": "launch",
53+
"name": "vuejs: chrome",
54+
"url": "http://localhost:8080",
55+
"webRoot": "${workspaceFolder}/src",
56+
"breakOnLoad": true,
57+
"sourceMapPathOverrides": {
58+
"webpack:///src/*": "${webRoot}/*"
59+
}
60+
},
61+
{
62+
"type": "firefox",
63+
"request": "launch",
64+
"name": "vuejs: firefox",
65+
"url": "http://localhost:8080",
66+
"webRoot": "${workspaceFolder}/src",
67+
"pathMappings": [{ "url": "webpack:///src/", "path": "${webRoot}/" }]
68+
}
69+
]
70+
}
71+
```
72+
73+
## ブレークポイントの設定
74+
75+
1. **src/components/HelloWorld.vue**`line 90` にある `data` 関数が文字列を返す部分にブレークポイントを設定します。.
76+
77+
![Breakpoint Renderer](/images/breakpoint_set.png)
78+
79+
2. ルートフォルダでお気に入りのターミナルを開き、Vue CLI を使ってアプリケーションを配信します:
80+
81+
```
82+
npm run serve
83+
```
84+
85+
3. デバッグ表示に移動して、**'vuejs: chrome/firefox'** の設定を選択したら、F5 キーを押すか、緑色の再生ボタンをクリックします。
86+
87+
4. ブレークポイントに到達すると、新しいブラウザのインスタンスが `http://localhost:8080` を開きます。
88+
89+
![Breakpoint Hit](/images/breakpoint_hit.png)
90+
91+
## 代替パターン
92+
93+
### Vue Devtools
94+
95+
もっと複雑なデバッグの方法もあります。最も一般的で単純な方法は、優れた Vue.js devtools [Chrome 向け](https://chrome.google.com/webstore/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd)[Firefox 向け](https://addons.mozilla.org/en-US/firefox/addon/vue-js-devtools/) を使うことです。Devtools を使うことのいくつかの利点は、データのプロパティを Live Edit(ライブエディット)して、その変更がすぐに反映されることです。その他の主な利点は、Vuex のタイムトラベルデバッグが可能になることです。
96+
97+
![Devtools Timetravel Debugger](/images/devtools-timetravel.gif)
98+
99+
Vue.js の本番向け・縮小化ビルド(CDN からの標準的なリンクなど)を使っているページでは、Devtools の検知がデフォルトで無効になっているため、Vue ペインが表示されないことに注意してください。縮小されていないバージョンに切り替えた場合は、それを表示するためにページのハード再読み込みが必要になるかもしれません。
100+
101+
### 単純な Debugger の記述
102+
103+
上記の例はすばらしいワークフローを持っています。しかし、[ネイティブの debugger 文](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/debugger) をコードの中で直接使うという別の方法もあります。この方法を選択した場合には、作業が終わったらこの debugger 文を削除することを忘れないようにするのが重要です。
104+
105+
```vue
106+
<script>
107+
export default {
108+
data() {
109+
return {
110+
message: ''
111+
}
112+
},
113+
mounted() {
114+
const hello = 'Hello World!'
115+
debugger
116+
this.message = hello
117+
}
118+
};
119+
</script>
120+
```
121+
122+
## 謝辞
123+
124+
このレシピは、[Kenneth Auchenberg](https://twitter.com/auchenberg) 氏からの寄稿を元にしています。[元の記事](https://github.com/Microsoft/VSCode-recipes/tree/master/vuejs-cli)

src/cookbook/editable-svg-icons.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
# Editable SVG Icon Systems
1+
# 編集可能な SVG アイコンシステム
22

3-
## Base Example
3+
## 基本的な例
44

5-
There are many ways to create an SVG Icon System, but one method that takes advantage of Vue's capabilities is to create editable inline icons as components. Some of the advantages of this way of working is:
5+
SVG アイコンシステムを作成する方法はいろいろありますが、 Vue の機能を生かした方法として、編集可能なインラインのアイコンをコンポーネントとして作成する方法があります。この方法のいくつかの利点としては:
66

7-
- They are easy to edit on the fly
8-
- They are animatable
9-
- You can use standard props and defaults to keep them to a typical size or alter them if you need to
10-
- They are inline, so no HTTP requests are necessary
11-
- They can be made accessible dynamically
7+
- 即座に編集することが簡単です
8+
- アニメーションが可能です
9+
- 標準的なプロパティとデフォルトを利用して標準サイズを保つことができ、必要に応じて変更することもできます
10+
- インラインなので HTTP リクエストが不要です
11+
- 動的にアクセスすることが可能です
1212

13-
First, we'll create a folder for all of the icons, and name them in a standardized fashion for easy retrieval:
13+
まず、すべてのアイコンを入れるフォルダを作り、検索しやすいように一定のルールで命名します:
1414

1515
- `components/icons/IconBox.vue`
1616
- `components/icons/IconCalendar.vue`
1717
- `components/icons/IconEnvelope.vue`
1818

19-
Here's an example repo to get you going, where you can see the entire setup: [https://github.com/sdras/vue-sample-svg-icons/](https://github.com/sdras/vue-sample-svg-icons/)
19+
ここにセットアップの全体像を見られるサンプルのリポジトリがあります: [https://github.com/sdras/vue-sample-svg-icons/](https://github.com/sdras/vue-sample-svg-icons/)
2020

21-
![Documentation site](https://s3-us-west-2.amazonaws.com/s.cdpn.io/28963/screendocs.jpg 'Docs demo')
21+
![Documentation site](/images/editable-svg-icons.jpg 'Docs demo')
2222

23-
We'll create a base icon (`IconBase.vue`) component that uses a slot.
23+
スロットを利用した基本となるアイコン(`IconBase.vue`)コンポーネントを作成します。
2424

2525
```html
2626
<template>
@@ -40,9 +40,9 @@ We'll create a base icon (`IconBase.vue`) component that uses a slot.
4040
</template>
4141
```
4242

43-
You can use this base icon as is- the only thing you might need to update is the `viewBox` depending on the `viewBox` of your icons. In the base, we're making the `width`, `height`, `iconColor`, and name of the icon props so that it can be dynamically updated with props. The name will be used for both the `<title>` content and its `id` for accessibility.
43+
アイコンの `viewBox` に応じて `viewBox` を更新する必要があるだけで、この基本となるアイコンをそのまま使うことができます。この基本では、 `width``height``iconColor` とアイコン名をプロパティにして、プロパティから動的に更新できるようにしています。名前は `<title>` のコンテンツと、アクセシビリティのための `id` の両方に使われます。
4444

45-
Our script will look like this, we'll have some defaults so that our icon will be rendered consistently unless we state otherwise:
45+
スクリプト部分はこのようになります。いくつかのデフォルトがあり、特に指定しない限り、アイコンが一貫してレンダリングされるようにします:
4646

4747
```js
4848
export default {
@@ -67,32 +67,32 @@ export default {
6767
}
6868
```
6969

70-
The `currentColor` property that's the default on the fill will make the icon inherit the color of whatever text surrounds it. We could also pass in a different color as a prop if we wish.
70+
塗りつぶし色のデフォルト `currentColor` プロパティは、アイコンの周囲のテキスト色を継承します。必要なら、別の色をプロパティとして渡すこともできます。
7171

72-
We can use it like so, with the only contents of `IconWrite.vue` containing the paths inside the icon:
72+
アイコンのパスを内包する `IconWrite.vue` だけを内容にすると、このように使えます:
7373

7474
```html
7575
<icon-base icon-name="write"><icon-write /></icon-base>
7676
```
7777

78-
Now, if we'd like to make many sizes for the icon, we can do so very easily:
78+
さまざまなサイズのアイコンを作りたいとなったら、とても簡単にできます:
7979

8080
```html
8181
<p>
82-
<!-- you can pass in a smaller `width` and `height` as props -->
82+
<!-- より小さい `width` `height` をプロパティとして渡せます -->
8383
<icon-base width="12" height="12" icon-name="write"><icon-write /></icon-base>
84-
<!-- or you can use the default, which is 18 -->
84+
<!-- あるいはデフォルトも使えます。デフォルトは 18 です -->
8585
<icon-base icon-name="write"><icon-write /></icon-base>
86-
<!-- or make it a little bigger too :) -->
86+
<!-- または少し大きくすることも :) -->
8787
<icon-base width="30" height="30" icon-name="write"><icon-write /></icon-base>
8888
</p>
8989
```
9090

91-
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/28963/Screen%20Shot%202018-01-01%20at%204.51.40%20PM.png" width="450" />
91+
<img src="/images/editable-svg-icons-sizes.png" width="450" />
9292

93-
## Animatable Icons
93+
## アニメーション可能なアイコン
9494

95-
Keeping icons in components comes in very handy when you'd like to animate them, especially on an interaction. Inline SVGs have the highest support for interaction of any method. Here's a very basic example of an icon that's animated on click:
95+
アイコンをコンポーネントに入れておくと、特にインタラクションによってアニメーションさせたいときにとても便利です。インライン SVG は、いろいろなやり方の中で最もインタラクションをサポートします。これはクリックでアニメーションするアイコンのとても基本的な例です:
9696

9797
```html
9898
<template>
@@ -141,27 +141,27 @@ export default {
141141
}
142142
```
143143

144-
We're applying `refs` to the groups of paths we need to move, and as both sides of the scissors have to move in tandem, we'll create a function we can reuse where we'll pass in the `refs`. The use of GreenSock helps resolve animation support and `transform-origin` issues across browser.
144+
移動する必要のあるパスのグループに `refs` を適用します。また、はさみの両側は連動して動く必要があるので、 `refs` を渡す再利用可能な関数を作成します。 GreenSock を使うとアニメーションのサポートや、ブラウザ間の `transform-origin` の問題を解決することができます。
145145

146146
<common-codepen-snippet title="Editable SVG Icon System: Animated icon" slug="dJRpgY" :preview="false" :editable="false" version="2" theme="0" />
147147

148148
<p style="margin-top:-30px">Pretty easily accomplished! And easy to update on the fly.</p>
149149

150-
You can see more animated examples in the repo [here](https://github.com/sdras/vue-sample-svg-icons/)
150+
他のアニメーションの例は、 [こちらの](https://github.com/sdras/vue-sample-svg-icons/) リポジトリで見ることができます。
151151

152-
## Additional Notes
152+
## 補足
153153

154-
Designers may change their minds. Product requirements change. Keeping the logic for the entire icon system in one base component means you can quickly update all of your icons and have it propagate through the whole system. Even with the use of an icon loader, some situations require you to recreate or edit every SVG to make global changes. This method can save you that time and pain.
154+
デザイナーの考えは変わるかもしれません。製品要件は変わります。アイコンシステム全体のロジックを 1 つの基本となるコンポーネントにまとめておけば、すべてのアイコンを素早く更新して、システム全体に広めることができます。アイコンローダーを使っても、場合によってはグローバルな変更を行うために、すべての SVG を再作成または編集しなければなりません。この方法ならば、そのような時間と苦痛からあなたを救うことができます。
155155

156-
## When To Avoid This Pattern
156+
## このパターンを回避するケース
157157

158-
This type of SVG icon system is really useful when you have a number of icons that are used in different ways throughout your site. If you're repeating the same icon many times on one page (e.g. a giant table with a delete icon in each row), it might make more sense to have all of the sprites compiled into a sprite sheet and use `<use>` tags to load them.
158+
このような SVG アイコンシステムは、サイト全体にさまざまな方法で使われているアイコンがたくさんある場合にとても便利です。1 つのページで同じアイコンを繰り返し使うならば(例えば、各行に削除アイコンのある巨大なテーブル)、すべてのスプライトをスプライトシートにコンパイルして `<use>` タグで読み込むほうが合理的でしょう。
159159

160-
## Alternative Patterns
160+
## 代替パターン
161161

162-
Other tooling to help manage SVG icons includes:
162+
SVG アイコンを管理するのに役立つ他のツールには、以下のものがあります:
163163

164164
- [svg-sprite-loader](https://github.com/kisenka/svg-sprite-loader)
165165
- [svgo-loader](https://github.com/rpominov/svgo-loader)
166166

167-
These tools bundle SVGs at compile time, but make them a little harder to edit during runtime, because `<use>` tags can have strange cross-browser issues when doing anything more complex. They also leave you with two nested `viewBox` properties and thus two coordinate systems. This makes the implementation a little more complex.
167+
これらのツールはコンパイル時に SVG をバンドルしますが、実行時にそれらを編集することが少し難しくなります。これは `<use>` タグが複雑な処理をする際に、おかしなクロスブラウザの問題を引き起こす可能性があるからです。2 つの入れ子になった `viewBox` プロパティがあるために、2 つの座標系が存在します。このため実装が少し複雑になります。

0 commit comments

Comments
 (0)