Exclude folder when compiling typescript

53.6k Views Asked by At

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?

1

There are 1 best solutions below

2
On

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.

link updated: https://www.typescriptlang.org/tsconfig#exclude