vite.config.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import { fileURLToPath } from 'url'
  4. import path from 'path'
  5. const resolve = (dir: string) => path.join(__dirname, dir)
  6. export default defineConfig({
  7. plugins: [vue()],
  8. resolve: {
  9. alias: {
  10. /*
  11. * We recommend to not use aliases in the lib's source,
  12. * because they will leak into the generated d.ts files and then
  13. * break the lib's types in the consuming app.
  14. */
  15. '@lib': resolve('src')
  16. },
  17. extensions: ['.js', '.json', '.vue', '.ts']
  18. },
  19. build: {
  20. lib: {
  21. name: 'vivid',
  22. entry: fileURLToPath(new URL('./src/index.ts', import.meta.url)),
  23. formats: ['es', 'cjs', 'iife'],
  24. fileName: (format) => {
  25. switch (format) {
  26. case 'es':
  27. return 'index.mjs'
  28. case 'cjs':
  29. return 'index.cjs'
  30. case 'iife':
  31. return 'index.js'
  32. default:
  33. return 'index.js'
  34. }
  35. },
  36. },
  37. minify: true,
  38. rollupOptions: {
  39. external: [
  40. 'vue',
  41. 'naive-ui',
  42. 'animate.css',
  43. 'katex',
  44. 'lowlight',
  45. 'remixicon/fonts/remixicon.css',
  46. ],
  47. output: {
  48. banner: `
  49. /**
  50. * Copyright ${new Date(Date.now()).getFullYear()} codecode.run zhufeng
  51. **/
  52. `,
  53. exports: 'named',
  54. globals: {
  55. vue: 'Vue',
  56. },
  57. },
  58. },
  59. },
  60. })