一、找到项目下的 tsconfig.json
二、添加如图所示baseUrl和paths
{"compilerOptions":{"target":"ESNext","useDefineForClassFields":true,"module":"ESNext","moduleResolution":"Node","strict":true,"jsx":"preserve","resolveJsonModule":true,"isolatedModules":true,"esModuleInterop":true,"lib":["ESNext","DOM"],"skipLibCheck":true,"noEmit":true,//解析非相对模块的基础地址,默认是当前目录"baseUrl":"./",//路径映射,相对于baseUrl"paths":{"@/*":["./src/*"]},},"include":["src/**/*.ts","src/**/*.d.ts","src/**/*.tsx","src/**/*.vue"],"references":[{"path":"./tsconfig.node.json"}]}
三、找到vite.config.ts
import{ defineConfig } from 'vite'importvue from '@vitejs/plugin-vue'
importpath from 'path'//引入path模块// https://vitejs.dev/config/
export defaultdefineConfig({
plugins:[vue()],
resolve:{
alias:{
vue:"vue/dist/vue.esm-bundler.js",'@': path.resolve(__dirname,'src'),//配置@路径}}})
本文转载自: https://blog.csdn.net/qweasdassd/article/details/129421402
版权归原作者 一步步迈入网络 所有, 如有侵权,请联系我们删除。
版权归原作者 一步步迈入网络 所有, 如有侵权,请联系我们删除。