Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude folder when compiling typescript

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?

like image 692
FCin Avatar asked Jan 04 '17 14:01

FCin


People also ask

What is include and exclude in Tsconfig?

The "include" property allows you to include a list of TypeScript files using the glob wildcards pattern. The "exclude" property allows you to exclude a list of TypeScript files using the glob wildcards pattern.

What is Skiplibcheck?

Skip type checking of declaration files. This can save time during compilation at the expense of type-system accuracy. For example, two libraries could define two copies of the same type in an inconsistent way. Rather than doing a full check of all d.

How does Tsconfig work?

The tsconfig. json file specifies the root files and the compiler options required to compile the project. JavaScript projects can use a jsconfig. json file instead, which acts almost the same but has some JavaScript-related compiler flags enabled by default.

Does TypeScript require compilation?

The TypeScript compiler compiles these files and outputs the JavaScript with . js extension by keeping the same file name as the individual input file. The TypeScript compiler also preserves the original file path, hence the . js output file will be generated where the input file was in the directory structure.


1 Answers

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.

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

like image 65
iamandrewluca Avatar answered Sep 17 '22 15:09

iamandrewluca