vite.config.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. monument: resolve(__dirname, 'monument/index.html'),
  27. bookFair: resolve(__dirname, 'book-fair/index.html'),
  28. tongyan: resolve(__dirname, 'tongyan/index.html'),
  29. birds: resolve(__dirname, 'birds/index.html')
  30. },
  31. output: {
  32. assetFileNames: (assetInfo) => {
  33. const name = assetInfo.name ?? ''
  34. const info = name.split('.')
  35. let extType = info[info.length - 1]
  36. if (/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/i.test(name)) {
  37. extType = 'media'
  38. } else if (/\.(png|jpe?g|gif|svg)(\?.*)?$/.test(name)) {
  39. extType = 'imgs'
  40. } else if (/\.(woff2?|eot|ttf|otf)(\?.*)?$/i.test(name)) {
  41. extType = 'fonts'
  42. }
  43. return `static/${extType}/[name]-[hash][extname]`
  44. },
  45. chunkFileNames: 'static/js/[name]-[hash].js',
  46. entryFileNames: 'static/js/[name]-[hash].js'
  47. }
  48. }
  49. }
  50. })