Skip to content

Commit

Permalink
feat: turn on noEmit by default and add tsconfig.lib.json (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
haoqunjiang authored Dec 15, 2023
1 parent b1975ea commit 5b778b2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ Otherwise, if you are trying to use Vue components in Node.js environments (e.g.

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

## Emitting Declaration Files

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`:

```json
"extends": [
"@vue/tsconfig/tsconfig.dom.json",
"@vue/tsconfig/tsconfig.lib.json"
]
```

## Migrating from TypeScript < 5.0

- The usage of base `tsconfig.json` is unchanged.
Expand Down
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
{
"compilerOptions": {
// Most non-library projects don't need to emit declarations.
// So we add this option by default to make the config more friendly to most users.
"noEmit": true,
// When type-checking with solution-style tsconfigs, though with `noEmit: true`, there won't
// be any `.d.ts` files emitted, but tsc still writes a `.tsbuildinfo` file to the `outDir`
// for each project. If we don't explicitly set the `outDir`, it will be in the same folder
// as the `tsconfig.json` file, which would look messy.
// Setting it to `./dist/` isn't ideal either, because it would pollute the `dist` folder.
// So we set it to a hidden folder in `node_modules` to avoid polluting the project root.
"outDir": "./node_modules/.cache/vue-tsbuildinfo",

// As long as you are using a build tool, we recommend you to author and ship in ES modules.
// Even if you are targeting Node.js, because
// - `CommonJS` is too outdated
Expand Down
8 changes: 8 additions & 0 deletions tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"noEmit": false,
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "./dist/"
}
}

0 comments on commit 5b778b2

Please sign in to comment.