First create a project with vite, and then configure it in the vite.conflg.js file
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
//引入path模块
import path from "path";
// console.log(path)
// https://vitejs.dev/config/
//创建一个文件读取方法
function resolve(url){
return path.resolve(__dirname,url)
}
export default defineConfig({
//配置@别名
resolve:{
alias:{
"@":resolve("./src"),
"@netWork":resolve("./src/network"),
"@utils":resolve("./src/utils"),
}
},
plugins: [vue()],
})
1. Import path
2, Create a file reading method, function
3. Configure in export default
Note: The js version supports the global variable path of node.js. But the TS version does not support it, you need to install it yourself
Install @types/node to let him support node