I have a project from which I need to build two different products. Say I have
./src/advanced
./src/basic
All code is written in Typescript so I need to compile this with tsc
Because of this, I created 3 tsconfig files
tsconfig-base.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"noImplicitAny": false,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./src",
"lib": ["es2018", "dom", "dom", "dom.iterable", "es6"],
"importHelpers": true,
},
"exclude": ["node_modules", "**/*.spec.ts","dist"]
Now to build the basic
product I have
tsconfig-basic.json
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"noEmitHelpers": true
},
"files": [
"basic/main.ts"
]
}
And I compile as follows
$> tsc -p ./tsconfig-basic.json
Now I have 2 issues
1) The file basic/main.ts
cannot be found, its looking in ./basic/main.ts
while it should have been ./src/basic/main.ts
. Why is baseUrl
not prepended?
2) If (1) is fixed, the compiled files are not written to ./dist
. Why is "outDir": "./dist
from the base file not used here? When I add the outDir
to tsconfig-basic.json it works as expected
Anyway, it looks like that extending here doesn't work, or works differently than I expect. Any suggestion how to improve my setup?
TypeScript's strict mode parameter can be configurated as several individual parameters for each specific case of type checking. So, basically, if you set the parameter strict to true in tsconfig. json it means that all these strict options are set to true.
The presence of a tsconfig. json file in a directory indicates that the directory is the root of a TypeScript project. The tsconfig. json file specifies the root files and the compiler options required to compile the project.
Use the exclude option in your tsconfig. json file to exclude a folder from compilation in TypeScript. The exclude option changes what the include setting finds and defaults to node_modules and bower_components .
There is a trick though. If you create a symlink to the base Tsconfig file from a relevant directory and extend the symlinked version rather than the original, all the paths will be resolved according to your expectations.
1) baseUrl
is only meant to be used with bundlers like webpack. See discussion on TypeScript/10866
2) This is unfortunately by design. See issue TypeScript/29172
Quote Wesley Wigham (Microsoft Employee):
Path-based compiler options (outDir, outFile, rootDir, include, files) are resolved from the config file they're found in)
You will need to repeat the outDir
for every tsconfig.json
file you have.
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