安装path

npm install --save-dev @types/node

配置

// vite.config.ts 
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"

import path from "path" // 需安装此模块

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      // 这里就是需要配置resolve里的别名
      "@": path.join(__dirname, "./src") // path记得引入
    }
  }
})

// tsconfig.json
"compilerOptions": {
  "baseUrl": ".",
  "paths": {
    "@/*":["./src/*"]
  }
}
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐