`Vue3 - Vite` 项目别名 src 到 @ 不起作用 [英] `Vue3 - Vite` project alias src to @ not working
本文介绍了`Vue3 - Vite` 项目别名 src 到 @ 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经用 vue3 - vite
导入了一个像
I have installed the project with vue3 - vite
importing a component like
从'../../../../components/Component.vue'导入组件
我只想给 src 文件夹取别名,然后做
i just want to alias the src folder and do
从'@/components/Component.vue'导入组件
这是我的vite.config.js
this is my vite.config.js
import vue from '@vitejs/plugin-vue'
/**
* https://vitejs.dev/config/
* @type {import('vite').UserConfig}
*/
export default {
plugins: [
vue({
template: {
compilerOptions: {
// ...
}
}
})
]
}
我错过了什么吗?我还应该做什么?
am i missing something? what else should i do?
推荐答案
这对我有用......
Here's what worked for me ...
import vue from '@vitejs/plugin-vue'
const path = require('path')
export default {
alias: {
'/@': path.resolve(__dirname, './src')
},
plugins: [vue()]
}
这篇关于`Vue3 - Vite` 项目别名 src 到 @ 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文