DNRN
DNRN

Reputation: 2499

exclude subdirectories in tsconfig.json

I have installed TypeScript 1.8.2, and using Visual Studio 2015. I have a simple project where I have problems excluding folders from the tsconfig.json file. The problem is I would like to exclude the file typings/browser.d.ts and the folder typings/browser. But this is not the case?

I have no problems excluding a subfolder, but not a sub-subfolder?

[NOTE] I just realized the problem is only when I build from Visual Studio! If i build with tsc from the command line, there's no problem. Could I have another version of TypeScript in Visual Studio? How can I check this?

This is my tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules",
    "public",
    "typings/browser",
    "typings/browser.d.ts"
  ]
}

I have a bigger project, where I use jspm and need to exclude the jspm package folder, which is located as a subfolder to public.

Upvotes: 47

Views: 101919

Answers (4)

Amid
Amid

Reputation: 22382

Try with:

{
  "compilerOptions": {/* ... */},

  "exclude": [
    "node_modules",
    "public",
    "typings/browser.d.ts",
    "typings/browser/**"
  ]
}

Upvotes: 52

Astra Bear
Astra Bear

Reputation: 2738

I am using ts V4.1.3 with webStorm 2021 and an exclude like exclude:[server/**] in tsconfig.json appeared to not be excluding, however I found it was only compiling if I opened one of the ts files in the editor.

I turned off WebStorm/File/Settings/Languages../TypeScript/Recompile On Changes and all is ok, ie it does not compile any ts files at any level in the server directory.

Upvotes: 0

Vinod Loha
Vinod Loha

Reputation: 31

Looks like this is a problem with typescript being unable to exclude paths/patterns that belong to deeper dir structure. Its still a problem with "typescript@^3.4.5".

To fix this I started cleaning my Dist dir with "rimraf dist" before every test run.

"test:unit": "npm run clean && stencil test --spec --snapshot",

I know its a hack, but works.

Upvotes: 3

SourceSimian
SourceSimian

Reputation: 740

I just installed and tested the latest version of TypeScript for Visual Studio 2015 (1.8.6 at the moment), and I can confirm that this problem has been fixed in the latest release.

https://www.microsoft.com/en-us/download/details.aspx?id=48593

[Edit] Be sure to also do an npm update -g typescript

Upvotes: 2

Related Questions