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
标签:vue,vitejs,路径,别名,import,path,config,vite 来源: https://www.cnblogs.com/chen-cheng/p/16184652.html