欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue项目使用ts识别别名@

程序员文章站 2022-05-17 20:33:42
...

在tsconfig.json文件中加入

"paths": {
 	  "baseUrl": ".",
      "@/*": ["src/*"]
    }

完整配置

//vite.config.ts
resolve: {
        alias: {
            '@': resolve('src'),
            '*': resolve(''),
        },
    },
//tsconfig.json
{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "strict": true,
    "jsx": "preserve",
    "sourceMap": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "lib": ["esnext", "dom"],
    "types": ["vite/client"],
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    }
  },
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
}

相关标签: vite