-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtsup.config.ts
More file actions
52 lines (41 loc) · 1.38 KB
/
Copy pathtsup.config.ts
File metadata and controls
52 lines (41 loc) · 1.38 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
import { defineConfig } from "tsup";
import { readFile, writeFile } from "fs/promises";
import { glob } from "tinyglobby";
export default defineConfig({
// Entry point — barrel file exporting all components
entry: ["src/components/index.ts"],
// Dual format: CommonJS for Node/require(), ESM for bundlers/import
format: ["cjs", "esm"],
// Use dedicated tsconfig without --incremental
tsconfig: "tsconfig.build.json",
// Generate .d.ts declaration files for full TypeScript support
dts: true,
// These are peerDependencies — never bundle them
external: [
"react",
"react-dom",
"react/jsx-runtime",
"framer-motion",
],
// Clean dist/ before each build
clean: true,
// Enable tree-shaking
treeshake: true,
// Source maps for debugging
sourcemap: true,
// Split code for optimal tree-shaking in ESM
splitting: true,
// Target modern browsers + Node 18+
target: "es2020",
// Inject "use client" directives after build (rollup strips banner directives)
async onSuccess() {
const files = await glob("dist/**/*.{js,mjs}", { absolute: true });
for (const file of files) {
const content = await readFile(file, "utf-8");
if (!content.startsWith('"use client"')) {
await writeFile(file, `"use client";\n${content}`);
}
}
console.log(`✓ Injected "use client" into ${files.length} output files`);
},
});