在根目录vite.config.js/vue.config.js下配置
import { defineConfig } from 'vite'
import path from 'path'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
const pathResolve = (pathStr) => {
return path.resolve(__dirname, pathStr);
};
export default defineConfig({
plugins: [vue()],
resolve: {
// 设置路径别名
alias: {
"@": pathResolve("./src")
},
},
})
核心代码为
import path from 'path'
const pathResolve = (pathStr) => {
return path.resolve(__dirname, pathStr);
};
resolve: {
// 设置路径别名
alias: {
"@": pathResolve("./src"),
},
},