0.3.2 • Published 5 years ago
homemade-dts-bundler v0.3.2
Homemade DTS bundler
As dts-bundle, this module bundles .d.ts files with a simple approach. It is not fully tested and may not work in your project.
In this approach, each .d.ts file is wrapped in a declare module statement, relative imports are resolved through this module scope and augmentations (declaration merging) should be preserved.
See a sample output in /dist/index.d.ts of a release.
Usage
Install it (you can also use a global install):
npm install homemade-dts-bundle
Compile your typescript project with --declaration
option.
Run homemade-dts-bundle:
./bin/homemade-dts-bundler --entry .declaration/index.d.ts --output index.d.ts --libraryName my-lib
See the options:
./bin/homemade-dts-bundler -h
Usage with webpack
The module come with a webpack plugin. In this case, files will be readed/writed through the webpack compilation assets.
const { HomemadeDTSBundlerPlugin } = require("homemade-dts-bundler");
module.exports = {
entry: "src/index.ts",
output: {
filename: "mylib.js",
path: "dist",
library: "mylib",
libraryTarget: "commonjs2",
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "ts-loader",
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".ts", ".js"],
},
plugins: [new HomemadeDTSBundlerPlugin({
entry: "dist/.declaration/index.d.ts",
output: "dist/index.d.ts",
libraryName: "mylib",
})],
};
Usage programmatic
.d.ts is provided with comments for programmatic usage.