Microbundle: How to avoid including types in dist that are not part of src/lib

Created on 15 May 2020  路  2Comments  路  Source: developit/microbundle

Repo: https://github.com/MartinMalinda/vue-concurrency

In my dist, besides the actual bundles, I also have a src folder with type files (index.d.ts, Task.d.ts and so on). That seems correct and much needed.

But besides that there's also typing being created for the whole __tests__ and test-utils folders and also there's jest.config.d.ts. These things probably shouldn't be included as part of the main bundle.

Is there a way to avoid it? Maybe it's some silly mistake on my side.

Thanks!

Most helpful comment

Ultimately that boils down to how TypeScript is configured in your project. From a quick glance it looks like everything will be compiled with TS and thus everything will get a definition file.

You can limit that to only the folders/files you want to be included by creating a separate tsconfig file for building.

{
  "extends": "./tsconfig",
  "exclude": ["**/*.test.ts", "**/*.mock.ts"]
}

And then specify that when running your build like so:

microbundle build --tsconfig tsconfig.build.json

The TypeScript team has a page in their docs about these fields.

All 2 comments

Ultimately that boils down to how TypeScript is configured in your project. From a quick glance it looks like everything will be compiled with TS and thus everything will get a definition file.

You can limit that to only the folders/files you want to be included by creating a separate tsconfig file for building.

{
  "extends": "./tsconfig",
  "exclude": ["**/*.test.ts", "**/*.mock.ts"]
}

And then specify that when running your build like so:

microbundle build --tsconfig tsconfig.build.json

The TypeScript team has a page in their docs about these fields.

thanks for the great answer, it makes total sense

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smithki picture smithki  路  19Comments

developit picture developit  路  14Comments

Conaclos picture Conaclos  路  11Comments

phryneas picture phryneas  路  12Comments

prateekbh picture prateekbh  路  17Comments