egoist / egoist/tsup

Excluding files from the build

Open
#590 5 comments 2 reactions 0 assignees View on GitHub
need repro
Dominant language
TypeScript
Stars
11.3k
Forks
275
PR merge metrics
No merged PRs in 30d

Description

Hello

How can we exclude files from compilation (for example test files ending with .spec.ts)? I tried https://github.com/egoist/tsup/issues/415 but it errored:

```
ESM Build failed
Error: Build failed with 1 error:
error: The entry point "./src/api.spec.ts" cannot be marked as external
```

Then I switched from using `npx tsup src` to `npx tsup src/index.ts` and I got an error that other files are imported but are not entrypoints.

```
src/index.ts(1,15): error TS6307: File '/src/endpoints.ts' is not listed within the file list of project ''. Projects must list all files or use an 'include' pattern.
The file is in the program because:
Imported via './endpoints' from file '/src/index.ts'
Imported via './endpoints' from file '/api.ts'
src/index.ts(3,15): error TS6307: File '/src/api.ts' is not listed within the file list of project ''. Projects must list all files or use an 'include' pattern.
```

Then I tried to "include" everything under "./src" in tsconfig.json, but it didn't help.

Then I tried to use the glob library to exactly specify my import files and exclude test files, but I don't think tsup supports asynchronous configs?

Is there a way to exclude files within the src directory (preferably without creating a node script that calls tsup's "build" directly)?

Contributor guide

Open the contributing guide

Research direction

Reproduce the reported `npx tsup src` and `npx tsup src/index.ts` commands with the described `tsconfig.json` setup, then inspect how tsup handles entry files and imported files. Done means providing a supported way to exclude `*.spec.ts` files under `src` without requiring a custom build script.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.