1 |
|
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 |
|
15 | Small tool to generate a dts bundle from your ts code.
|
16 |
|
17 | For example:
|
18 |
|
19 | ```ts
|
20 | // a.ts
|
21 | export class A {}
|
22 | ```
|
23 |
|
24 | ```ts
|
25 | // b.ts
|
26 | export class B {}
|
27 | ```
|
28 |
|
29 | ```ts
|
30 | // entry.ts
|
31 | import { A } from './a';
|
32 | import { B } from './b';
|
33 |
|
34 | declare function makeA(): A;
|
35 | export function makeB(): B {
|
36 | makeA();
|
37 | return new B();
|
38 | }
|
39 | ```
|
40 |
|
41 | When you run `dts-bundle-generator -o my.d.ts entry.ts` in `my.d.ts` you will get the following:
|
42 |
|
43 | ```ts
|
44 | declare class B {
|
45 | }
|
46 | export declare function makeB(): B;
|
47 | ```
|
48 |
|
49 | ## Installation
|
50 |
|
51 | 1. 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 |
|
63 | 1. Enable `declaration` compiler option in `tsconfig.json`
|
64 |
|
65 | ## Usage
|
66 |
|
67 | ```
|
68 | Usage: dts-bundle-generator [options] <file(s)>
|
69 |
|
70 | Options:
|
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 | --export-referenced-types By default all interfaces, types and const enums are marked as
|
110 | exported even if they aren't exported directly. This option allows
|
111 | you to disable this behavior so a node will be exported if it is
|
112 | exported from root source file only. [boolean] [default: true]
|
113 | --config File path to the generator config file [string]
|
114 | --no-banner Allows remove "Generated by dts-bundle-generator" comment from the
|
115 | output [boolean] [default: false]
|
116 | --version Show version number [boolean]
|
117 | ```
|
118 |
|
119 | Examples:
|
120 |
|
121 | ```bash
|
122 | ./node_modules/.bin/dts-bundle-generator -o my.d.ts path/to/your/entry-file.ts
|
123 | ```
|
124 |
|
125 | ```bash
|
126 | ./node_modules/.bin/dts-bundle-generator path/to/your/entry-file.ts path/to/your/entry-file-2.ts
|
127 | ```
|
128 |
|
129 | ```bash
|
130 | ./node_modules/.bin/dts-bundle-generator --external-inlines=@mycompany/internal-project --external-imports=@angular/core rxjs path/to/your/entry-file.ts
|
131 | ```
|
132 |
|
133 | ```bash
|
134 | ./node_modules/.bin/dts-bundle-generator --external-types=jquery path/to/your/entry-file.ts
|
135 | ```
|
136 |
|
137 | ## Config file
|
138 |
|
139 | It is unnecessary, but you can use config file for the tool. See [config documentation](src/config-file/README.md) for more information.
|
140 |
|
141 | ## Why
|
142 |
|
143 | If you have modules then you can create definitions by default using `tsc`, but `tsc` generates them for each module separately.
|
144 | Yeah, you can use `outFile` (for `amd` and `system`), but generated code looks like this:
|
145 |
|
146 | ```ts
|
147 | declare module "a" {
|
148 | export class A {
|
149 | }
|
150 | }
|
151 | declare module "b" {
|
152 | export class B {
|
153 | }
|
154 | }
|
155 | declare module "entry" {
|
156 | import { B } from "b";
|
157 | export function makeB(): B;
|
158 | }
|
159 | ```
|
160 |
|
161 | but:
|
162 |
|
163 | 1. `A` is not used at all and most probably you do not want to export it.
|
164 | 1. 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.
|
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
|