Typescript tsconfig to exclude some source files

Nicholas Mordecai picture Nicholas Mordecai · Apr 21, 2017 · Viewed 12.6k times · Source

I am trying to get Typescript to exclude certain files when compiling. However it doesn't seem to want to exclude them.

Here is my tsconfig.json

{
  "ref": "master",
  "path": "typings",
  "compilerOptions": {
    "module": "amd",
    "target": "es5",
    "declaration": true,
    "sourceMap": true,
    "outDir": "build/src"
  },
  "exclude": [
    "node_modules",
    "typings/global",
    "typings/index.d.ts",
    "./src/subClassA.ts"
  ],
  "files": [
    "./src/entry.ts"
  ]
}

It seems to be excluding the node_modules and typings. However the compiled code, still includes subClassA.

I would have expected the compiled code to not have any of the code from subClassA, however it does.

Answer

Saravana picture Saravana · Apr 21, 2017

From the documentation:

Any files that are referenced by files included via the "files" or "include" properties are also included. Similarly, if a file B.ts is referenced by another file A.ts, then B.ts cannot be excluded unless the referencing file A.ts is also specified in the "exclude" list.

If your ./src/entry.ts file or any dependency of ./src/entry.ts uses ./src/subClassA.ts somewhere, then ./src/subClassA.ts cannot be excluded unless ./src/entry.ts is excluded too.

Related discussion: https://github.com/Microsoft/TypeScript/issues/7432