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.

60 lines
1.5 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. // vite.config.js
  2. import { defineConfig } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import { resolve } from 'path'
  5. import { readdirSync, writeFileSync } from 'fs'
  6. function createHTMLFiles() {
  7. const viewsDir = './src/views/admin'
  8. const vueFiles = readdirSync(viewsDir).filter(file => file.endsWith('.vue'))
  9. const input = {}
  10. vueFiles.forEach(file => {
  11. const pageName = file.replace('.vue', '')
  12. const htmlFileName = `${pageName}.html`
  13. // 在项目根目录创建 HTML 文件
  14. const htmlContent = `<!DOCTYPE html>
  15. <html lang="zh-CN">
  16. <head>
  17. <meta charset="UTF-8" />
  18. <link rel="icon" type="image/svg+xml" href="./vite.svg" />
  19. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  20. <title>${pageName}</title>
  21. </head>
  22. <body>
  23. <div id="app"></div>
  24. <script type="module" src="./src/main.js"></script>
  25. </body>
  26. </html>`
  27. writeFileSync(htmlFileName, htmlContent)
  28. input[pageName] = resolve(__dirname, htmlFileName)
  29. })
  30. return input
  31. }
  32. export default defineConfig({
  33. plugins: [vue()],
  34. // 设置基础路径为相对路径
  35. base: './',
  36. build: {
  37. rollupOptions: {
  38. input: {
  39. // 添加 index.html 作为默认页面
  40. index: resolve(__dirname, 'index.html'),
  41. ...createHTMLFiles()
  42. }
  43. },
  44. // 资源文件放在根目录(空字符串)
  45. assetsDir: '',
  46. // 清理输出目录
  47. emptyOutDir: true
  48. },
  49. preview: {
  50. port: 4173,
  51. host: true,
  52. // 设置默认打开的页面
  53. open: '/landingManagement.html'
  54. }
  55. })