Invalid value "umd" for option "output.format" - UMD and IIFE output formats are not supported for code-splitting builds.问题修复
问题:vite2打lib库包时报Invalid value "umd" for option "output.format" - UMD and IIFE output formats are not supported for code-splitting builds.错误
原因:lib.formats默认 ['es', 'umd'],output.format默认es,不支持多个值
解决方案:lib.formats设置为['es']
vite.config.js配置的build如下:
import { defineConfig } from 'vite'; import { createVuePlugin } from 'vite-plugin-vue2'; const path = require('path'); export default defineConfig({ build: { // 输出文件目录 outDir: 'libs', // 生产环境移除console minify: 'terser', lib: { entry: path.resolve(__dirname, './src/components/index.ts'), name: 'libs', fileName: (format) => `isafety-ui.${format}.js`, formats: ['es'], // 默认['es', 'umd'] }, terserOptions: { compress: { drop_console: true, drop_debugger: true, }, }, rollupOptions: { // 确保外部化处理那些你不想打包进库的依赖 external: ['vue'], output: { // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量 globals: { vue: 'Vue', }, // format: 'es', // 默认'es' } } }, });