Skip to content

Commit d6bf066

Browse files
feat(create-app): clearer vue-ts setup recommend (#1896) [skip ci]
1 parent fc4dc18 commit d6bf066

File tree

4 files changed

+59
-36
lines changed

4 files changed

+59
-36
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,58 @@
11
<template>
22
<h1>{{ msg }}</h1>
33

4-
<p>
5-
<a href="https://vitejs.dev/guide/features.html" target="_blank">Vite Documentation</a> |
6-
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Documentation</a>
7-
</p>
4+
<label>
5+
<input type="checkbox" v-model="useScriptSetup" /> Use
6+
<code>&lt;script setup&gt;</code>
7+
</label>
8+
<label>
9+
<input type="checkbox" v-model="useTsPlugin" /> Provide types for
10+
<code>*.vue</code> imports
11+
</label>
812

913
<p>
1014
Recommended IDE setup:
1115
<a href="https://code.visualstudio.com/" target="_blank">VSCode</a>
1216
+
13-
<a
14-
href="https://marketplace.visualstudio.com/items?itemName=octref.vetur"
15-
target="_blank"
16-
>Vetur</a>
17-
+
18-
<a
19-
href="https://marketplace.visualstudio.com/items?itemName=znck.vue-language-features"
20-
target="_blank"
21-
>Vue DX</a>
17+
<template v-if="!useScriptSetup">
18+
<a
19+
href="https://marketplace.visualstudio.com/items?itemName=octref.vetur"
20+
target="_blank"
21+
>Vetur</a>
22+
+
23+
<a
24+
href="https://marketplace.visualstudio.com/items?itemName=znck.vue-language-features"
25+
target="_blank"
26+
>Vue DX</a>
27+
</template>
28+
<template v-else>
29+
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
30+
</template>
2231
</p>
23-
<p>
24-
If using &lt;script setup&gt;: use
25-
<a
26-
href="https://github.com/johnsoncodehk/volar"
27-
target="_blank"
28-
>Volar</a> instead (and disable Vetur)
29-
</p>
30-
<p>
31-
<b style="color:red">Make sure to use workspace version of TypeScript!!!</b>
32-
<br />This leverages the
33-
<code>@vuex/typescript-plugin-vue</code> to provide types for `*.vue` imports.
34-
<br />1. Open
32+
<p v-if="useTsPlugin">
33+
tsconfig setup:
34+
<br />1. Install and add
35+
<code>@vuex/typescript-plugin-vue</code> to tsconfig plugins
36+
<br />2. Delete shims-vue.d.ts
37+
<br />3. Open
3538
<code>src/main.ts</code> in VSCode
36-
<br />2. Open VSCode command input
37-
<br />3. Search and run "Select TypeScript version" -> "Use workspace version"
39+
<br />4. Open VSCode command input
40+
<br />5. Search and run "Select TypeScript version" -> "Use workspace version"
3841
</p>
3942
<button @click="count++">count is: {{ count }}</button>
4043
<p>
4144
Edit
4245
<code>components/HelloWorld.vue</code> to test hot module replacement.
4346
</p>
47+
48+
<p>
49+
<a href="https://vitejs.dev/guide/features.html" target="_blank">Vite Docs</a> |
50+
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Docs</a>
51+
</p>
4452
</template>
4553

4654
<script lang="ts">
4755
import { ref, defineComponent } from 'vue'
48-
4956
export default defineComponent({
5057
name: 'HelloWorld',
5158
props: {
@@ -56,7 +63,9 @@ export default defineComponent({
5663
},
5764
setup: () => {
5865
const count = ref(0)
59-
return { count }
66+
const useScriptSetup = ref(false);
67+
const useTsPlugin = ref(false);
68+
return { count, useScriptSetup, useTsPlugin }
6069
}
6170
})
6271
</script>
@@ -65,4 +74,16 @@ export default defineComponent({
6574
a {
6675
color: #42b983;
6776
}
68-
</style>
77+
78+
label {
79+
margin: 0 0.5em;
80+
font-weight: bold;
81+
}
82+
83+
code {
84+
background-color: #eee;
85+
padding: 2px 4px;
86+
border-radius: 4px;
87+
color: #304455;
88+
}
89+
</style>
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { createApp } from 'vue'
2-
// TypeScript error? Run VSCode command
3-
// TypeScript: Select TypeScript version - > Use Workspace Version
42
import App from './App.vue'
53

64
createApp(App).mount('#app')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare module '*.vue' {
2+
import { DefineComponent } from 'vue'
3+
const component: DefineComponent<{}, {}, any>
4+
export default component
5+
}

packages/create-app/template-vue-ts/tsconfig.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
"strict": true,
77
"jsx": "preserve",
88
"sourceMap": true,
9-
"lib": ["esnext", "dom"],
10-
"types": ["vite/client"],
11-
"plugins": [{ "name": "@vuedx/typescript-plugin-vue" }],
129
"resolveJsonModule": true,
13-
"esModuleInterop": true
10+
"esModuleInterop": true,
11+
"lib": ["esnext", "dom"],
12+
"types": ["vite/client"]
1413
},
1514
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
1615
}

0 commit comments

Comments
 (0)