How can I specify multiple source folders in my tsconfig.json? How can I specify multiple source folders in my tsconfig.json? typescript typescript

How can I specify multiple source folders in my tsconfig.json?


Now other than rootDir, you can use rootDirs

"rootDirs": ["./scripts", "./src"],

for multiple folders.

Here is the API doc: https://www.typescriptlang.org/docs/handbook/module-resolution.html#virtual-directories-with-rootdirs


I think you are looking for path mapping. With the paths compiler option, you can specify not only a mapping to a single location but to several. This is the example from the documentation:

"compilerOptions": {    "baseUrl": ".",    "paths": {      "*": [        "*",        "generated/*"      ]    }}

If the compiler does not find a module in the expected location, it repeats module resolution in the "generated" subfolder. The baseUrl setting seems redundant but it is mandatory.


Or is it "better" to place the tests inline in the src/ folder and have a separate webpack.config.js file for them?

That is what I do. Do not use the TypeScript compiler as a module bundler (Especially if you are not using modules https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md). Just let it do the compile and bundle for browser using webpack and use as it is (if using module commonjs) for backend (nodejs).