diff --git a/README.md b/README.md index f05e195..d94ee10 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/tsconfig.json b/tsconfig.json index d185ef8..f612826 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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 diff --git a/tsconfig.lib.json b/tsconfig.lib.json new file mode 100644 index 0000000..4812721 --- /dev/null +++ b/tsconfig.lib.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "noEmit": false, + "declaration": true, + "emitDeclarationOnly": true, + "outDir": "./dist/" + } +}