如何配置react-script以便它不会在'start'上覆盖tsconfig.json [英] How to configure react-script so that it doesn't override tsconfig.json on 'start'
问题描述
我目前正在使用create-react-app
引导我的一个项目.基本上,我试图通过将它们添加到由create-react-app生成的默认tsconfig.json中来在tsconfig.json中设置路径:
I'm currently using create-react-app
to bootstrap one of my projects. Basically, I'm trying to set up paths in tsconfig.json by adding these to the default tsconfig.json generated by create-react-app:
"baseUrl": "./src",
"paths": {
"interfaces/*": [
"common/interfaces/*",
],
"components/*": [
"common/components/*",
],
},
但是,每次我运行基本上运行react-scripts start
的yarn start
时,它都会删除我的更改并再次生成默认配置.
However, every time I run yarn start
which basically runs react-scripts start
, it deletes my changes and generates the default configurations again.
如何告诉create-react-app使用我的自定义配置?
How can I tell create-react-app to use my custom configs?
推荐答案
我能够通过使用将配置选项放入脚本,以便将脚本像要删除的文件放在单独的文件(例如,paths.json)中,并通过extends指令从tsconfig.json中引用它.
Put the configuration options react scripts likes to remove in a separate file (e.g. paths.json) and reference it from tsconfig.json via the extends directive.
paths.json:
paths.json:
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"interfaces/*": [ "common/interfaces/*"],
"components/*": [ "common/components/*"],
}
}
}
tsconfig.json
tsconfig.json
{
"extends": "./paths.json"
...rest of tsconfig.json
}
这篇关于如何配置react-script以便它不会在'start'上覆盖tsconfig.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!