微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为打字稿添加路径别名

如何解决为打字稿添加路径别名

我使用 create-react-app 作为脚手架,使用 tsconfig-paths 作为 tsconfig 的扩展,因为 create-react-app 在运行时删除了我的路径。我已经使用这个设置一年了,我没有问题,但最近当我从头开始创建一个项目时,它不再工作了

tsconfig.json:

{
  "extends": "./tsconfig-paths.json","compilerOptions": {
    "target": "es5","lib": [
      "dom","dom.iterable","esnext"
    ],"types": [
      "cypress"
    ],"allowJs": true,"skipLibCheck": true,"esModuleInterop": true,"allowSyntheticDefaultImports": true,"strict": true,"forceConsistentCasingInFileNames": true,"noFallthroughCasesInSwitch": true,"module": "esnext","moduleResolution": "node","resolveJsonModule": true,"isolatedModules": true,"noEmit": true,"jsx": "react-jsx","downlevelIteration": true
  },"include": [
    "src"
  ]
}

tsconfig-paths.json:

{
    "compilerOptions": {
        "baseUrl": "./src","paths": {
            "components/*": ["./components/*"],"constants/*": ["./constants/*"],"pages/*": ["./pages/*"],"assets/*": ["./assets/*"],"actions/*": ["./actions/*"],"reducers/*": ["./reducers/*"],"layouts/*": ["./layouts/*"],"routes/*": ["./routes/*"],"utils/*": ["./utils/*"],"theme/*": ["./theme/*"],"api": ["./api"],"hooks": ["./hooks"],"formdocuments/*": ["./formdocuments/*"],"enums/*": ["./enums/*"]
        }
    }
}

脚本:

"scripts": {
    "start": "craco start","build": "craco build","test": "craco test","eject": "react-scripts eject"
},

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。