-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsup.config.ts
45 lines (41 loc) · 1.32 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
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/index.ts'],
outDir: tsconfig?.compilerOptions?.outDir ?? './dist',
bundle: true,
// minify: !!process.argv.find((el) => el === '--define.env=prod'),
banner: {
js: `
/**
* @Package ${pkg?.name ?? 'unknown'}
* @Version ${pkg?.version ?? 'unknown'}
* @Author ${Array.isArray(pkg?.author) ? pkg.author.join(', ') : pkg?.author ?? ''}
* @Copyright 2024 Hotaru. All rights reserved.
* @License ${pkg?.license ?? 'GPL-3.0'}
* @Date ${new Date().toLocaleString()}
*/
`
},
clean: !!process.argv.find((el) => el === '--define.env=prod')
}
})