developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8.04k stars 362 forks source link

How to handle declaration files for pure javascript libraries? #925

Closed arthurfiorette closed 2 years ago

arthurfiorette commented 2 years ago

For really small projects, like single-file ones, using typescript is overkill. So what I usually do is just manually write my own declaration files. The result of a simple example is something like this:

├── src
│   ├── index.d.ts
│   └── index.js

If I use types in my package.json, microbundle will replace that with what it could generate based on the jsdoc from the index.js file. I also tried with /// triple slash directives, didn't work.

Is there a way that I can tell microbundle to get that declaration file and use it?

rschristian commented 2 years ago

You can use the --generateTypes flag:

$ microbundle build --generateTypes=false

It won't copy your types to your output directory, so if you only distribute dist/, you'll need to do a post-build copy yourself.

developit commented 2 years ago

Yep! I stick them in the repo root too, to ease publishing.