react typescript @别名的使用

编程入门 行业动态 更新时间:2024-10-19 17:22:18

react typescript @<a href=https://www.elefans.com/category/jswz/34/1769025.html style=别名的使用"/>

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 @别名的使用

本文发布于:2023-11-16 10:14:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617879.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:别名   react   typescript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!