Skip to content

Commit f8af00b

Browse files
committed
feat: tsInTemplates option for faster linting by disabling TypeScript syntax in Vue templates
Fixes #127
1 parent 91a85a9 commit f8af00b

31 files changed

+755
-18
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ import {
6363
} from '@vue/eslint-config-typescript'
6464

6565
configureVueProject({
66+
// Whether to parse TypeScript syntax in Vue templates.
67+
// Defaults to `true`.
68+
// Setting it to `false` could improve performance.
69+
// But TypeScript syntax in Vue templates will then lead to syntax errors.
70+
// Also, type-aware rules won't be applied to expressions in templates in that case.
71+
tsInTemplates: true,
72+
6673
// Optional: specify the script langs in `.vue` files
6774
// Defaults to `['ts']`.
6875
scriptLangs: [
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
.DS_Store
12+
dist
13+
dist-ssr
14+
coverage
15+
*.local
16+
17+
/cypress/videos/
18+
/cypress/screenshots/
19+
20+
# Editor directories and files
21+
.vscode/*
22+
!.vscode/extensions.json
23+
.idea
24+
*.suo
25+
*.ntvs*
26+
*.njsproj
27+
*.sln
28+
*.sw?
29+
30+
*.tsbuildinfo
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"Vue.volar",
4+
"dbaeumer.vscode-eslint"
5+
]
6+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# disable-ts-in-templates
2+
3+
This template should help get you started developing with Vue 3 in Vite.
4+
5+
## Recommended IDE Setup
6+
7+
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
8+
9+
## Type Support for `.vue` Imports in TS
10+
11+
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 [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
12+
13+
## Customize configuration
14+
15+
See [Vite Configuration Reference](https://vitejs.dev/config/).
16+
17+
## Project Setup
18+
19+
```sh
20+
npm install
21+
```
22+
23+
### Compile and Hot-Reload for Development
24+
25+
```sh
26+
npm run dev
27+
```
28+
29+
### Type-Check, Compile and Minify for Production
30+
31+
```sh
32+
npm run build
33+
```
34+
35+
### Lint with [ESLint](https://eslint.org/)
36+
37+
```sh
38+
npm run lint
39+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pluginVue from 'eslint-plugin-vue'
2+
import {
3+
configureVueProject,
4+
defineConfigWithVueTs,
5+
vueTsConfigs,
6+
} from '@vue/eslint-config-typescript'
7+
8+
configureVueProject({
9+
tsInTemplates: false,
10+
})
11+
12+
export default defineConfigWithVueTs(
13+
{
14+
name: 'app/files-to-lint',
15+
files: ['**/*.ts', '**/*.mts', '**/*.vue'],
16+
},
17+
18+
{
19+
name: 'app/files-to-ignore',
20+
ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
21+
},
22+
23+
pluginVue.configs['flat/essential'],
24+
vueTsConfigs.recommended,
25+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<link rel="icon" href="/favicon.ico">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "disable-ts-in-templates",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "run-p type-check \"build-only {@}\" --",
9+
"preview": "vite preview",
10+
"build-only": "vite build",
11+
"type-check": "vue-tsc --build --force",
12+
"lint": "eslint . --fix"
13+
},
14+
"dependencies": {
15+
"vue": "^3.5.13"
16+
},
17+
"devDependencies": {
18+
"@tsconfig/node20": "^20.1.4",
19+
"@types/node": "^20.17.12",
20+
"@vitejs/plugin-vue": "^5.2.1",
21+
"@vue/eslint-config-typescript": "workspace:*",
22+
"@vue/tsconfig": "^0.7.0",
23+
"eslint": "^9.18.0",
24+
"eslint-plugin-vue": "^9.32.0",
25+
"npm-run-all2": "^7.0.2",
26+
"typescript": "~5.7.3",
27+
"vite": "^6.0.7",
28+
"vue-tsc": "^2.2.0"
29+
}
30+
}
Binary file not shown.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<script setup lang="ts">
2+
import HelloWorld from './components/HelloWorld.vue'
3+
import TheWelcome from './components/TheWelcome.vue'
4+
</script>
5+
6+
<template>
7+
<header>
8+
<img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" />
9+
10+
<div class="wrapper">
11+
<HelloWorld msg="You did it!" />
12+
</div>
13+
</header>
14+
15+
<main>
16+
<TheWelcome />
17+
</main>
18+
</template>
19+
20+
<style scoped>
21+
header {
22+
line-height: 1.5;
23+
}
24+
25+
.logo {
26+
display: block;
27+
margin: 0 auto 2rem;
28+
}
29+
30+
@media (min-width: 1024px) {
31+
header {
32+
display: flex;
33+
place-items: center;
34+
padding-right: calc(var(--section-gap) / 2);
35+
}
36+
37+
.logo {
38+
margin: 0 2rem 0 0;
39+
}
40+
41+
header .wrapper {
42+
display: flex;
43+
place-items: flex-start;
44+
flex-wrap: wrap;
45+
}
46+
}
47+
</style>

0 commit comments

Comments
 (0)