UNPKG

9.74 kBMarkdownView Raw
1<!-- markdownlint-disable MD033 -->
2
3<div align="center">
4 <a href="https://github.com/timocov/dts-bundle-generator">
5 <img width="250px" height="250px" src="https://github.com/timocov/dts-bundle-generator/raw/master/.github/logo.svg?sanitize=true">
6 </a>
7</div>
8
9# DTS Bundle Generator
10
11[![GH Actions][ci-img]][ci-link]
12[![npm version][npm-version-img]][npm-link]
13[![Downloads][npm-downloads-img]][npm-link]
14
15Small tool to generate a dts bundle from your ts code.
16
17For example:
18
19```ts
20// a.ts
21export class A {}
22```
23
24```ts
25// b.ts
26export class B {}
27```
28
29```ts
30// entry.ts
31import { A } from './a';
32import { B } from './b';
33
34declare function makeA(): A;
35export function makeB(): B {
36 makeA();
37 return new B();
38}
39```
40
41When you run `dts-bundle-generator -o my.d.ts entry.ts` in `my.d.ts` you will get the following:
42
43```ts
44declare class B {
45}
46export declare function makeB(): B;
47```
48
49## Installation
50
511. Install the package from `npm`:
52
53 ```bash
54 npm install --save-dev dts-bundle-generator
55 ```
56
57 or
58
59 ```bash
60 npm install -g dts-bundle-generator
61 ```
62
631. Enable `declaration` compiler option in `tsconfig.json`
64
65## Usage
66
67```
68Usage: dts-bundle-generator.js [options] <file(s)>
69
70Options:
71 --help Show help [boolean]
72 --out-file, -o File name of generated d.ts [string]
73 --verbose Enable verbose logging [boolean] [default: false]
74 --silent Disable any logging except errors [boolean] [default: false]
75 --no-check Skip validation of generated d.ts file [boolean] [default: false]
76 --fail-on-class Fail if generated dts contains class declaration
77 [boolean] [default: false]
78 --external-inlines Array of package names from node_modules to inline typings from.
79 Used types will be inlined into the output file [array]
80 --external-imports Array of package names from node_modules to import typings from.
81 Used types will be imported using "import { First, Second } from
82 'library-name';".
83 By default all libraries will be imported (except inlined libraries
84 and libraries from @types) [array]
85 --external-types Array of package names from @types to import typings from via the
86 triple-slash reference directive.
87 By default all packages are allowed and will be used according to
88 their usages [array]
89 --umd-module-name Name of the UMD module. If specified then `export as namespace
90 ModuleName;` will be emitted [string]
91 --project Path to the tsconfig.json file that will be used for the
92 compilation [string]
93 --sort Sort output nodes [boolean] [default: false]
94 --inline-declare-global Enables inlining of `declare global` statements contained in files
95 which should be inlined (all local files and packages from
96 `--external-inlines`) [boolean] [default: false]
97 --inline-declare-externals Enables inlining of `declare module` statements of the global
98 modules (e.g. `declare module 'external-module' {}`, but NOT
99 `declare module './internal-module' {}`) contained in files which
100 should be inlined (all local files and packages from inlined
101 libraries) [boolean] [default: false]
102 --disable-symlinks-following (EXPERIMENTAL) Disables resolving of symlinks to the original path.
103 See https://github.com/timocov/dts-bundle-generator/issues/39 for
104 more information [boolean] [default: false]
105 --respect-preserve-const-enum Enables stripping the `const` keyword from every direct-exported
106 (or re-exported) from entry file `const enum`. See
107 https://github.com/timocov/dts-bundle-generator/issues/110 for more
108 information [boolean] [default: false]
109 --config File path to the generator config file [string]
110 --no-banner Allows remove "Generated by dts-bundle-generator" comment from the
111 output [boolean] [default: false]
112 --version Show version number [boolean]
113```
114
115Examples:
116
117```bash
118./node_modules/.bin/dts-bundle-generator -o my.d.ts path/to/your/entry-file.ts
119```
120
121```bash
122./node_modules/.bin/dts-bundle-generator path/to/your/entry-file.ts path/to/your/entry-file-2.ts
123```
124
125```bash
126./node_modules/.bin/dts-bundle-generator --external-inlines=@mycompany/internal-project --external-imports=@angular/core,rxjs path/to/your/entry-file.ts
127```
128
129```bash
130./node_modules/.bin/dts-bundle-generator --external-types=jquery path/to/your/entry-file.ts
131```
132
133## Config file
134
135It is unnecessary, but you can use config file for the tool. See [config documentation](src/config-file/README.md) for more information.
136
137## Why
138
139If you have modules then you can create definitions by default using `tsc`, but `tsc` generates them for each module separately.
140Yeah, you can use `outFile` (for `amd` and `system`), but generated code looks like this:
141
142```ts
143declare module "a" {
144 export class A {
145 }
146}
147declare module "b" {
148 export class B {
149 }
150}
151declare module "entry" {
152 import { B } from "b";
153 export function makeB(): B;
154}
155```
156
157but:
158
1591. `A` is not used at all and most probably you do not want to export it.
1601. If you bundle your code in a way when all modules are merged (like when using Webpack or Rollup) then there should be no such modules as `a` or `b` (actually `entry` too) in the resulting file.
161
162## Known limitations
163
1641. All your types should have different names inside a bundle. If you have 2 `interface Options {}` they will be merged by `TypeScript` and you will get wrong definitions.
165
166[ci-img]: https://github.com/timocov/dts-bundle-generator/workflows/CI%20Test/badge.svg?branch=master
167[ci-link]: https://github.com/timocov/dts-bundle-generator/actions?query=branch%3Amaster
168
169[npm-version-img]: https://badge.fury.io/js/dts-bundle-generator.svg
170[npm-downloads-img]: https://img.shields.io/npm/dm/dts-bundle-generator.svg
171[npm-link]: https://www.npmjs.com/package/dts-bundle-generator
172
173## Contributors
174
175### Code Contributors
176
177This project exists thanks to all the people who contribute.
178<a href="https://github.com/timocov/dts-bundle-generator/graphs/contributors"><img src="https://opencollective.com/dts-bundle-generator/contributors.svg?width=890&button=false" /></a>
179
180### Financial Contributors
181
182Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/dts-bundle-generator/contribute)]
183
184#### Individuals
185
186<a href="https://opencollective.com/dts-bundle-generator"><img src="https://opencollective.com/dts-bundle-generator/individuals.svg?width=890"></a>
187
188#### Organizations
189
190Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/dts-bundle-generator/contribute)]
191
192<a href="https://opencollective.com/dts-bundle-generator/organization/0/website"><img src="https://opencollective.com/dts-bundle-generator/organization/0/avatar.svg"></a>
193<a href="https://opencollective.com/dts-bundle-generator/organization/1/website"><img src="https://opencollective.com/dts-bundle-generator/organization/1/avatar.svg"></a>
194<a href="https://opencollective.com/dts-bundle-generator/organization/2/website"><img src="https://opencollective.com/dts-bundle-generator/organization/2/avatar.svg"></a>
195<a href="https://opencollective.com/dts-bundle-generator/organization/3/website"><img src="https://opencollective.com/dts-bundle-generator/organization/3/avatar.svg"></a>
196<a href="https://opencollective.com/dts-bundle-generator/organization/4/website"><img src="https://opencollective.com/dts-bundle-generator/organization/4/avatar.svg"></a>
197<a href="https://opencollective.com/dts-bundle-generator/organization/5/website"><img src="https://opencollective.com/dts-bundle-generator/organization/5/avatar.svg"></a>
198<a href="https://opencollective.com/dts-bundle-generator/organization/6/website"><img src="https://opencollective.com/dts-bundle-generator/organization/6/avatar.svg"></a>
199<a href="https://opencollective.com/dts-bundle-generator/organization/7/website"><img src="https://opencollective.com/dts-bundle-generator/organization/7/avatar.svg"></a>
200<a href="https://opencollective.com/dts-bundle-generator/organization/8/website"><img src="https://opencollective.com/dts-bundle-generator/organization/8/avatar.svg"></a>
201<a href="https://opencollective.com/dts-bundle-generator/organization/9/website"><img src="https://opencollective.com/dts-bundle-generator/organization/9/avatar.svg"></a>