当前位置:首页 > 编程笔记 > 正文
已解决

react typescript @别名的使用

来自网友在路上 183883提问 提问时间:2023-11-07 06:15:27阅读次数: 83

最佳答案 问答题库838位专家为你答疑解惑

1、config/webpack.config.js中找到alias,添加"@": path.resolve(__dirname,'../src'),如下:

alias: {// Support React Native Web// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-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(__dirname,'../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、重启收工 

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"react typescript @别名的使用":http://eshow365.cn/6-34294-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!