vite js 配置@路径
npm install @types/node --save-dev
vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
//需要引入
import path from 'path'// https://vitejs.dev/config/
export default defineConfig({plugins: [vue()],resolve: {alias: {'@': path.resolve(__dirname, './src')}}
})
看看有没有jsconfig.json文件和src文件同级,没有就新建一个,然后把代码粘贴进入,配置就完成了
{"compilerOptions": {"experimentalDecorators": true, "baseUrl": "./","paths": {"@/*": ["src/*"],"components/*": ["src/components/*"],"assets/*": ["src/assets/*"],"views/*": ["src/views/*"],"common/*": ["src/common/*"],}},"exclude": ["node_modules", "dist"]
}