使用vite构建的react-ts,路径别名配置提示无效

1.vite-config.ts

TypeScript 复制代码
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import * as  path from "path"
// https://vitejs.dev/config/
export default defineConfig({
  base: '/',
  plugins: [react()],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    }
  },


})

2.注意是在tsconfig.app.json中添加,不是tsconfig.json

TypeScript 复制代码
{
  "compilerOptions": {
    "composite": true,
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
    "target": "ES2020",
    "useDefineForClassFields": true,
    "lib": [
      "ES2020",
      "DOM",
      "DOM.Iterable"
    ],
    "module": "ESNext",
    "skipLibCheck": true,
    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "moduleDetection": "force",
    "noEmit": true,
    "jsx": "react-jsx",
    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true,
//------------------添加------------------
    "baseUrl": "./",
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
//------------------
  },
  "include": [
    "src"
  ]
}
相关推荐
whuhewei18 分钟前
为什么客户端不存在跨域问题
前端·安全
妮妮喔妮32 分钟前
supabase的webhook报错
开发语言·前端·javascript
qq_12084093711 小时前
Three.js 大场景分块加载实战:从全量渲染到可视集调度
开发语言·javascript·数码相机
yivifu1 小时前
手搓HTML双行夹批效果
前端·html·html双行夹注
奔跑的卡卡2 小时前
Web开发与AI融合-第一篇:Web开发与AI融合的时代序幕
前端·人工智能
IT_陈寒2 小时前
Redis批量删除的大坑,差点让我加班到天亮
前端·人工智能·后端
帆张芳显2 小时前
智表ZCELL产品V3.6 版发布,新增系统预置右键菜单操作、页签栏操作等功能
前端·canva可画·excel插件
漂流瓶jz2 小时前
运行时vs编译时:CSS in JS四种主流方案介绍和对比
前端·javascript·css
Asmewill2 小时前
uv包管理命令
前端
发现一只大呆瓜2 小时前
深入浅出 Tree Shaking:Rollup 是如何“摇”掉死代码的?
前端·性能优化·vite