https://github.com/shigma/dtsc
Generate bundled TypeScript declaration files
https://github.com/shigma/dtsc
Last synced: about 2 months ago
JSON representation
Generate bundled TypeScript declaration files
- Host: GitHub
- URL: https://github.com/shigma/dtsc
- Owner: shigma
- License: mit
- Created: 2022-05-20T15:09:00.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-03-04T16:04:12.000Z (over 1 year ago)
- Last Synced: 2024-10-05T11:41:51.610Z (8 months ago)
- Language: TypeScript
- Size: 48.8 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dtsc
[](https://www.npmjs.com/package/dtsc)
[](https://github.com/shigma/dtsc/blob/master/LICENSE)Generate bundled TypeScript declaration files.
## Background
TypeScript has a [`outFile`](https://www.typescriptlang.org/tsconfig/#outFile) compiler option:
> If specified, all global (non-module) files will be concatenated into the single output file specified.
>
> If module is system or amd, all module files will also be concatenated into this file after all global content.
>
> Note: outFile cannot be used unless module is None, System, or AMD. **This option cannot be used to bundle CommonJS or ES6 modules.**Supposing you have a project structure like this:
```
├── src
│ ├── index.ts
│ ├── foo.ts
│ └── bar.ts
├── package.json
└── tsconfig.json
```After running `tsc --outFile lib/index.d.ts`, the following file will be generated:
```ts
// lib/index.d.ts
declare module "foo" {
export function someMethod(): void;
}
declare module "bar" {
export function otherMethod(): void;
}
declare module "index" {
export * from "foo";
export * from "bar";
export * from "baz";
}
```However, what we really want is:
```ts
// lib/index.d.ts
export function someMethod(): void;
export function otherMethod(): void;
```This is where dtsc comes in. It generates a single bundled declaration file which behaves like other bundling tools.
## Usage
dtsc supports `outFile` option out of the box.
```jsonc
// tsconfig.json
{
"compilerOptions": {
"rootDir": "src",
"outFile": "lib/index.d.ts",
},
"include": [
"src",
],
}
``````jsonc
// package.json
{
"typings": "lib/index.d.ts",
"scripts": {
"build": "dtsc",
},
}
``````bash
npm run build
```## Limitations
This package uses a string-based approach to generate bundle from a .d.ts file. It may have some limitations:
- If you find one, welcome to report an issue.
## See also
- [atsc](https://github.com/shigma/atsc): augment tsc with non-typescript files support