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

Commit ef9b63c

Browse files
committed
docs: vue-cli with ts, close #14
1 parent f052591 commit ef9b63c

File tree

10 files changed

+393
-17
lines changed

10 files changed

+393
-17
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ And then use [`vue-tsc`](https://github.com/johnsoncodehk/volar) to do the type
8888
{
8989
"scripts": {
9090
"dev": "nuxt",
91-
"build": "vue-tsc --noEmit && nuxt build",
91+
"build": "vue-tsc --noEmit && nuxt build"
9292
}
9393
}
9494
```
@@ -112,6 +112,40 @@ module.exports = {
112112

113113
Example: [`examples/vue-cli`](./examples/vue-cli)
114114

115+
###### TypeScript
116+
117+
To use TypeScript with Vue CLI, install `@vue/cli-plugin-typescript` but disable the type check:
118+
119+
```bash
120+
npm i -D @vue/cli-plugin-typescript vue-tsc
121+
```
122+
123+
```ts
124+
module.exports = {
125+
configureWebpack: {
126+
plugins: [
127+
require('vue2-script-setup-transform/webpack-plugin').default(),
128+
],
129+
},
130+
chainWebpack(config) {
131+
// disable type check and let `vue-tsc` handles it
132+
config.plugins.delete('fork-ts-checker')
133+
},
134+
}
135+
```
136+
137+
And then use [`vue-tsc`](https://github.com/johnsoncodehk/volar) to do the type check at build time:
138+
139+
```jsonc
140+
// package.json
141+
{
142+
"scripts": {
143+
"dev": "vue-cli-service serve",
144+
"build": "vue-tsc --noEmit && vue-cli-service build"
145+
}
146+
}
147+
```
148+
115149
<br></details>
116150

117151
<details>

examples/vue-cli/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"scripts": {
55
"dev": "vue-cli-service serve",
6-
"build": "vue-cli-service build",
6+
"build": "vue-tsc --noEmit && vue-cli-service build",
77
"lint": "vue-cli-service lint"
88
},
99
"dependencies": {
@@ -12,8 +12,11 @@
1212
},
1313
"devDependencies": {
1414
"@vue/cli-plugin-babel": "~4.5.0",
15+
"@vue/cli-plugin-typescript": "~4.5.0",
1516
"@vue/cli-service": "~4.5.0",
17+
"typescript": "~4.1.5",
1618
"vue-template-compiler": "^2.6.11",
19+
"vue-tsc": "^0.3.0",
1720
"vue2-script-setup-transform": "workspace:*"
1821
}
1922
}

examples/vue-cli/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</div>
55
</template>
66

7-
<script setup>
7+
<script setup lang="ts">
88
import HelloWorld from './components/HelloWorld.vue'
99
</script>
1010

examples/vue-cli/src/components/HelloWorld.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
</p>
99
<h3>Installed CLI Plugins</h3>
1010
<ul>
11-
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
12-
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
11+
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-typescript" target="_blank" rel="noopener">typescript</a></li>
1312
</ul>
1413
<h3>Essential Links</h3>
1514
<ul>
@@ -30,7 +29,7 @@
3029
</div>
3130
</template>
3231

33-
<script setup>
32+
<script setup lang="ts">
3433
defineProps({
3534
msg: String,
3635
})

examples/vue-cli/src/main.js renamed to examples/vue-cli/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import App from './App.vue'
55
Vue.config.productionTip = false
66
Vue.use(VueCompostionAPI)
77

8-
const app = new Vue({ render: h => h(App) })
8+
const app = new Vue({ render: h => h(App as any) })
99

1010
app.$mount('#app')

examples/vue-cli/src/shims-vue.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.vue' {
2+
import Vue from 'vue'
3+
export default Vue
4+
}

examples/vue-cli/tsconfig.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "esnext",
5+
"strict": true,
6+
"jsx": "preserve",
7+
"importHelpers": true,
8+
"moduleResolution": "node",
9+
"skipLibCheck": true,
10+
"esModuleInterop": true,
11+
"allowSyntheticDefaultImports": true,
12+
"sourceMap": true,
13+
"baseUrl": ".",
14+
"types": [
15+
"webpack-env",
16+
"vue2-script-setup-transform/types"
17+
],
18+
"paths": {
19+
"@/*": [
20+
"src/*"
21+
]
22+
},
23+
"lib": [
24+
"esnext",
25+
"dom",
26+
"dom.iterable",
27+
"scripthost"
28+
]
29+
},
30+
"include": [
31+
"src/**/*.ts",
32+
"src/**/*.tsx",
33+
"src/**/*.vue",
34+
"tests/**/*.ts",
35+
"tests/**/*.tsx"
36+
],
37+
"exclude": [
38+
"node_modules"
39+
]
40+
}

examples/vue-cli/vue.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ module.exports = {
1111
ScriptSetup(),
1212
],
1313
},
14+
chainWebpack(config) {
15+
// disable type check and let `vue-tsc` handles it
16+
config.plugins.delete('fork-ts-checker')
17+
},
1418
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"esno": "^0.9.1",
7878
"fast-glob": "^3.2.7",
7979
"jest": "^27.0.6",
80+
"log-editor": "^0.1.0",
8081
"rimraf": "^3.0.2",
8182
"ts-jest": "^27.0.5",
8283
"tsup": "^4.14.0",

0 commit comments

Comments
 (0)