别名的使用"/>
react typescript @别名的使用
1、config/webpack.config.js中找到alias,添加'@': path.resolve('src') ,如下:
alias: {// Support React Native Web// /"react-native": "react-native-web",// Allows for better profiling with ReactDevTools...(isEnvProductionProfile && {"react-dom$": "react-dom/profiling","scheduler/tracing": "scheduler/tracing-profiling",}),...(modules.webpackAliases || {}),"@": path.resolve("src")
},
2、tsconfg.json中配置,新增"paths":{"@/*":["./src/*"]}
{"compilerOptions": {"target": "es5","lib": ["dom","dom.iterable","esnext"],"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","paths": {"@/*": ["./src/*"]}},"include": ["src"]
}
3、重启收工
更多推荐
react typescript @别名的使用
发布评论