Browse Source

修改配置文件

milestone-20251021-双11活动后台
zhaoruhui 3 months ago
parent
commit
57c87f41c7
  1. 36
      vite.config.js

36
vite.config.js

@ -2,7 +2,7 @@
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import { resolve } from 'path' import { resolve } from 'path'
import { readdirSync, writeFileSync } from 'fs'
import { readdirSync, existsSync, mkdirSync } from 'fs'
function createHTMLFiles() { function createHTMLFiles() {
const viewsDir = './src/views/admin' const viewsDir = './src/views/admin'
@ -13,23 +13,29 @@ function createHTMLFiles() {
const pageName = file.replace('.vue', '') const pageName = file.replace('.vue', '')
const htmlFileName = `${pageName}.html` const htmlFileName = `${pageName}.html`
// 在项目根目录创建 HTML 文件
// 创建正确的 HTML 内容,使用相对路径
const htmlContent = `<!DOCTYPE html> const htmlContent = `<!DOCTYPE html>
<html lang="zh-CN"> <html lang="zh-CN">
<head> <head>
<meta charset="UTF-8" /> <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" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>${pageName}</title> <title>${pageName}</title>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
<script type="module" src="./src/main.js"></script>
<script type="module" src="/src/main.js"></script>
</body> </body>
</html>` </html>`
writeFileSync(htmlFileName, htmlContent)
input[pageName] = resolve(__dirname, htmlFileName)
// 确保目录存在
if (!existsSync('./src')) {
mkdirSync('./src')
}
// 将 HTML 文件写入 src 目录
writeFileSync(resolve(__dirname, 'src', htmlFileName), htmlContent)
input[pageName] = resolve(__dirname, 'src', htmlFileName)
}) })
return input return input
@ -37,25 +43,27 @@ function createHTMLFiles() {
export default defineConfig({ export default defineConfig({
plugins: [vue()], plugins: [vue()],
// 设置基础路径为相对路径
base: './', base: './',
build: { build: {
rollupOptions: { rollupOptions: {
input: { input: {
// 添加 index.html 作为默认页面
index: resolve(__dirname, 'index.html'),
main: resolve(__dirname, 'index.html'),
...createHTMLFiles() ...createHTMLFiles()
} }
}, },
// 资源文件放在根目录(空字符串)
assetsDir: '', assetsDir: '',
// 清理输出目录
emptyOutDir: true
emptyOutDir: true,
// 添加 chunk 大小警告限制
chunkSizeWarningLimit: 1000
},
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
}, },
preview: { preview: {
port: 4173, port: 4173,
host: true, host: true,
// 设置默认打开的页面
open: '/landingList.html'
open: '/landingManagement.html'
} }
}) })
Loading…
Cancel
Save