vite.config.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import vueJsx from '@vitejs/plugin-vue-jsx'
  5. import Components from 'unplugin-vue-components/vite'
  6. import { VantResolver } from '@vant/auto-import-resolver'
  7. import { resolve } from 'path'
  8. // https://vitejs.dev/config/
  9. export default defineConfig({
  10. base: './',
  11. plugins: [
  12. vue(),
  13. vueJsx(),
  14. Components({
  15. resolvers: [VantResolver()]
  16. })
  17. ],
  18. resolve: {
  19. alias: {
  20. '@': fileURLToPath(new URL('./src', import.meta.url))
  21. }
  22. },
  23. build: {
  24. rollupOptions: {
  25. input: {
  26. coverHome: resolve(__dirname, 'cover-home/index.html'),
  27. monument: resolve(__dirname, 'monument/index.html'),
  28. bookFair: resolve(__dirname, 'book-fair/index.html'),
  29. tongyan: resolve(__dirname, 'tongyan/index.html'),
  30. birds: resolve(__dirname, 'birds/index.html'),
  31. wedding: resolve(__dirname, 'wedding/index.html')
  32. },
  33. output: {
  34. assetFileNames: (assetInfo) => {
  35. const name = assetInfo.name ?? ''
  36. const info = name.split('.')
  37. let extType = info[info.length - 1]
  38. if (/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/i.test(name)) {
  39. extType = 'media'
  40. } else if (/\.(png|jpe?g|gif|svg)(\?.*)?$/.test(name)) {
  41. extType = 'imgs'
  42. } else if (/\.(woff2?|eot|ttf|otf)(\?.*)?$/i.test(name)) {
  43. extType = 'fonts'
  44. }
  45. return `static/${extType}/[name]-[hash][extname]`
  46. },
  47. chunkFileNames: 'static/js/[name]-[hash].js',
  48. entryFileNames: 'static/js/[name]-[hash].js'
  49. }
  50. }
  51. }
  52. })