当前位置: 首页 > 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、重启收工 

相关文章:

  • 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
  • 媒体报道一民企投资400万运营出租车4年未获批,广西隆林县回应
  • 国际博物馆日|航海博物馆:穿梭于海洋神话与造船工艺间
  • 蒲慕明院士:好的科普应以“质疑、讨论公众关切的科学问题”为切入点
  • 国际博物馆日|在辽宁省博物馆遇见敦煌
  • 《五行令》《攻守占》,2个月后国博见
  • 浙江省台州市政协原副主席林虹被“双开”