Ludwik Ludwik - 4 months ago 16
TypeScript Question

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?

Answer

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.