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/*"]
}
},
...
}
本文来自博客园,作者:光影星宸,转载请注明原文链接:https://www.cnblogs.com/gyxc/p/17306064.html