Skip to content

Commit 5b778b2

Browse files
authored
feat: turn on noEmit by default and add tsconfig.lib.json (#26)
1 parent b1975ea commit 5b778b2

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ Otherwise, if you are trying to use Vue components in Node.js environments (e.g.
5959

6060
Make sure to place `@vue/tsconfig/tsconfig.json` *after* `@tsconfig/node18/tsconfig.json` so that it takes precedence.
6161

62+
## Emitting Declaration Files
63+
64+
As most Vue projects are built with bundlers, the default Vue TSConfig does not emit declaration files. If you are building a library or a component library, you can enable declaration file emitting by also extending `@vue/tsconfig/tsconfig.lib.json` in your `tsconfig.json`:
65+
66+
```json
67+
"extends": [
68+
"@vue/tsconfig/tsconfig.dom.json",
69+
"@vue/tsconfig/tsconfig.lib.json"
70+
]
71+
```
72+
6273
## Migrating from TypeScript < 5.0
6374

6475
- The usage of base `tsconfig.json` is unchanged.

tsconfig.json

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
{
22
"compilerOptions": {
3+
// Most non-library projects don't need to emit declarations.
4+
// So we add this option by default to make the config more friendly to most users.
5+
"noEmit": true,
6+
// When type-checking with solution-style tsconfigs, though with `noEmit: true`, there won't
7+
// be any `.d.ts` files emitted, but tsc still writes a `.tsbuildinfo` file to the `outDir`
8+
// for each project. If we don't explicitly set the `outDir`, it will be in the same folder
9+
// as the `tsconfig.json` file, which would look messy.
10+
// Setting it to `./dist/` isn't ideal either, because it would pollute the `dist` folder.
11+
// So we set it to a hidden folder in `node_modules` to avoid polluting the project root.
12+
"outDir": "./node_modules/.cache/vue-tsbuildinfo",
13+
314
// As long as you are using a build tool, we recommend you to author and ship in ES modules.
415
// Even if you are targeting Node.js, because
516
// - `CommonJS` is too outdated

tsconfig.lib.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"noEmit": false,
4+
"declaration": true,
5+
"emitDeclarationOnly": true,
6+
"outDir": "./dist/"
7+
}
8+
}

0 commit comments

Comments
 (0)