tsup: Excluding Files From the Build
Created: Nov 04, 2023 – Last Updated: Nov 04, 2023
Tags: ToolingDigital Garden
One common problem I ran into was that I needed to exclude files from the build output, namely test files. Because my Jest/Vitest files are most often inside a
__tests__ folder inside
src or alongside the source files with a postfix of
You can use the CLI to give tsup its inputs:
This would build all files inside the
src directory. In a configuration file it would look like this:
tsup uses globby (opens in a new tab) under the hood for its pattern matching inside
entry so you can also use
! to notate a negative pattern.
To exclude files inside
<filename>.test.<ext> files, you can modify the
entry to this:
Feel free to use a less verbose configuration (since you can combine this logic into one pattern) and test it with e.g. globster.xyz (opens in a new tab).