How to generate d.ts and d.ts.map files using webpack?
Running ts-loader
before babel-loader
will do the trick.
Specifying that you want declaration files in config is all you need.
If you are using an absolute path, the output d.ts files will also contain absolute paths which are useless and will result in typescript compilation errors.
To fix that, I wrote a plugin to convert an absolute path to a relative path: https://github.com/stavalfi/babel-plugin-module-resolver-loader
You can call the Typescript compiler tsc
directly to do that.
Use tsc --declaration
to output a .d.ts
file and tsc --declarationMap
to generate the corresponding map file.
You can find more documentation here: https://www.typescriptlang.org/docs/handbook/compiler-options.html