-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsup.config.ts
More file actions
49 lines (42 loc) · 1.12 KB
/
tsup.config.ts
File metadata and controls
49 lines (42 loc) · 1.12 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
import { defineConfig, Options } from 'tsup';
import { readdirSync } from 'node:fs';
import { join } from 'node:path';
const buildDir = 'dist/';
const external = ['@catbee/utils'];
const cwd = process.cwd();
const srcRoot = join(cwd, 'src');
const modules = readdirSync(srcRoot, { withFileTypes: true })
.filter(d => d.isDirectory())
.map(d => d.name);
const getBaseConfig = ({ bundle = true, sourcemap = false }): Options => {
const options: Options = {
bundle,
splitting: false,
target: 'es2022',
clean: true,
minify: false,
sourcemap,
format: ['cjs', 'esm'],
outExtension({ format }) {
return format === 'esm' ? { js: '.mjs' } : { js: '.cjs' };
},
treeshake: 'recommended',
external
};
return options;
};
const entryPoints = modules.flatMap((name: string): Options[] => [
{
...getBaseConfig({ bundle: true, sourcemap: false }),
entry: [`src/${name}/index.ts`],
outDir: `${buildDir}${name}`
}
]);
export default defineConfig([
...entryPoints,
{
...getBaseConfig({ bundle: false, sourcemap: false }),
entry: ['src/index.ts'],
outDir: buildDir
}
]);