tsup: Excluding Files From the Build
tsup is a popular bundler powered by esbuild. You can bundle, transform, and minify JavaScript and TypeScript with it.
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 <filename>.test.<ext>.
You can use the CLI to give tsup its inputs:
tsup srcThis would build all files inside the src directory. In a configuration file it would look like this:
import { defineConfig } from 'tsup'
export default defineConfig({ entry: ['src'],})tsup uses globby under the hood for its pattern matching inside entry so you can also use ! to notate a negative pattern.
To exclude files inside __tests__ or <filename>.test.<ext> files, you can modify the entry to this:
import { defineConfig } from 'tsup'
export default defineConfig({ entry: ['src', '!src/**/__tests__/**', '!src/**/*.test.*'],})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.