Exclude folder when compiling typescript

FCin picture FCin · Jan 4, 2017 · Viewed 13.8k times · Source

I use Atom to write code. It uses tsconfig.json to include and exclude folders. In order to use intellisense I need node_modules to be included, but when I want to compile it to js I don't want node_modules to be compiled. So I need to call tsc in the upper folder where the config.ts is, and this results in compiling the whole node_modules.

My folder structure looks like this:

node_modules
config.ts
spec
  |--test1.ts
  |--test2.ts

Any idea how to exclude node_modules when compiling with tsc command?

Answer

Andrew Luca picture Andrew Luca · Jan 4, 2017

Use exclude property

{
    "compilerOptions": {
        ...
    }
    "exclude": [
        "node_modules"
    ]
}

Files included using "include" can be filtered using the "exclude" property. However, files included explicitly using the "files" property are always included regardless of "exclude". The "exclude" property defaults to excluding the node_modules, bower_components, jspm_packages and directories when not specified.

https://www.typescriptlang.org/docs/handbook/tsconfig-json.html