|
|
|
@ -2,39 +2,34 @@ |
|
|
|
import { defineConfig } from 'vite' |
|
|
|
import vue from '@vitejs/plugin-vue' |
|
|
|
import { resolve } from 'path' |
|
|
|
import { readdirSync, existsSync, mkdirSync, writeFileSync } from 'fs' |
|
|
|
import { readdirSync, writeFileSync } from 'fs' |
|
|
|
|
|
|
|
function setupMultiPage() { |
|
|
|
const pagesDir = './pages' |
|
|
|
function createHTMLFiles() { |
|
|
|
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 htmlFileName = `${pageName}.html` |
|
|
|
|
|
|
|
// 在项目根目录创建 HTML 文件
|
|
|
|
const htmlContent = `<!DOCTYPE html>
|
|
|
|
<html lang="en"> |
|
|
|
<html lang="zh-CN"> |
|
|
|
<head> |
|
|
|
<meta charset="UTF-8" /> |
|
|
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> |
|
|
|
<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> |
|
|
|
<script type="module" src="./src/main.js"></script> |
|
|
|
</body> |
|
|
|
</html>` |
|
|
|
|
|
|
|
writeFileSync(htmlPath, htmlContent) |
|
|
|
input[pageName] = resolve(__dirname, htmlPath) |
|
|
|
writeFileSync(htmlFileName, htmlContent) |
|
|
|
input[pageName] = resolve(__dirname, htmlFileName) |
|
|
|
}) |
|
|
|
|
|
|
|
return input |
|
|
|
@ -42,19 +37,25 @@ function setupMultiPage() { |
|
|
|
|
|
|
|
export default defineConfig({ |
|
|
|
plugins: [vue()], |
|
|
|
// 设置基础路径为相对路径
|
|
|
|
base: './', |
|
|
|
build: { |
|
|
|
rollupOptions: { |
|
|
|
input: { |
|
|
|
// 添加 index.html 作为默认页面
|
|
|
|
index: resolve(__dirname, 'index.html'), |
|
|
|
...setupMultiPage() |
|
|
|
...createHTMLFiles() |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
// 资源文件放在根目录(空字符串)
|
|
|
|
assetsDir: '', |
|
|
|
// 清理输出目录
|
|
|
|
emptyOutDir: true |
|
|
|
}, |
|
|
|
preview: { |
|
|
|
port: 4173, |
|
|
|
host: true, |
|
|
|
// 设置默认打开的页面
|
|
|
|
open: '/pages/landingList.html' |
|
|
|
open: '/landingList.html' |
|
|
|
} |
|
|
|
}) |