3.0.4 • Published 2 months ago

dtsc v3.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

dtsc

npm GitHub

Generate bundled TypeScript declaration files.

Background

TypeScript has a 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:

// 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:

// 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.

// tsconfig.json
{
  "compilerOptions": {
    "rootDir": "src",
    "outFile": "lib/index.d.ts",
  },
  "include": [
    "src",
  ],
}
// package.json
{
  "typings": "lib/index.d.ts",
  "scripts": {
    "build": "dtsc",
  },
}
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: augment tsc with non-typescript files support
3.0.4

2 months ago

3.0.3

3 months ago

3.0.2

3 months ago

3.0.1

4 months ago

3.0.0

4 months ago

2.3.0

1 year ago

2.2.4

1 year ago

2.2.3

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.1

2 years ago

2.2.2

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.1.0

2 years ago