Skip to content
This repository was archived by the owner on May 25, 2024. It is now read-only.

Commit bf1a4da

Browse files
authored
ガイドの Vite3 対応 (#161)
1 parent 6d87e63 commit bf1a4da

22 files changed

+454
-315
lines changed

docs/rendering.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ Welcome to Vue Handson!
4141
mustache とは口髭を指す英語で、二重中括弧 `{{ }}` が口髭のように見えることから命名されました。
4242
:::
4343

44+
## コード変更の準備
45+
46+
ここからは、デフォルトで生成された Vue のプロジェクトを独自のコードに置き換えていきます。まず、今後のステップで利用しない不要なコードやファイルを削除していきましょう。
47+
48+
まず、`src/main.js` を以下のように編集します。具体的には 4 行目のコードを削除します(今回はこの css を利用しないため)。
49+
50+
変更前(`src/main.js`
51+
52+
<<< @/../examples/overview/src/main.js
53+
54+
変更後(`src/main.js`
55+
56+
<<< @/../examples/rendering/src/main.js
57+
58+
次に、今後のステップで利用しないファイルをディレクトリごと削除します。削除する対象は以下のディレクトリです。
59+
60+
- `src/assets/` 以下すべて
61+
- `src/components/` 以下すべて
62+
4463
## 商品をレンダリング
4564

4665
プロジェクトのファイルを書き換えて、商品をレンダリングしていきましょう。まず、`src/App.vue` ファイルの template を次のように変更します。

examples/overview/index.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<!DOCTYPE html>
22
<html lang="ja">
33
<head>
4-
<meta charset="utf-8">
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7-
<link rel="icon" href="/favicon.ico">
4+
<meta charset="UTF-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
87
<title>handson-vue3-examples</title>
98
<link rel="stylesheet" href="./style.css">
109
</head>

examples/overview/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "overview",
33
"private": true,
4-
"version": "0.0.0",
4+
"version": "0.1.1",
55
"scripts": {
66
"dev": "vite",
77
"build": "vite build",
8-
"preview": "vite preview --port 5050"
8+
"preview": "vite preview --port 4173"
99
},
1010
"dependencies": {
11-
"vue": "^3.2.33"
11+
"vue": "^3.2.37"
1212
},
1313
"devDependencies": {
14-
"@vitejs/plugin-vue": "^2.3.1",
15-
"vite": "^2.9.5"
14+
"@vitejs/plugin-vue": "^3.0.1",
15+
"vite": "^3.0.1"
1616
}
1717
}

examples/overview/src/App.vue

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,53 @@
1+
// region script
2+
<script setup>
3+
import HelloWorld from './components/HelloWorld.vue'
4+
import TheWelcome from './components/TheWelcome.vue'
5+
</script>
6+
// endregion script
7+
18
// region template
29
<template>
3-
<img
4-
alt="Vue logo"
5-
src="./assets/logo.png">
6-
<HelloWorld msg="Welcome to Your Vue.js App" />
10+
<header>
11+
<img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" />
12+
13+
<div class="wrapper">
14+
<HelloWorld msg="You did it!" />
15+
</div>
16+
</header>
17+
18+
<main>
19+
<TheWelcome />
20+
</main>
721
</template>
822
// endregion template
923

10-
// region script
11-
<script>
12-
import HelloWorld from './components/HelloWorld.vue'
24+
// region style
25+
<style scoped>
26+
header {
27+
line-height: 1.5;
28+
}
1329
14-
export default {
15-
name: 'App',
16-
components: {
17-
HelloWorld
18-
}
30+
.logo {
31+
display: block;
32+
margin: 0 auto 2rem;
1933
}
20-
</script>
21-
// endregion script
2234
23-
// region style
24-
<style>
25-
#app {
26-
font-family: Avenir, Helvetica, Arial, sans-serif;
27-
-webkit-font-smoothing: antialiased;
28-
-moz-osx-font-smoothing: grayscale;
29-
text-align: center;
30-
color: #2c3e50;
31-
margin-top: 60px;
35+
@media (min-width: 1024px) {
36+
header {
37+
display: flex;
38+
place-items: center;
39+
padding-right: calc(var(--section-gap) / 2);
40+
}
41+
42+
.logo {
43+
margin: 0 2rem 0 0;
44+
}
45+
46+
header .wrapper {
47+
display: flex;
48+
place-items: flex-start;
49+
flex-wrap: wrap;
50+
}
3251
}
3352
</style>
3453
// endregion style

examples/overview/src/assets/base.css

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* color palette from <https://github.com/vuejs/theme> */
2+
:root {
3+
--vt-c-white: #ffffff;
4+
--vt-c-white-soft: #f8f8f8;
5+
--vt-c-white-mute: #f2f2f2;
6+
7+
--vt-c-black: #181818;
8+
--vt-c-black-soft: #222222;
9+
--vt-c-black-mute: #282828;
10+
11+
--vt-c-indigo: #2c3e50;
12+
13+
--vt-c-divider-light-1: rgba(60, 60, 60, 0.29);
14+
--vt-c-divider-light-2: rgba(60, 60, 60, 0.12);
15+
--vt-c-divider-dark-1: rgba(84, 84, 84, 0.65);
16+
--vt-c-divider-dark-2: rgba(84, 84, 84, 0.48);
17+
18+
--vt-c-text-light-1: var(--vt-c-indigo);
19+
--vt-c-text-light-2: rgba(60, 60, 60, 0.66);
20+
--vt-c-text-dark-1: var(--vt-c-white);
21+
--vt-c-text-dark-2: rgba(235, 235, 235, 0.64);
22+
}
23+
24+
/* semantic color variables for this project */
25+
:root {
26+
--color-background: var(--vt-c-white);
27+
--color-background-soft: var(--vt-c-white-soft);
28+
--color-background-mute: var(--vt-c-white-mute);
29+
30+
--color-border: var(--vt-c-divider-light-2);
31+
--color-border-hover: var(--vt-c-divider-light-1);
32+
33+
--color-heading: var(--vt-c-text-light-1);
34+
--color-text: var(--vt-c-text-light-1);
35+
36+
--section-gap: 160px;
37+
}
38+
39+
@media (prefers-color-scheme: dark) {
40+
:root {
41+
--color-background: var(--vt-c-black);
42+
--color-background-soft: var(--vt-c-black-soft);
43+
--color-background-mute: var(--vt-c-black-mute);
44+
45+
--color-border: var(--vt-c-divider-dark-2);
46+
--color-border-hover: var(--vt-c-divider-dark-1);
47+
48+
--color-heading: var(--vt-c-text-dark-1);
49+
--color-text: var(--vt-c-text-dark-2);
50+
}
51+
}
52+
53+
*,
54+
*::before,
55+
*::after {
56+
box-sizing: border-box;
57+
margin: 0;
58+
position: relative;
59+
font-weight: normal;
60+
}
61+
62+
body {
63+
min-height: 100vh;
64+
color: var(--color-text);
65+
background: var(--color-background);
66+
transition: color 0.5s, background-color 0.5s;
67+
line-height: 1.6;
68+
font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
69+
Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
70+
font-size: 15px;
71+
text-rendering: optimizeLegibility;
72+
-webkit-font-smoothing: antialiased;
73+
-moz-osx-font-smoothing: grayscale;
74+
}

examples/overview/src/assets/logo.png

-6.69 KB
Binary file not shown.

examples/overview/src/assets/logo.svg

Lines changed: 1 addition & 0 deletions
Loading

examples/overview/src/assets/main.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@import "./base.css";
2+
3+
#app {
4+
max-width: 1280px;
5+
margin: 0 auto;
6+
padding: 2rem;
7+
8+
font-weight: normal;
9+
}
10+
11+
a,
12+
.green {
13+
text-decoration: none;
14+
color: hsla(160, 100%, 37%, 1);
15+
transition: 0.4s;
16+
}
17+
18+
@media (hover: hover) {
19+
a:hover {
20+
background-color: hsla(160, 100%, 37%, 0.2);
21+
}
22+
}
23+
24+
@media (min-width: 1024px) {
25+
body {
26+
display: flex;
27+
place-items: center;
28+
}
29+
30+
#app {
31+
display: grid;
32+
grid-template-columns: 1fr 1fr;
33+
padding: 0 2rem;
34+
}
35+
}

0 commit comments

Comments
 (0)