| 123456789101112131415161718192021222324252627282930313233 |
- import { defineConfig } from 'vite'
- import react from '@vitejs/plugin-react'
- import { createRequire } from 'module'
- import { fileURLToPath } from 'url'
- import { dirname, join } from 'path'
- // 使用 createRequire 来加载 CommonJS 格式的配置文件
- const __filename = fileURLToPath(import.meta.url)
- const __dirname = dirname(__filename)
- const require = createRequire(import.meta.url)
- const configPath = join(__dirname, 'configs', 'config.js')
- const config = require(configPath)
- // 从配置文件读取 Vite 端口,默认 5173
- const vitePort = config.vite?.port || 5173
- const viteHost = config.vite?.host || 'localhost'
- export default defineConfig({
- plugins: [react()],
- server: {
- host: viteHost,
- port: vitePort,
- strictPort: false, // 如果端口被占用,自动尝试下一个端口
- open: false // 不自动打开浏览器,只用于 Electron 桌面应用
- },
- css: {
- preprocessorOptions: {
- scss: {
- api: 'modern-compiler', // 使用现代 API,消除弃用警告
- },
- },
- },
- })
|