在tsconfig.json中添加 "baseUrl": "src" 就可以在页面导入其他组件的时候不用写相对路径,只需要写src下的的哪个目录哪个文件就可以, 如 src下有page目录和app.tsx文件,page目录下有一个login.tsx文件,在app.tsx导入这个文件只需要写 import Login from 'page/login'即可
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"baseUrl": "src" // 添加此配置
},
"include": [
"src"
]
}