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

Commit f052591

Browse files
committed
docs: add notes about Nuxt with TS
1 parent 1d37e07 commit f052591

File tree

5 files changed

+546
-3
lines changed

5 files changed

+546
-3
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,37 @@ export default {
6262
6363
Example: [`examples/nuxt`](./examples/nuxt)
6464

65+
###### TypeScript
66+
67+
To use TypeScript with Nuxt, install the [`@nuxtjs/typescript-module`](https://typescript.nuxtjs.org/) but disable the type check:
68+
69+
```bash
70+
npm i -D @nuxt/typescript-build vue-tsc
71+
```
72+
73+
```ts
74+
// nuxt.config.js
75+
export default {
76+
buildModules: [
77+
['@nuxt/typescript-build', { typeCheck: false }],
78+
'@nuxtjs/composition-api/module',
79+
'vue2-script-setup-transform/nuxt',
80+
],
81+
}
82+
```
83+
84+
And then use [`vue-tsc`](https://github.com/johnsoncodehk/volar) to do the type check at build time:
85+
86+
```jsonc
87+
// package.json
88+
{
89+
"scripts": {
90+
"dev": "nuxt",
91+
"build": "vue-tsc --noEmit && nuxt build",
92+
}
93+
}
94+
```
95+
6596
<br></details>
6697

6798
<details>

examples/nuxt/nuxt.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
export default {
22
buildModules: [
3-
'@nuxt/typescript-build',
3+
// we disable the type check and left it to `vue-tsc`
4+
['@nuxt/typescript-build', { typeCheck: false }],
5+
// @vue/composition-api support
46
'@nuxtjs/composition-api/module',
7+
// install the transformer
58
'vue2-script-setup-transform/nuxt',
69
],
710
}

examples/nuxt/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"scripts": {
55
"dev": "nuxt",
6-
"build": "nuxt build",
6+
"build": "vue-tsc --noEmit && nuxt build",
77
"start": "nuxt start",
88
"generate": "nuxt generate"
99
},
@@ -16,6 +16,7 @@
1616
"@nuxt/typescript-build": "^2.1.0",
1717
"@nuxtjs/composition-api": "^0.27.0",
1818
"@vue/runtime-dom": "^3.2.4",
19+
"vue-tsc": "^0.3.0",
1920
"vue2-script-setup-transform": "workspace:*"
2021
}
2122
}

examples/nuxt/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"DOM"
1010
],
1111
"esModuleInterop": true,
12+
"skipLibCheck": true,
1213
"allowJs": true,
1314
"sourceMap": true,
1415
"strict": true,
@@ -24,7 +25,8 @@
2425
},
2526
"types": [
2627
"@types/node",
27-
"@nuxt/types"
28+
"@nuxt/types",
29+
"vue2-script-setup-transform/types"
2830
]
2931
},
3032
"exclude": [

0 commit comments

Comments
 (0)