vite.config.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { fileURLToPath, URL } from 'node:url'
  2. import type { UserConfigExport } from 'vite'
  3. import { defineConfig } from 'vite'
  4. import vue from '@vitejs/plugin-vue'
  5. import vueJsx from '@vitejs/plugin-vue-jsx'
  6. import dts from 'vite-plugin-dts'
  7. export default defineConfig(ctx => {
  8. const alias: Record<string, string> = {
  9. '@': fileURLToPath(new URL('./src', import.meta.url)),
  10. events: 'events',
  11. path: 'path-browserify',
  12. stream: 'stream-browserify',
  13. zlib: 'browserify-zlib'
  14. }
  15. if (ctx.mode !== 'lib') {
  16. alias['@file-viewer/core'] = fileURLToPath(new URL('../../core/src/index.ts', import.meta.url))
  17. }
  18. const config: UserConfigExport = {
  19. plugins: [vue(), vueJsx()],
  20. base: './',
  21. resolve: {
  22. alias
  23. }
  24. }
  25. if (ctx.mode === 'lib') {
  26. config.plugins?.push(dts({ rollupTypes: true }))
  27. config.build = {
  28. target: 'es2015',
  29. copyPublicDir: false,
  30. emptyOutDir: true,
  31. lib: {
  32. entry: fileURLToPath(new URL('src/package/index.ts', import.meta.url)),
  33. name: 'fileViewerVue3',
  34. formats: ['es'],
  35. fileName: format => format === 'es' ? 'index.mjs' : 'index.umd.js'
  36. },
  37. rollupOptions: {
  38. external: ['vue', '@file-viewer/core'],
  39. output: {
  40. chunkFileNames: 'components/[name].js'
  41. }
  42. }
  43. }
  44. config.worker = {
  45. rollupOptions: {
  46. output: {
  47. entryFileNames: 'worker/[name].js'
  48. }
  49. }
  50. }
  51. }
  52. return config
  53. })