-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsup.config.ts
32 lines (28 loc) · 936 Bytes
/
tsup.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { log } from 'node:console'
import { existsSync, readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { defineConfig } from 'tsup'
// biome-ignore lint:
function getFileJson(file: string): Partial<Record<string, any>> {
const filepath = resolve(process.cwd(), file)
if (!existsSync(filepath)) return {}
const str = readFileSync(filepath, 'utf-8')
// biome-ignore lint:
let json: any
try {
json = JSON.parse(str)
} catch (e) {
throw new Error(`Parse Error at ${filepath}: ${String(e)}`)
}
return json
}
export default defineConfig((options) => {
if (!options.silent) log('Dir:', process.cwd())
const [tsconfig, pkg] = ['tsconfig.json', 'package.json'].map((file) => getFileJson(file))
return {
entryPoints: ['./src'],
outDir: tsconfig?.compilerOptions?.outDir ?? './dist',
bundle: false,
clean: !!process.argv.find((el) => el === '--define.env=prod')
}
})