I'm trying to include some files in my tsconfig.json, but it's including files I don't want to be included. From a repo (with uncompiled source) I'm trying to include files that end in .ts
, except for ones that end in .spec.ts
.
The following includes the files I want, but doesn't successfully exclude the files I don't want.
"include": ["node_modules/dashboard/**/*.ts"],
"exclude": ["node_modules/dashboard/**/*.spec.ts"],
(Then) new to Unix glob patterns/strings, I need ones to match and exclude the files correctly, and then how to add them to the config.
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.
To exclude test files from compilation, but still have them type checked, create a second configuration file, e.g. tsconfig. build. json , which uses the excludes array to exclude your test files from compilation when running the tsc command.
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.
json file is a file of JSON format which allows us to point the root level files and different compiler options to setup that require to compile a TypeScript based projects. The existence of this file in a project specifies that the given directory is the TypeScript project folder root.
The TypeScript handbook has a good write up on tsconfig file.
The example in the handbook is:
"exclude": [
"node_modules",
"**/*.spec.ts"
]
Note the use of **
for any folder, and *
(a single asterisk) for the file name wildcard.
You don't usually need to be any more specific, as I imagine you would want to exclude "all spec files", not just files in a particular sub-directory.
There are cases when this won't work.
tsc app.ts
(or pass other arguments) - your tsconfig is ignored when you do thisYou can use
"exclude": ["node_modules/dashboard/**/*.spec.ts"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With