My team is maintaining multiple packages and we are trying to create a shared tsconfig.json
with common configuration for all of them. It contains our preferences about compile target, JSX, output directory and included files, for example:
{
"compilerOptions": {
"module": "esnext",
"target": "es5",
"lib": ["es5", "dom"],
"jsx": "react",
"outDir": "build/dist"
},
"include": ["./src/**/*.ts", "./src/**/*.tsx"]
}
We publish this file as a shared npm-module, like my-build-config
and then use extends
in every project:
{
"extends": "./node_modules/my-build-config/tsconfig.json"
}
The issue here is that all paths in the shared config are relative to the file location. E.g. it will try to include ".ts" files not from the current project, but inside my-build-config
. For example, instead of ./src/index.ts
it looks for ./node_modules/my-build-config/src/index.ts
.
Is there a way to share file locations, so they will not be repeated in 10+ packages? Maybe something similar what Jest does with rootDir
property.
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.
TypeScript includes a default set of type definitions for built-in JS APIs (like Math ), as well as type definitions for things found in browser environments (like document ).
ts-node supports a variety of options which can be specified via tsconfig.
If you know my-build-config
will always be installed at node_modules/my-build-config
relative to each project without symlinks, you could just prepend ../../
to each affected path.
Alternatively, use a different tool to copy your tsconfig.json
into all the projects, such as Braid (disclosure: I'm a Braid contributor).
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