-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsup.config.ts
More file actions
41 lines (37 loc) · 1.14 KB
/
tsup.config.ts
File metadata and controls
41 lines (37 loc) · 1.14 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
import { defineConfig } from 'tsup';
import { copyFileSync, mkdirSync, readdirSync } from 'fs';
import { join } from 'path';
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
sourcemap: true,
clean: true,
splitting: false,
treeshake: true,
// Bundle the TypeScript code but keep data external
bundle: true,
// Mark data paths as external so they're not bundled
esbuildOptions(options) {
options.external = ['./data/*'];
},
// Copy data files to dist directory
onSuccess: async () => {
// Copy data directory to dist
const copyDir = (src: string, dest: string) => {
mkdirSync(dest, { recursive: true });
const entries = readdirSync(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = join(src, entry.name);
const destPath = join(dest, entry.name);
if (entry.isDirectory()) {
copyDir(srcPath, destPath);
} else {
copyFileSync(srcPath, destPath);
}
}
};
copyDir('src/data', 'dist/data');
console.log('✓ Data files copied to dist/data');
},
});