22 lines
586 B
TypeScript
22 lines
586 B
TypeScript
import { defineConfig, loadEnv } from 'vite';
|
|
import react from '@vitejs/plugin-react-swc';
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig(({ mode }) => {
|
|
// 加载环境变量
|
|
const env = loadEnv(mode, process.cwd(), '');
|
|
|
|
return {
|
|
plugins: [react()],
|
|
server: {
|
|
port: parseInt(env.VITE_PORT || '5173', 10),
|
|
host: true, // 允许外部访问
|
|
open: true, // 自动打开浏览器
|
|
},
|
|
preview: {
|
|
port: parseInt(env.VITE_PORT || '4173', 10),
|
|
host: true,
|
|
},
|
|
};
|
|
});
|