我如何在 NX monorepo 中的同一库中使用绝对路径

efd*_*ali 6 nomachine-nx monorepo next.js nrwl nrwl-nx

我正在开发 Nx monorepo。我们有 5 个库,并且正在库中使用这样的导入'../../components/Button'。但我们不想使用绝对导入。

例如:

同一个库中有 2 个文件:libs/shop/containers/Basket.js,libs/shop/components/Button.js

Basket.js我想像这样导入'components/Basket'而不是'../../components/Button'.

我在库 tsconfig 中添加了 baseUrl 和 paths 配置,但它不起作用。

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"
    }
  ]
}

Run Code Online (Sandbox Code Playgroud)