Skip to content

Commit 87a9a70

Browse files
committed
feat(create-vite): update vue templates
1 parent 7be6c0c commit 87a9a70

File tree

9 files changed

+46
-81
lines changed

9 files changed

+46
-81
lines changed

packages/create-vite/template-vue-ts/README.md

+2-18
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,8 @@ This template should help get you started developing with Vue 3 and Typescript i
44

55
## Recommended IDE Setup
66

7-
[VSCode](https://code.visualstudio.com/) + [Vetur](https://marketplace.visualstudio.com/items?itemName=octref.vetur). Make sure to enable `vetur.experimental.templateInterpolationService` in settings!
8-
9-
### If Using `<script setup>`
10-
11-
[`<script setup>`](https://github.com/vuejs/rfcs/pull/227) is a feature that is currently in RFC stage. To get proper IDE support for the syntax, use [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar) instead of Vetur (and disable Vetur).
7+
- [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar)
128

139
## Type Support For `.vue` Imports in TS
1410

15-
Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can use the following:
16-
17-
### If Using Volar
18-
19-
Run `Volar: Switch TS Plugin on/off` from VSCode command palette.
20-
21-
### If Using Vetur
22-
23-
1. Install and add `@vuedx/typescript-plugin-vue` to the [plugins section](https://www.typescriptlang.org/tsconfig#plugins) in `tsconfig.json`
24-
2. Delete `src/shims-vue.d.ts` as it is no longer needed to provide module info to Typescript
25-
3. Open `src/main.ts` in VSCode
26-
4. Open the VSCode command palette
27-
5. Search and run "Select TypeScript version" -> "Use workspace version"
11+
Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's `.vue` type support plugin by running `Volar: Switch TS Plugin on/off` from VSCode command palette.

packages/create-vite/template-vue-ts/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"vue": "^3.2.6"
1111
},
1212
"devDependencies": {
13-
"@vitejs/plugin-vue": "^1.3.0",
13+
"@vitejs/plugin-vue": "^1.6.0",
1414
"@vue/compiler-sfc": "^3.0.5",
1515
"typescript": "^4.3.2",
16-
"vite": "^2.4.4",
16+
"vite": "^2.5.1",
1717
"vue-tsc": "^0.2.2"
1818
}
1919
}

packages/create-vite/template-vue-ts/src/App.vue

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1+
<script setup lang="ts">
2+
// This starter template is using Vue 3 <script setup> SFCs
3+
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
4+
import HelloWorld from './components/HelloWorld.vue'
5+
</script>
6+
17
<template>
28
<img alt="Vue logo" src="./assets/logo.png" />
39
<HelloWorld msg="Hello Vue 3 + TypeScript + Vite" />
410
</template>
511

6-
<script lang="ts">
7-
import { defineComponent } from 'vue'
8-
import HelloWorld from './components/HelloWorld.vue'
9-
10-
export default defineComponent({
11-
name: 'App',
12-
components: {
13-
HelloWorld
14-
}
15-
})
16-
</script>
17-
1812
<style>
1913
#app {
2014
font-family: Avenir, Helvetica, Arial, sans-serif;

packages/create-vite/template-vue-ts/src/components/HelloWorld.vue

+8-26
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1+
<script setup lang="ts">
2+
import { ref } from 'vue'
3+
4+
defineProps<{ msg: string }>()
5+
6+
const count = ref(0)
7+
</script>
8+
19
<template>
210
<h1>{{ msg }}</h1>
311

412
<p>
513
Recommended IDE setup:
614
<a href="https://code.visualstudio.com/" target="_blank">VSCode</a>
715
+
8-
<a
9-
href="https://marketplace.visualstudio.com/items?itemName=octref.vetur"
10-
target="_blank"
11-
>
12-
Vetur
13-
</a>
14-
or
1516
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
16-
(if using
17-
<code>&lt;script setup&gt;</code>)
1817
</p>
1918

2019
<p>See <code>README.md</code> for more information.</p>
@@ -34,23 +33,6 @@
3433
</p>
3534
</template>
3635

37-
<script lang="ts">
38-
import { ref, defineComponent } from 'vue'
39-
export default defineComponent({
40-
name: 'HelloWorld',
41-
props: {
42-
msg: {
43-
type: String,
44-
required: true
45-
}
46-
},
47-
setup: () => {
48-
const count = ref(0)
49-
return { count }
50-
}
51-
})
52-
</script>
53-
5436
<style scoped>
5537
a {
5638
color: #42b983;

packages/create-vite/template-vue-ts/src/shims-vue.d.ts packages/create-vite/template-vue-ts/src/env.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference types="vite/client" />
2+
13
declare module '*.vue' {
24
import { DefineComponent } from 'vue'
35
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types

packages/create-vite/template-vue-ts/src/vite-env.d.ts

-1
This file was deleted.

packages/create-vite/template-vue/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"vue": "^3.2.6"
1111
},
1212
"devDependencies": {
13-
"@vitejs/plugin-vue": "^1.3.0",
13+
"@vitejs/plugin-vue": "^1.6.0",
1414
"@vue/compiler-sfc": "^3.0.5",
15-
"vite": "^2.4.4"
15+
"vite": "^2.5.1"
1616
}
1717
}

packages/create-vite/template-vue/src/App.vue

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
<script setup>
2+
// This starter template is using Vue 3 <script setup> SFCs
3+
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
4+
import HelloWorld from './components/HelloWorld.vue'
5+
</script>
6+
17
<template>
28
<img alt="Vue logo" src="./assets/logo.png" />
39
<HelloWorld msg="Hello Vue 3 + Vite" />
410
</template>
511

6-
<script setup>
7-
import HelloWorld from './components/HelloWorld.vue'
8-
9-
// This starter template is using Vue 3 experimental <script setup> SFCs
10-
// Check out https://github.com/vuejs/rfcs/blob/master/active-rfcs/0040-script-setup.md
11-
</script>
12-
1312
<style>
1413
#app {
1514
font-family: Avenir, Helvetica, Arial, sans-serif;

packages/create-vite/template-vue/src/components/HelloWorld.vue

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1+
<script setup>
2+
import { ref } from 'vue'
3+
4+
defineProps({
5+
msg: String
6+
})
7+
8+
const count = ref(0)
9+
</script>
10+
111
<template>
212
<h1>{{ msg }}</h1>
313

14+
<p>
15+
Recommended IDE setup:
16+
<a href="https://code.visualstudio.com/" target="_blank">VSCode</a>
17+
+
18+
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
19+
</p>
20+
421
<p>
522
<a href="https://vitejs.dev/guide/features.html" target="_blank">
623
Vite Documentation
@@ -9,25 +26,13 @@
926
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Documentation</a>
1027
</p>
1128

12-
<button type="button" @click="state.count++">
13-
count is: {{ state.count }}
14-
</button>
29+
<button type="button" @click="count++">count is: {{ count }}</button>
1530
<p>
1631
Edit
1732
<code>components/HelloWorld.vue</code> to test hot module replacement.
1833
</p>
1934
</template>
2035

21-
<script setup>
22-
import { defineProps, reactive } from 'vue'
23-
24-
defineProps({
25-
msg: String
26-
})
27-
28-
const state = reactive({ count: 0 })
29-
</script>
30-
3136
<style scoped>
3237
a {
3338
color: #42b983;

0 commit comments

Comments
 (0)