I am working on Nx monorepo. We have 5 library and are using imports like this '../../components/Button'
in library. but instead of this, we want to use absolute imports.
For example:
there are 2 files in same library: libs/shop/containers/Basket.js
, libs/shop/components/Button.js
in Basket.js
I want to import like this 'components/Basket'
instead of '../../components/Button'
.
I added baseUrl and paths config in library tsconfig but it's not working.
library tsconfig
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx",
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"baseUrl": ".",
"paths": {
"*": ["./src/lib/*"]
}
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
"@components/shop/*": ["libs/shop/src/lib/*"],
) to thetsconfig.base.json
paths
object. – Hurlow