Ludwik
Ludwik

Reputation: 2407

Typescript: How to compile only the files in a folder

The typescript docs state that in tsconfig.json we can control input files either with files where we list all files, or with exclude. I have all my source files in a src directory and only want to compile all files that are there (to a bifferent directory, build). I could exclude all other files and directories, but I might miss something. I don't want to manually add every file to files.

How can I specify to typescript that it should compile only the typescript files it finds in the src directory, and nothing else?

Upvotes: 18

Views: 18627

Answers (2)

Supriya
Supriya

Reputation: 1941

For anybody who stumbles across this question like I did -

Just like exclude, directories can be included as well now.

I include just my src directory like this to compile only my src:

"include": [
"./src/**/*"
]

Upvotes: 28

jonrsharpe
jonrsharpe

Reputation: 121987

According to the TypeScript documentation, the only way to do this within tsconfig.json is either to:

  1. Exhaustively list the files you do want to compile under files; or
  2. Exhaustively list the files and directories you don't want to compile under exclude.

It does mention that files referenced by included files will also be compiled, so it's possible that 1. wouldn't have to list everything individually, but I haven't tried that myself.

Upvotes: 4

Related Questions