Skip to content

Commit

Permalink
chore(create-vite): align vue template with create-vue (#11128)
Browse files Browse the repository at this point in the history
Co-authored-by: Haoqun Jiang <3277634+sodatea@users.noreply.github.com>
  • Loading branch information
sapphi-red and sodatea committed Nov 30, 2022
1 parent 97f8b4d commit 1a54e58
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 18 deletions.
@@ -1,3 +1,3 @@
{
"recommendations": ["Vue.volar"]
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
}
12 changes: 7 additions & 5 deletions packages/create-vite/template-vue-ts/README.md
Expand Up @@ -4,13 +4,15 @@ This template should help get you started developing with Vue 3 and TypeScript i

## Recommended IDE Setup

- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
- [VS Code](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).

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

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 Take Over mode by following these steps:
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.

1. Run `Extensions: Show Built-in Extensions` from VS Code's command palette, look for `TypeScript and JavaScript Language Features`, then right click and select `Disable (Workspace)`. By default, Take Over mode will enable itself if the default TypeScript extension is disabled.
2. Reload the VS Code window by running `Developer: Reload Window` from the command palette.
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:

You can learn more about Take Over mode [here](https://github.com/johnsoncodehk/volar/discussions/471).
1. Disable the built-in TypeScript Extension
1. Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2. Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
2 changes: 0 additions & 2 deletions packages/create-vite/template-vue-ts/src/App.vue
@@ -1,6 +1,4 @@
<script setup lang="ts">
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://vuejs.org/api/sfc-script-setup.html#script-setup
import HelloWorld from './components/HelloWorld.vue'
</script>

Expand Down
6 changes: 0 additions & 6 deletions packages/create-vite/template-vue-ts/src/vite-env.d.ts
@@ -1,7 +1 @@
/// <reference types="vite/client" />

declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
2 changes: 1 addition & 1 deletion packages/create-vite/template-vue/.vscode/extensions.json
@@ -1,3 +1,3 @@
{
"recommendations": ["Vue.volar"]
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
}
2 changes: 1 addition & 1 deletion packages/create-vite/template-vue/README.md
Expand Up @@ -4,4 +4,4 @@ This template should help get you started developing with Vue 3 in Vite. The tem

## Recommended IDE Setup

- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
- [VS Code](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).
2 changes: 0 additions & 2 deletions packages/create-vite/template-vue/src/App.vue
@@ -1,6 +1,4 @@
<script setup>
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://vuejs.org/api/sfc-script-setup.html#script-setup
import HelloWorld from './components/HelloWorld.vue'
</script>

Expand Down

0 comments on commit 1a54e58

Please sign in to comment.