Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typescript tsconfig.json include exclude not working

I have a web project

I have folders

src/app/shared/models
src/app/shared/services
src/app/shared/types

Each one of those is subfolder that have folders or files inside it, I want to exclude those folders, So i tried:

  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts",
    "src/app/shared/**/*"
  ]

and its not working, even "src/app/shared/*" not working, How I can do it?

My tsconfig.json now:

{
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2015",
      "dom"
    ]
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts",
    "src/app/shared/**/*"
  ]
}

Thanks

like image 957
Zakk Avatar asked Oct 15 '17 12:10

Zakk


People also ask

What is include and exclude in Tsconfig json?

The include and exclude properties take a list of glob-like file patterns. The supported glob wildcards are: * matches zero or more characters (excluding directory separators) ? matches any one character (excluding directory separators)

What is exclude in Tsconfig json?

json file. The exclude array contains filenames or patterns that should be skipped when resolving the include array. The exclude option changes what the include option finds, effectively filtering out some folders or files from compilation.

What is Lib in Tsconfig json?

TypeScript includes a default set of type definitions for built-in JS APIs (like Math ), as well as type definitions for things found in browser environments (like document ).


1 Answers

The first thing to consider, if you decide to use the “exclude” keyword to list files is that, in order to remove them from the compilation process, you will need also to exclude any other files, which by using either a triple-slash directive "/// <reference path="..." />" or an "import" statement refer to a file in your excluded list.

tsconfig.json turns a folder into a “project”. Without specifying any “exclude” or “files” entries, all files in the folder containing the tsconfig.json and all its sub-directories are included in your compilation.

tsconfig.json automatic inclusion does not embed module resolution. If the compiler identified a file as a target of a module import, it will be included in the compilation regardless if it was excluded in the previous steps.

The include and exclude properties take a list of glob-like file patterns. The supported glob wildcards are:

  • * matches zero or more characters (excluding directory separators)
  • ? matches any one character (excluding directory separators)
  • **/ recursively matches any subdirectory

When using the files property it takes a list of relative or absolute file paths.

Setting "baseUrl" informs the compiler where to find modules. All module imports with non-relative names are assumed to be relative to the baseUrl.

Files included using "include" can be filtered using the "exclude" property. However, if you include files explicitly using the "files" property they would be always included regardless of "exclude".

like image 69
Benjamin Vincent Avatar answered Sep 20 '22 08:09

Benjamin Vincent