Skip to content

Commit 85d614b

Browse files
committed
add: chapter 01
1 parent e1cad26 commit 85d614b

33 files changed

+788
-0
lines changed

ch01/.eslintrc.cjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-env node */
2+
require('@rushstack/eslint-patch/modern-module-resolution')
3+
4+
module.exports = {
5+
root: true,
6+
'extends': [
7+
'plugin:vue/vue3-essential',
8+
'eslint:recommended',
9+
'@vue/eslint-config-typescript',
10+
'@vue/eslint-config-prettier/skip-formatting'
11+
],
12+
parserOptions: {
13+
ecmaVersion: 'latest'
14+
}
15+
}

ch01/.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
.DS_Store
12+
dist
13+
dist-ssr
14+
coverage
15+
*.local
16+
17+
/cypress/videos/
18+
/cypress/screenshots/
19+
20+
# Editor directories and files
21+
.vscode/*
22+
!.vscode/extensions.json
23+
.idea
24+
*.suo
25+
*.ntvs*
26+
*.njsproj
27+
*.sln
28+
*.sw?

ch01/.prettierrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://json.schemastore.org/prettierrc",
3+
"semi": false,
4+
"tabWidth": 2,
5+
"singleQuote": true,
6+
"printWidth": 100,
7+
"trailingComma": "none"
8+
}

ch01/.vscode/extensions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"recommendations": [
3+
"Vue.volar",
4+
"Vue.vscode-typescript-vue-plugin",
5+
"dbaeumer.vscode-eslint",
6+
"esbenp.prettier-vscode"
7+
]
8+
}

ch01/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# ch01
2+
3+
This template should help get you started developing with Vue 3 in Vite.
4+
5+
## Recommended IDE Setup
6+
7+
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).
8+
9+
## Type Support for `.vue` Imports in TS
10+
11+
TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.
12+
13+
If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:
14+
15+
1. Disable the built-in TypeScript Extension
16+
1) Run `Extensions: Show Built-in Extensions` from VSCode's command palette
17+
2) Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
18+
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
19+
20+
## Customize configuration
21+
22+
See [Vite Configuration Reference](https://vitejs.dev/config/).
23+
24+
## Project Setup
25+
26+
```sh
27+
npm install
28+
```
29+
30+
### Compile and Hot-Reload for Development
31+
32+
```sh
33+
npm run dev
34+
```
35+
36+
### Type-Check, Compile and Minify for Production
37+
38+
```sh
39+
npm run build
40+
```
41+
42+
### Run Unit Tests with [Vitest](https://vitest.dev/)
43+
44+
```sh
45+
npm run test:unit
46+
```
47+
48+
### Lint with [ESLint](https://eslint.org/)
49+
50+
```sh
51+
npm run lint
52+
```

ch01/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

ch01/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<link rel="icon" href="/favicon.ico">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>

ch01/package.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "ch01",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "run-p type-check build-only",
8+
"preview": "vite preview",
9+
"test:unit": "vitest",
10+
"build-only": "vite build",
11+
"type-check": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
12+
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
13+
"format": "prettier --write src/"
14+
},
15+
"dependencies": {
16+
"pinia": "^2.1.6",
17+
"vue": "^3.3.4",
18+
"vue-router": "^4.2.4"
19+
},
20+
"devDependencies": {
21+
"@rushstack/eslint-patch": "^1.3.2",
22+
"@tsconfig/node18": "^18.2.0",
23+
"@types/jsdom": "^21.1.1",
24+
"@types/node": "^18.17.5",
25+
"@vitejs/plugin-vue": "^4.3.1",
26+
"@vitejs/plugin-vue-jsx": "^3.0.2",
27+
"@vue/eslint-config-prettier": "^8.0.0",
28+
"@vue/eslint-config-typescript": "^11.0.3",
29+
"@vue/test-utils": "^2.4.1",
30+
"@vue/tsconfig": "^0.4.0",
31+
"eslint": "^8.46.0",
32+
"eslint-plugin-vue": "^9.16.1",
33+
"jsdom": "^22.1.0",
34+
"npm-run-all": "^4.1.5",
35+
"prettier": "^3.0.0",
36+
"typescript": "~5.1.6",
37+
"vite": "^4.4.9",
38+
"vitest": "^0.34.2",
39+
"vue-tsc": "^1.8.8"
40+
}
41+
}

ch01/public/favicon.ico

4.19 KB
Binary file not shown.

ch01/src/App.vue

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<script setup lang="ts">
2+
import { RouterLink, RouterView } from 'vue-router'
3+
import HelloWorld from './components/HelloWorld.vue'
4+
</script>
5+
6+
<template>
7+
<header>
8+
<img alt="Vue logo" class="logo" src="@/assets/logo.svg" width="125" height="125" />
9+
10+
<div class="wrapper">
11+
<HelloWorld msg="You did it!" />
12+
13+
<nav>
14+
<RouterLink to="/">Home</RouterLink>
15+
<RouterLink to="/about">About</RouterLink>
16+
</nav>
17+
</div>
18+
</header>
19+
20+
<RouterView />
21+
</template>
22+
23+
<style scoped>
24+
header {
25+
line-height: 1.5;
26+
max-height: 100vh;
27+
}
28+
29+
.logo {
30+
display: block;
31+
margin: 0 auto 2rem;
32+
}
33+
34+
nav {
35+
width: 100%;
36+
font-size: 12px;
37+
text-align: center;
38+
margin-top: 2rem;
39+
}
40+
41+
nav a.router-link-exact-active {
42+
color: var(--color-text);
43+
}
44+
45+
nav a.router-link-exact-active:hover {
46+
background-color: transparent;
47+
}
48+
49+
nav a {
50+
display: inline-block;
51+
padding: 0 1rem;
52+
border-left: 1px solid var(--color-border);
53+
}
54+
55+
nav a:first-of-type {
56+
border: 0;
57+
}
58+
59+
@media (min-width: 1024px) {
60+
header {
61+
display: flex;
62+
place-items: center;
63+
padding-right: calc(var(--section-gap) / 2);
64+
}
65+
66+
.logo {
67+
margin: 0 2rem 0 0;
68+
}
69+
70+
header .wrapper {
71+
display: flex;
72+
place-items: flex-start;
73+
flex-wrap: wrap;
74+
}
75+
76+
nav {
77+
text-align: left;
78+
margin-left: -1rem;
79+
font-size: 1rem;
80+
81+
padding: 1rem 0;
82+
margin-top: 1rem;
83+
}
84+
}
85+
</style>

0 commit comments

Comments
 (0)