如何配置 react-script 使其不会在“开始”时覆盖 tsconfig.json

新手上路,请多包涵

我目前正在使用 create-react-app 来引导我的一个项目。基本上,我试图通过将这些添加到由 create-react-app 生成的默认 tsconfig.json 中来设置 tsconfig.json 中的路径:

 "baseUrl": "./src",
"paths": {
  "interfaces/*": [
    "common/interfaces/*",
  ],
  "components/*": [
    "common/components/*",
  ],
},

但是,每次我运行 yarn start 基本上运行 react-scripts start 时,它都会删除我的更改并再次生成默认配置。

如何告诉 create-react-app 使用我的自定义配置?

原文由 CodeIntern 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 944
1 个回答

我能够通过使用来自 这个问题 的建议来做到这一点。

将 React 脚本喜欢删除的配置选项放在一个单独的文件中(例如 paths.json),并通过 extends 指令从 tsconfig.json 中引用它。

路径.json:

 {
  "compilerOptions": {
  "baseUrl": "./src",
  "paths": {
    "interfaces/*": [ "common/interfaces/*"],
    "components/*": [ "common/components/*"],
    }
  }
}

tsconfig.json文件

{
  "extends": "./paths.json"
   ...rest of tsconfig.json
}

原文由 Glenn 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进