I am having a TypeScript package (using yarn 2 as package manager) with two different source trees:
|- src-bin
\- src
The sources in src-bin
target node, whereas the sources in src
target a browser environment. Hence, I am having two different tsconfig.json
files.
I usually build them with tsc -b . src-bin
, which works quite fine.
However, in "watch-mode", tsc
only compile and watches src
, but not src-bin
.
I was actually able to solve it using project references:
The tsconfig.json
(for src):
{
"extends": "../tsconfig.base.json",
"include": ["src/**/*.ts", "src/**/*.tsx"],
"references": [{ "path": "src-bin" }],
"compilerOptions": {
"types": [],
"rootDir": "src",
"outDir": "build",
"noEmit": false,
"declaration": true,
"composite": true
}
}
The src-bin/tsconfig.json
(for src-bin):
{
"extends": "../../tsconfig.base.json",
"include": ["**/*.ts"],
"compilerOptions": {
"types": ["node"],
"rootDir": ".",
"outDir": "../build/bin",
"noEmit": false,
"declaration": true,
"composite": true
}
}
Running tsc -b --watch
now compiles BOTH source trees.