-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsup.config.ts
More file actions
97 lines (79 loc) · 2.32 KB
/
tsup.config.ts
File metadata and controls
97 lines (79 loc) · 2.32 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { defineConfig } from "tsup";
export default defineConfig({
// Entry points - main library file
entry: ["src/index.ts"],
// Output formats
format: ["cjs", "esm"],
// Generate .d.ts files
dts: {
resolve: true,
// Entry point for types
entry: "./src/index.ts",
},
// Split output into chunks for better tree-shaking
splitting: false,
// Sourcemaps for debugging
sourcemap: true,
// Clean output directory before build
clean: true,
// Minify output with Terser for aggressive optimization
minify: "terser",
terserOptions: {
compress: {
passes: 2, // Multiple passes for better optimization
dead_code: true, // Remove unreachable code
unused: true, // Remove unused functions/variables
drop_console: false, // Keep console (we don't use it anyway)
pure_funcs: [], // Will be inferred by terser
},
mangle: {
keep_classnames: false, // Allow class name mangling
keep_fnames: true, // Keep function names (already set in keepNames)
},
format: {
comments: /^!/, // Keep comments starting with /*! (like banner), remove others
},
},
// Bundle external dependencies
// We keep React and Vitest as external since they're peer deps
external: [
"react",
"react-dom",
"vitest",
"@testing-library/react",
"@testing-library/jest-dom",
],
// Don't bundle node modules
noExternal: [],
// Target modern browsers and Node 18+
target: "esnext",
// Enable tree-shaking
treeshake: true,
// Keep original function names for better debugging
keepNames: true,
// Skip node protocol imports
skipNodeModulesBundle: true,
// Environment variables to replace
env: {
NODE_ENV: "production",
},
// Build-time constants for tree-shaking
// Same pattern as vitest.config.common.mts
define: {
__DEV__: "false", // Production build - replaced with keyword false
},
// Output configuration
outDir: "dist",
// Generate banner with package info
banner: {
js: `/*!
* vitest-react-profiler v${process.env.npm_package_version || "0.0.0"}
* (c) ${new Date().getFullYear()} ${process.env.npm_package_author_name || "Contributors"}
* Released under the MIT License.
*/`,
},
// Success callback
onSuccess: async () => {
console.log("✅ Build completed successfully!");
},
});