56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { defineConfig, ConfigEnv, loadEnv } from 'vite'
|
||
// import {
|
||
// getRootPath,
|
||
// getSrcPath,
|
||
// setupVitePlugins,
|
||
// } from "./build";
|
||
import vue from '@vitejs/plugin-vue'
|
||
import path from 'path'
|
||
import { fileURLToPath, URL } from 'url'
|
||
// https://vitejs.dev/config/
|
||
export default defineConfig((configEnv: ConfigEnv) => {
|
||
const viteEnv = loadEnv(
|
||
configEnv.mode,
|
||
process.cwd()
|
||
) as unknown as ImportMetaEnv;
|
||
return {
|
||
plugins: [vue()],
|
||
// plugins: setupVitePlugins(viteEnv),
|
||
// 1. 路径别名(对应你之前的 @ -> src)
|
||
resolve: {
|
||
alias: {
|
||
'@/utils': path.resolve(__dirname, './utils'),
|
||
"~": path.resolve(__dirname, './src'),
|
||
'@': path.resolve(__dirname, './src'),
|
||
'@/typings': path.resolve(__dirname, './src/typings'),
|
||
components: path.resolve(__dirname, "components"),
|
||
|
||
},
|
||
extensions: ['.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
|
||
},
|
||
|
||
// 2. SCSS 兼容 & 全局变量(和 Vue CLI 写法不同)
|
||
css: {
|
||
preprocessorOptions: {
|
||
scss: {
|
||
// 如果你有全局 scss 变量文件,在这里引入
|
||
// additionalData: `@use "@/assets/styles/variables.scss" as *;`
|
||
}
|
||
}
|
||
},
|
||
|
||
// 3. 开发服务配置(端口、跨域、自动打开浏览器等)
|
||
server: {
|
||
host: "0.0.0.0",
|
||
port: viteEnv.VITE_CLI_PORT,
|
||
proxy: {
|
||
[viteEnv.VITE_BASE_API]: {
|
||
target: viteEnv.VITE_BASE_PATH,
|
||
changeOrigin: true,
|
||
rewrite: (path: string) =>
|
||
path.replace(new RegExp("^" + viteEnv.VITE_BASE_API), ""),
|
||
},
|
||
},
|
||
}
|
||
}
|
||
}) |