You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
// vite.config.js
import { defineConfig } from 'vite'import vue from '@vitejs/plugin-vue'import { resolve } from 'path'import { readdirSync, writeFileSync } from 'fs'
function createHTMLFiles() { const viewsDir = './src/views/admin' const vueFiles = readdirSync(viewsDir).filter(file => file.endsWith('.vue')) const input = {}
vueFiles.forEach(file => { const pageName = file.replace('.vue', '') const htmlFileName = `${pageName}.html`
// 在项目根目录创建 HTML 文件
const htmlContent = `<!DOCTYPE html>
<html lang="zh-CN"><head> <meta charset="UTF-8" /> <link rel="icon" type="image/svg+xml" href="./vite.svg" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>${pageName}</title></head><body> <div id="app"></div> <script type="module" src="./src/main.js"></script></body></html>`
writeFileSync(htmlFileName, htmlContent) input[pageName] = resolve(__dirname, htmlFileName) })
return input}
export default defineConfig({ plugins: [vue()], // 设置基础路径为相对路径
base: './', build: { rollupOptions: { input: { // 添加 index.html 作为默认页面
index: resolve(__dirname, 'index.html'), ...createHTMLFiles() } }, // 资源文件放在根目录(空字符串)
assetsDir: '', // 清理输出目录
emptyOutDir: true }, preview: { port: 4173, host: true, // 设置默认打开的页面
open: '/landingManagement.html' }})
|