-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
65 lines (59 loc) · 1.58 KB
/
tsdown.config.ts
File metadata and controls
65 lines (59 loc) · 1.58 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { rmSync } from 'node:fs'
import { build, defineConfig } from 'tsdown'
async function transformJS(path: string) {
const result = await build({
entry: path,
minify: true,
write: false,
dts: false,
config: false,
})
const chunk = result[0].chunks[0]
if (chunk.type === 'chunk') {
return chunk.code
}
throw new Error('Not chunk')
}
async function transformCSS(path: string) {
const result = await build({
entry: path,
minify: true,
write: false,
dts: false,
config: false,
})
const chunk = result[0].chunks[1]
if (chunk.type === 'asset') {
return chunk.source.toString().replace(/\s+/g, ' ')
}
throw new Error('Not asset')
}
rmSync('./dist', { recursive: true, force: true })
const fontCSS = await transformCSS('./src/utils/devtools/font.css')
const scrollbarCSS = await transformCSS('./src/utils/devtools/scrollbar.css')
const JS = await transformJS('./src/utils/devtools/js.ts')
export default defineConfig([
{
entry: {
index: './src/entry/index.ts',
utils: './src/utils/index.ts',
provider: './src/provider/index.ts',
},
format: ['esm', 'cjs'],
dts: { oxc: true },
define: {
__FONT_CSS__: JSON.stringify(fontCSS?.replace(/\n/g, '') || ''),
__SCROLLBAR_CSS__: JSON.stringify(scrollbarCSS?.replace(/\n/g, '') || ''),
__JS__: JSON.stringify(JS?.replace(/\n/g, '').replace('export{};', '') || ''),
},
},
{
entry: {
vite: './src/vite/index.ts',
},
format: 'esm',
dts: { resolve: true },
treeshake: true,
external: ['electron', 'vite'],
},
])