mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-19 19:51:20 -08:00
refactor(tooling): [MOD-02] split library build and development into typed modules
This commit is contained in:
1 parent
28c7abb2bb
commit
401d4cdd65
36 files changed
+1644
-427
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import type { BuildOptions, InlineConfig, LibraryFormats, Plugin } from 'vite'
|
||||
import { bannerPlugin, workerBannerPlugin } from './banner.ts'
|
||||
|
||||
export interface LibraryConfigOptions {
|
||||
entry: string
|
||||
outDir: string
|
||||
name: string
|
||||
format: LibraryFormats
|
||||
fileName: string
|
||||
minify?: boolean | 'esbuild' | 'terser'
|
||||
target?: string | string[]
|
||||
banner?: string
|
||||
emptyOutDir?: boolean
|
||||
}
|
||||
|
||||
type LibraryConfig = InlineConfig & {
|
||||
build: BuildOptions & { rollupOptions: NonNullable<BuildOptions['rollupOptions']> & { plugins: Plugin[] } }
|
||||
define: Record<string, string>
|
||||
}
|
||||
|
||||
export function getViteBuildConfig(options: LibraryConfigOptions): LibraryConfig {
|
||||
const { entry, outDir, name, format, fileName, minify = 'esbuild', target = 'es2020', banner, emptyOutDir = false } = options
|
||||
return {
|
||||
configFile: false,
|
||||
publicDir: false,
|
||||
logLevel: 'warn',
|
||||
build: {
|
||||
outDir,
|
||||
emptyOutDir,
|
||||
minify,
|
||||
target,
|
||||
lib: { entry, name, formats: [format], fileName: () => fileName },
|
||||
rollupOptions: {
|
||||
output: { exports: 'default' },
|
||||
plugins: banner ? [bannerPlugin(name, banner)] : [],
|
||||
},
|
||||
},
|
||||
worker: { format: 'es', plugins: () => [workerBannerPlugin()] },
|
||||
define: { 'process.env.NODE_ENV': JSON.stringify(minify ? 'production' : 'development') },
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user