当前位置: 首页 > news >正文

react typescript @别名的使用

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、重启收工 

http://www.dtcms.com/a/3743.html

相关文章:

  • Django框架的推导
  • AI 绘画 | Stable Diffusion 高清修复、细节优化
  • ArcGIS属性表导出时中文为乱码的解决办法
  • Microsoft Dynamics 365 CE 扩展定制 - 7. 安全
  • 远程运维用什么软件?可以保障更安全?
  • 如何选择SVM中最佳的【核函数】
  • ffmpeg的使用
  • 【Web】在前端中,HTML<meta>标签
  • Chrome 插件开发 V3版本 跨域处理
  • 案例研究|腾讯音乐娱乐集团与JumpServer共探安全运维审计解决方案
  • 【离散数学】图论
  • IDEA 函数下边出现红色的波浪线,提示报错
  • 中间件redis的使用
  • nginx upstream健康检测
  • Hello Vue!
  • sqli 靶场 Level23-Level30 wp
  • xshell是什么软件,1000字让你完全了解xshell
  • flink1.15.2 报错 processElement_split
  • Docker学习——④
  • yuv420并转为bgr
  • 【编程语言发展史】Unity开发语言的历史发展
  • ST 任意内核 移植freertos系统
  • 项目实战:中央控制器实现(2)-优化Controller,将共性动作抽取到中央控制器
  • Redis系列-Redis集群模式【8】
  • Qt 4.8.6 的下载与安装
  • VS2010配置gdal1.10.0 gdal1.10.1编译
  • 【原创】java+swing+mysql爱心捐赠管理系统设计与实现
  • mysql---存储引擎
  • 2、音视频基础
  • 配置OSPF特殊区域