I've got a (desired) structure like this:
- tsconfig.json - src - app.ts - tests - appTest.ts - appTest.js - dist - app.js
If there was no tests
folder, a tsconfig.json like this would work fine:
{ "compilerOptions": { "outDir":"dist" }, "include" :[ "src/**/*.ts" ] }
However, if I add tests/**/*.ts
to the include
element, it also compiles my test files into dist
and changes its folder structure (understandably, but undesirably).
Can I tell TypeScript compiler to include test files in the project to support things like refactoring but omit them from output to dist
? Specifically, I'd like the .js
to be compiled in the tests
directory as suggested in the structure above.
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.
The tsconfig. json is generally put in the root folder of the project.
ts-node automatically finds and loads tsconfig. json . Most ts-node options can be specified in a "ts-node" object using their programmatic, camelCase names. We recommend this because it works even when you cannot pass CLI flags, such as node --require ts-node/register and when using shebangs.
You may use rootDirs
option within tsconfig.json
such as:
{ "compilerOptions": { "rootDirs": [ "src", "tests" ] } }
This can be looked up at Typescript documents, on this page (search for Virtual Directories with rootDirs subtitle): Module Resolution
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