vite.config.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import path from 'path'
  2. import pkg from './package.json'
  3. import { defineConfig } from 'vite'
  4. import vue2 from '@vitejs/plugin-vue2'
  5. import vueJsx from '@vitejs/plugin-vue2-jsx'
  6. export default defineConfig({
  7. base: '/',
  8. resolve: {
  9. alias: {
  10. '@': path.resolve(__dirname, 'src'),
  11. 'vue': 'vue/dist/vue.esm'
  12. }
  13. },
  14. server: {
  15. host: '0.0.0.0',
  16. port: 3000
  17. },
  18. build: {
  19. minify: true,
  20. cssCodeSplit: true, // 将组件的 style 打包到 js 文件中
  21. outDir: 'dist',
  22. lib: {
  23. target: 'esnext',
  24. formats: ['umd'],
  25. entry: path.resolve(__dirname, 'src/main.js'),
  26. name: 'CustomForm',
  27. fileName: (format) => `form.${pkg.version}.${format}.js`
  28. },
  29. rollupOptions: {
  30. // 确保外部化处理那些你不想打包进库的依赖
  31. external: ['vue'],
  32. output: {
  33. // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
  34. globals: {
  35. vue: 'Vue'
  36. }
  37. }
  38. }
  39. },
  40. plugins: [
  41. vueJsx(),
  42. vue2({
  43. template: {
  44. // 解决Dom结构中会出现多余的空白字符,导致文本内容间出现分隔、行内标签间出现空格
  45. compilerOptions: {
  46. whitespace: 'condense',
  47. }
  48. }
  49. }),
  50. ]
  51. })