我使用 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"
},