How to include a file / subfolder from an excluded folder?

I have a situation where I need to include one file in a TSC assembly under a folder that contains other unnecessary files. How can I usually tell TSC in the tsconfig file that I need these specific files / subfolders from the folder, otherwise ignore it?

eg:

/.
 |-folder 1
     |->file2.ts 
 |->src.ts
 |-folder 2 //ignored
     |->file1.ts //This file is needed
     |->file2.ts //the rest should be ignored
     |->...

      

Due to the way we use namespaces in TS, I would like to include the @types folder from node modules, but ignore everything else. currently tsconfig.json:

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es5",
    "declaration": true,
    "removeComments": true,
    "sourceMap": true,
    "outFile": "Compile/Result.js",
    "jsx": "react"
  },
  "exclude": [
    "Compile/Result.d.ts",
    "node_modules"
  ],
  "include": [
    "node_modules/@types"
  ]
}

      

But it doesn't work at the moment

+3


source to share


2 answers


Files included with "include" can be filtered using the "exclude" property. However, files that are explicitly included using the files property are always included regardless of the exclusion. Use

"files": ["yourFilePath"]

      



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

0


source


Scaling your requirements:

/.
 |-folder 2 //ignored
     |->file1.ts //This file is needed
     |->file2.ts //the rest should be ignored
     |->...

      



Your config should be

"exclude": [
    "folder 2"
  ],
  "include": [
    "folder 2/file1.ts"
  ]

      

0


source







All Articles