vite为vue3配置@路径,vite路径配置

vite的ts环境里面没有配置@,我们需要自己配置

再vite.config.ts这个文件里面

配置alias

  resolve: {
      alias: {
        '@': path.resolve(__dirname, './src'),
        '*': path.resolve('')
        },
    },
import path from 'path'

然后再再tsconfig.json文件配置 baseUrl,paths 参数

{
  "compilerOptions": {
    "target": "ESNext",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "strict": true,
    "jsx": "preserve",
    "sourceMap": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "lib": ["ESNext", "DOM"],
    "skipLibCheck": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    }
  },
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
  "references": [{ "path": "./tsconfig.node.json" }]
}

vite为vue3配置@路径,vite路径配置_第1张图片

 然后重新运行就行

你可能感兴趣的:(vue,vue.js,前端,javascript)