You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.8 KiB
TypeScript

/*
* @Author: donghao donghao@supervision.ltd
* @Date: 2025-03-06 11:27:03
* @LastEditors: donghao donghao@supervision.ltd
* @LastEditTime: 2025-03-12 19:38:36
* @FilePath: \vite-ai\data-dashboard\vite.config.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { defineConfig, loadEnv } from 'vite'
import { resolve } from "path";
import vue from '@vitejs/plugin-vue'
import { viteMockServe } from 'vite-plugin-mock'
import AutoImport from "unplugin-auto-import/vite";
/** 路径查找 */
const pathResolve = (dir: string): string => {
return resolve(__dirname, ".", dir);
};
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
return {
resolve: {
alias: [
{ find: /^@\//, replacement: resolve(__dirname, "src") + "/" },
{ find: /^~/, replacement: "" },
{ find: /^@build\//, replacement: pathResolve("build") }
]
},
plugins: [
vue(),
viteMockServe({
mockPath: 'mock', // 模拟数据文件存放的目录
localEnabled: env.VITE_MOCK_ENABLED === 'true',
rodEnabled: false, // 生产环境是否开启 mock 功能
}),
AutoImport({
imports: ["vue"],
eslintrc: {
enabled: true
}
})
],
// 开发服务器配置
server: {
port: 5050,
proxy: {
'/api': {
target: env.VITE_APP_BASE_API,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
},
// 生产构建配置
build: {
outDir: mode === 'staging' ? 'dist-staging' : 'dist',
sourcemap: mode !== 'production' // 生产环境关闭 sourcemap
},
define: {
'process.env': env
}
}
})