Vue3+TS配置路径别名@

1. vite.config.ts

import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': resolve(__dirname, './src')
    }
  }
})

注意:如果import { resolve } from 'path'报错,先执行npm i @types/node -D依赖

2. tsconfig.ts

{
  "compilerOptions": {
    ...
    "baseUrl": "./",
    "paths": {
      "@/*": ["src/*"]
    }
  },
  ...
}
posted @ 2023-04-11 14:11  光影星宸  阅读(396)  评论(0编辑  收藏  举报