1
0
mirror of https://github.com/tabler/tabler.git synced 2026-08-08 04:12:26 +04:00
Files
tabler/.build/vite.config.helper.ts
T

66 lines
1.8 KiB
TypeScript

import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig, type UserConfig } from 'vite'
interface CreateViteConfigOptions {
entry: string
name?: string
fileName: string | ((format: string) => string)
formats: ('es' | 'umd' | 'iife' | 'cjs')[]
outDir: string
banner?: string
minify?: boolean | 'esbuild'
}
/**
* Creates a Vite configuration for building libraries
*/
export function createViteConfig({ entry, name, fileName, formats, outDir, banner, minify = false }: CreateViteConfigOptions): UserConfig {
// Vite 8 (Rolldown) always emits const bindings and no longer accepts the
// Rollup-only generatedCode.constBindings option
const rollupOutput: { banner?: string } = {}
// Add banner if provided
if (banner) {
rollupOutput.banner = banner
}
const config: UserConfig = {
// These are library (JS bundle) builds, not app builds — Vite's default
// behavior of copying <root>/public into outDir on every build is not wanted
// here (and in @tabler/preview, where public/ is itself generated from this
// same outDir, caused unbounded growth across repeated builds).
publicDir: false,
build: {
lib: {
entry: path.resolve(entry),
name: name,
fileName: typeof fileName === 'function' ? fileName : () => fileName,
formats: formats,
},
outDir: path.resolve(outDir),
emptyOutDir: false,
sourcemap: true,
rollupOptions: {
output: rollupOutput,
},
target: 'es2015',
minify: minify,
},
define: {
'process.env.NODE_ENV': '"production"',
},
esbuild: {
target: 'es2015',
tsconfigRaw: {
compilerOptions: {
module: 'ES2020',
target: 'ES2015',
},
},
},
}
return defineConfig(config)
}