vite.config.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import vue from '@vitejs/plugin-vue'
  2. import viteSvgIcons from 'vite-plugin-svg-icons'
  3. import path from 'path'
  4. import pkg from './package.json'
  5. export default {
  6. base: './',
  7. build: {
  8. minify: false,
  9. cssCodeSplit: true, // 将组件的 style 打包到 js 文件中
  10. outDir: 'dist',
  11. lib: {
  12. target: 'esnext',
  13. formats: ['iife'],
  14. entry: path.resolve(__dirname, 'src/index.js'),
  15. name: 'MagicComponent',
  16. fileName: (format) => `magic-component.${pkg.version}.${format}.js`
  17. },
  18. rollupOptions: {
  19. // 确保外部化处理那些你不想打包进库的依赖
  20. external: ['vue'],
  21. output: {
  22. // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
  23. globals: {
  24. vue: 'Vue'
  25. }
  26. }
  27. }
  28. },
  29. plugins: [
  30. vue(),
  31. viteSvgIcons({
  32. iconDirs: [path.resolve(process.cwd(), 'src/icons')],
  33. symbolId: 'magic-component-[name]'
  34. }),
  35. ]
  36. }