-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsup.config.ts
More file actions
56 lines (49 loc) · 1.51 KB
/
tsup.config.ts
File metadata and controls
56 lines (49 loc) · 1.51 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
import { defineConfig } from "tsup";
import { existsSync, mkdirSync } from "fs";
import { join } from "path";
export default defineConfig({
entry: ["src/index.ts"],
format: ["esm"],
dts: true,
sourcemap: true,
clean: true,
target: "es2022",
outDir: "dist",
splitting: false,
minify: false,
external: [],
banner: {
js: `// Runtime files will be resolved from the dist directory`
},
loader: {
".json": "json"
},
onSuccess: async () => {
// Copy runtime directory to dist after build
const runtimeDir = join(process.cwd(), "runtime");
const distRuntimeDir = join(process.cwd(), "dist", "runtime");
if (existsSync(runtimeDir)) {
if (!existsSync(distRuntimeDir)) {
mkdirSync(distRuntimeDir, { recursive: true });
}
// Copy runtime files
const fs = await import("fs/promises");
const path = await import("path");
async function copyDir(src: string, dest: string) {
await fs.mkdir(dest, { recursive: true });
const entries = await fs.readdir(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
await copyDir(srcPath, destPath);
} else {
await fs.copyFile(srcPath, destPath);
}
}
}
await copyDir(runtimeDir, distRuntimeDir);
console.log("✓ Runtime files copied to dist/runtime");
}
}
});