Skip to content

Commit 702c855

Browse files
committed
docs(typescript): declaration file output to same directory. fixes #934
1 parent 3a5a32d commit 702c855

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

packages/typescript/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,54 @@ export default {
279279

280280
Previous versions of this plugin used Typescript's `transpileModule` API, which is faster but does not perform typechecking and does not support cross-file features like `const enum`s and emit-less types. If you want this behaviour, you can use [@rollup/plugin-sucrase](https://github.com/rollup/plugins/tree/master/packages/sucrase) instead.
281281

282+
### Declaration Output With `output.file`
283+
284+
When instructing Rollup to output a specific file name via the `output.file` Rollup configuration, and TypeScript to output declaration files, users may encounter a situation where the declarations are nested improperly. And additionally when attempting to fix the improper nesting via use of `outDir` or `declarationDir` result in further TypeScript errors.
285+
286+
Consider the following `rollup.config.js` file:
287+
288+
```js
289+
import typescript from '@rollup/plugin-typescript';
290+
291+
export default {
292+
input: 'src/index.ts',
293+
output: {
294+
file: 'dist/index.mjs'
295+
},
296+
plugins: [typescript({ tsconfig: './tsconfig.json' })]
297+
};
298+
```
299+
300+
And accompanying `tsconfig.json` file:
301+
302+
```json
303+
{
304+
"include": ["*"],
305+
"compilerOptions": {
306+
"outDir": "dist",
307+
"declaration": true
308+
}
309+
}
310+
```
311+
312+
This setup will produce `dist/index.mjs` and `dist/dist/index.d.ts`. To correctly place the declaration file, add an `exclude` setting in `tsconfig` and modify the `declarationDir` setting in `compilerOptions` to resemble:
313+
314+
```json
315+
{
316+
"include": ["*"],
317+
"exclude": ["dist"],
318+
"compilerOptions": {
319+
"outDir": "dist",
320+
"declaration": true,
321+
"declarationDir": "."
322+
}
323+
}
324+
```
325+
326+
This will result in the correct output of `dist/index.mjs` and `dist/index.d.ts`.
327+
328+
_For reference, please see the workaround this section is based on [here](https://github.com/microsoft/bistring/commit/7e57116c812ae2c01f383c234f3b447f733b5d0c)_
329+
282330
## Meta
283331

284332
[CONTRIBUTING](/.github/CONTRIBUTING.md)

0 commit comments

Comments
 (0)