-
Notifications
You must be signed in to change notification settings - Fork 51
/
tsup.config.ts
46 lines (42 loc) · 1.01 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
46
import fs from 'node:fs'
import { defineConfig, type Options } from 'tsup'
import { bundleless } from 'tsup-plugin-bundleless'
const env = process.env.NODE_ENV
const { esbuildPlugins, plugins } = bundleless({
exclude: ['*.css'],
})
const commonOptions = (options: Options): Options => ({
define: {
'process.env.NODE_ENV': JSON.stringify(env || 'development'),
},
target: 'es2015',
external: ['react', 'react-dom'],
dts: true,
esbuildOptions(opt) {
!options.watch && (opt.drop = ['debugger'])
},
splitting: false,
treeshake: true,
minify: false,
async onSuccess() {
if (fs.existsSync('dist/index.css')) {
fs.renameSync('dist/index.css', 'dist/style.css')
}
},
})
export default defineConfig((options) => [
{
...commonOptions(options),
entry: ['./src/**/*.{ts,tsx}'],
format: ['esm'],
platform: 'browser',
esbuildPlugins,
plugins,
},
{
...commonOptions(options),
entry: ['./src/index.ts'],
format: ['cjs'],
platform: 'neutral',
},
])