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.

59 lines
1.4 KiB

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, existsSync, mkdirSync, writeFileSync } from 'fs'
  6. function setupMultiPage() {
  7. const pagesDir = './pages'
  8. const viewsDir = './src/views/admin'
  9. if (!existsSync(pagesDir)) {
  10. mkdirSync(pagesDir)
  11. }
  12. const vueFiles = readdirSync(viewsDir).filter(file => file.endsWith('.vue'))
  13. const input = {}
  14. vueFiles.forEach(file => {
  15. const pageName = file.replace('.vue', '')
  16. const htmlPath = `${pagesDir}/${pageName}.html`
  17. const htmlContent = `<!DOCTYPE html>
  18. <html lang="en">
  19. <head>
  20. <meta charset="UTF-8" />
  21. <link rel="icon" type="image/svg+xml" href="/vite.svg" />
  22. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  23. <title>${pageName}</title>
  24. </head>
  25. <body>
  26. <div id="app"></div>
  27. <script type="module" src="/src/main.js"></script>
  28. </body>
  29. </html>`
  30. writeFileSync(htmlPath, htmlContent)
  31. input[pageName] = resolve(__dirname, htmlPath)
  32. })
  33. return input
  34. }
  35. export default defineConfig({
  36. plugins: [vue()],
  37. build: {
  38. rollupOptions: {
  39. input: {
  40. // 添加 index.html 作为默认页面
  41. index: resolve(__dirname, 'index.html'),
  42. ...setupMultiPage()
  43. }
  44. }
  45. },
  46. preview: {
  47. port: 4173,
  48. host: true,
  49. // 设置默认打开的页面
  50. open: '/pages/landingList.html'
  51. }
  52. })