developit / microbundle

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

Individually exported types are not included in the build, even if they're referenced/exported by an entry point #889

Closed carpeliam closed 3 years ago

carpeliam commented 3 years ago

I have a TypeScript package with a number of types in different files underneath a src/resources directory. Though these files and their types are alternately imported and/or exported from src/index.ts (which is my entry point/source within package.json), many of them are excluded, unless I export * all the way down.

Just from experimenting, it looks like:

Expected behavior: if I export { Type } from './location' from an entry point, then './dist/location.d.ts is created/built, ideally with only the types or other resources that have been exported or depended on from the entry point.

Workaround: run tsc src/index.ts --outDir dist --declaration --emitDeclarationOnly --esModuleInterop AFTER running microbundle to create ALL types referenced by entry point. This doesn't prune unused types, but it's a start!

Small sample to reproduce: https://github.com/carpeliam/microbundle-where-are-my-types

I'm hoping this is just user error, please let me know if I have a problem in my package.json or tsconfig.json or if this isn't a use case that microbundle is focusing on. Thanks all for building a sweet bundler!

illumincrotty commented 3 years ago

This is a pretty common problem (see #868 #855), the cause/solution is here. You need to add an include section to your tsconfig as shown below

file: tsconfig.json
{
    "compilerOptions": { ... },
    "include": ["src/**/*"]
}
carpeliam commented 3 years ago

Thank you! I searched for issues but somehow missed these.

agilgur5 commented 2 years ago

Thought I'd update here that I fixed the root cause upstream in https://github.com/ezolenko/rollup-plugin-typescript2/pull/406, which was released in rpt2 0.34.0.

The tsconfig include workaround should no longer be necessary, and one can now use tsconfig files instead.