tsdown: Excluding Files From the Build
Created: – Last Updated:
tsdown (opens in a new tab) is a bundler powered by Rolldown that can bundle individual files or whole directories for you. If you’re choosing a directory as your entry (e.g. src folder) you might bundle test files, too. They’ll end up in your dist folder and shipped to npm.
So your tsdown configuration might look like this:
import { defineConfig } from 'tsdown'
export default defineConfig([ { entry: ['src'], platform: 'neutral', dts: true, },])The entry option supports glob patterns (opens in a new tab). You can use this feature to exclude test files from your entry.
In the example below any files that have .test. in their name or are in the __tests__ folder will be excluded.
import { defineConfig } from 'tsdown'
export default defineConfig([ { entry: ['src', '!src/**/__tests__/**', '!src/**/*.test.*'], platform: 'neutral', dts: true, },])With ! you can negate a pattern. If you’re unsure how your glob pattern will affect the output, you can also try websites like globster.xyz (opens in a new tab).
Need a tsup version of this? Read tsup: Excluding Files From the Build.