refactor(vite.config.ts): Vite别名使用方式一

This commit is contained in:
郝先瑞
2022-01-01 15:57:05 +08:00
parent 93bbc8e98f
commit d727617b0e

View File

@@ -22,7 +22,7 @@ export default ({command, mode}: ConfigEnv): UserConfig => {
}) })
], ],
// 本地反向代理解决跨域 // 本地反向代理解决浏览器跨域限制
server: { server: {
host: 'localhost', host: 'localhost',
port: Number(env.VITE_APP_PORT), port: Number(env.VITE_APP_PORT),
@@ -38,44 +38,44 @@ export default ({command, mode}: ConfigEnv): UserConfig => {
resolve: { resolve: {
// Vite2设置别名路径方式一 // Vite2设置别名路径方式一
// alias:{ alias: {
// "/@":path.resolve("./src"), // 相对路径别名配置,@表示src "@": path.resolve("./src"), // 相对路径别名配置,@表示src
// }, },
// Vite2设置别名路径方式二 // Vite2设置别名路径方式二
alias: [ // alias: [
{ // {
find: "@", // find: "@",
replacement: path.resolve("./src") // replacement: path.resolve("./src")
}, // },
{ // {
find: "@image", // find: "@image",
replacement: path.resolve("./src/assets/images") // replacement: path.resolve("./src/assets/images")
}, // },
{ // {
find: "@router", // find: "@/router",
replacement: path.resolve("./src/router") // replacement: path.resolve("./src/router")
}, // },
{ // {
find: "@store", // find: "@/store",
replacement: path.resolve("./src/store") // replacement: path.resolve("./src/store")
}, // },
{ // {
find: "@api", // find: "@/api",
replacement: path.resolve("./src/api") // replacement: path.resolve("./src/api")
}, // },
{ // {
find: "@utils", // find: "@/utils",
replacement: path.resolve("./src/utils") // replacement: path.resolve("./src/utils")
}, // },
{ // {
find: "@views", // find: "@/views",
replacement: path.resolve("./src/views") // replacement: path.resolve("./src/views")
}, // },
{ // {
find: "@styles", // find: "@/styles",
replacement: path.resolve("./src/styles") // replacement: path.resolve("./src/styles")
}, // },
] // ]
} }
} }