import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import { fileURLToPath, URL } from 'node:url' import fs from 'fs' export default defineConfig({ base: process.env.NODE_ENV === 'production' ? 'https://cdn.kdesign.top/' : '/', // base: '/', plugins: [ vue(), // 添加自定义中间件来处理根路径 { name: 'configure-server', configureServer(server) { server.middlewares.use((req, res, next) => { if (req.url === '/' || req.url === '/index.html') { // 读取start.html的内容并发送 const startHtml = fs.readFileSync( fileURLToPath(new URL('./start.html', import.meta.url)), 'utf-8' ); res.statusCode = 200; res.setHeader('Content-Type', 'text/html'); res.end(startHtml); return; } next(); }); } } ], server: { host: '0.0.0.0', port: 3992 }, build: { rollupOptions: { input: { main: fileURLToPath(new URL('./index.html', import.meta.url)), start: fileURLToPath(new URL('./start.html', import.meta.url)) }, output: { chunkFileNames: 'assets/[name]-[hash].js', entryFileNames: 'assets/[name]-[hash].js', assetFileNames: 'assets/[name]-[hash].[ext]' } } }, resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } }, pwa: { iconPaths: { favicon32: 'favicon.ico', favicon16: 'favicon.ico', appleTouchIcon: 'favicon.ico', maskIcon: 'favicon.ico', msTileImage: 'favicon.ico' } } })