|
| 1 | +import { resolve } from 'node:path' |
| 2 | +import { fileURLToPath, URL } from 'node:url' |
| 3 | + |
| 4 | +import { defineConfig } from 'vite' |
| 5 | +import vue from '@vitejs/plugin-vue' |
| 6 | +import dts from 'vite-plugin-dts' |
| 7 | + |
| 8 | +export default defineConfig(({ mode }) => { |
| 9 | + if (mode !== 'production' && mode !== 'development' && mode !== 'neutral' && mode !== 'test') { |
| 10 | + throw new Error(`Unknown mode: ${mode}`) |
| 11 | + } |
| 12 | + |
| 13 | + const dtsPlugin = mode === 'neutral' ? dts({ |
| 14 | + copyDtsFiles: false |
| 15 | + }) : null |
| 16 | + |
| 17 | + return { |
| 18 | + plugins: [ |
| 19 | + vue(), |
| 20 | + dtsPlugin |
| 21 | + ], |
| 22 | + resolve: { |
| 23 | + alias: { |
| 24 | + '@': fileURLToPath(new URL('./src', import.meta.url)) |
| 25 | + } |
| 26 | + }, |
| 27 | + define: ['production', 'development'].includes(mode) ? { |
| 28 | + 'process.env.NODE_ENV': JSON.stringify(mode) |
| 29 | + } : {}, |
| 30 | + build: { |
| 31 | + emptyOutDir: false, |
| 32 | + minify: mode === 'production', |
| 33 | + lib: { |
| 34 | + entry: resolve(__dirname, 'src/vue-vnode-utils.ts'), |
| 35 | + name: 'VueVNodeUtils', |
| 36 | + formats: mode === 'neutral' ? ['cjs', 'es'] : ['es', 'iife'], |
| 37 | + |
| 38 | + fileName(format) { |
| 39 | + let name = 'vue-vnode-utils' |
| 40 | + |
| 41 | + if (format === 'iife') { |
| 42 | + name += '.global' |
| 43 | + } else if (format === 'es') { |
| 44 | + name += '.esm-' + (mode === 'neutral' ? 'bundler' : 'browser') |
| 45 | + } |
| 46 | + |
| 47 | + if (mode === 'production') { |
| 48 | + name += '.prod' |
| 49 | + } else if (mode === 'development') { |
| 50 | + name += '.dev' |
| 51 | + } |
| 52 | + |
| 53 | + name += format === 'cjs' ? '.cjs' : '.js' |
| 54 | + |
| 55 | + return name |
| 56 | + } |
| 57 | + }, |
| 58 | + rollupOptions: { |
| 59 | + external: ['vue'], |
| 60 | + output: { |
| 61 | + globals: { |
| 62 | + vue: 'Vue' |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | +}) |
0 commit comments