// vite.config.js import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import { resolve } from 'path' import { readdirSync, existsSync, mkdirSync, writeFileSync } from 'fs' function setupMultiPage() { const pagesDir = './pages' const viewsDir = './src/views/admin' if (!existsSync(pagesDir)) { mkdirSync(pagesDir) } const vueFiles = readdirSync(viewsDir).filter(file => file.endsWith('.vue')) const input = {} vueFiles.forEach(file => { const pageName = file.replace('.vue', '') const htmlPath = `${pagesDir}/${pageName}.html` const htmlContent = ` ${pageName}
` writeFileSync(htmlPath, htmlContent) input[pageName] = resolve(__dirname, htmlPath) }) return input } export default defineConfig({ plugins: [vue()], build: { rollupOptions: { input: { // 添加 index.html 作为默认页面 index: resolve(__dirname, 'index.html'), ...setupMultiPage() } } }, preview: { port: 4173, host: true, // 设置默认打开的页面 open: '/pages/landingList.html' } })