vite 配置路径别名
首先需要在tsconfig.json
"baseUrl": "./", "paths": { "@/*": ["src/*"], "#/*": ["types/*"], }
然后在vite.config.ts配置 https://cn.vitejs.dev/config/#resolve-alias
import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import * as path from 'path' // https://vitejs.dev/config/ export default defineConfig({ plugins: [vue()], resolve: { alias: { "@": path.join(__dirname, "src"), "#": path.join(__dirname, "types"), } } })
直接引入path会报错
得先安装依赖
npm install @type/node -D yarn add @type/node -D