-
Notifications
You must be signed in to change notification settings - Fork 3
/
tsup.config.ts
57 lines (53 loc) · 1.12 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
47
48
49
50
51
52
53
54
55
56
57
import { defineConfig, Options } from 'tsup';
function getCommonConfig(): Options {
return {
splitting: false,
};
}
function getPackageConfig(platform: 'node' | 'browser'): Options {
return {
...getCommonConfig(),
outDir: 'build',
name: platform,
platform,
entry: ['src/main.ts'],
outExtension({ format }) {
if (format === 'cjs') return { js: `.${platform}.${format}` };
return { js: `.${platform}.${format}.js` };
},
};
}
function getCLIConfig(): Options {
return {
...getCommonConfig(),
outDir: 'bin',
name: 'cli',
entry: ['src/cli/CLI.ts'],
format: ['cjs'],
esbuildPlugins: [
{
name: 'rewrite-main-import',
setup(build) {
build.onResolve({ filter: /^\.\.\/main$/ }, () => {
return { path: '../build/main.node.cjs', external: true };
});
},
},
],
};
}
export default defineConfig([
{
...getPackageConfig('node'),
format: ['cjs', 'esm'],
dts: true,
},
{
...getPackageConfig('browser'),
format: ['esm'],
noExternal: [/./],
},
{
...getCLIConfig(),
},
]);