-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsup.config.ts
65 lines (57 loc) · 2.04 KB
/
tsup.config.ts
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
import { spawnSync } from "child_process";
import { defineConfig as defineTsupConfig } from "tsup";
import type { SpawnSyncOptionsWithStringEncoding as SpawnSyncOptions } from "child_process";
/**
* Options for spawning synchronous processes.
*/
const spawnProcessOptions: SpawnSyncOptions = {
cwd: process.cwd(),
env: process.env,
stdio: "inherit",
encoding: "utf-8",
};
/**
* `tsup` configuration.
* @see https://tsup.egoist.dev
*/
const tsupConfig = defineTsupConfig({
entry: {
ui: "src/index.ts",
next: "src/index.next.ts",
},
// TODO enable Rollup tree-shaking, temporarily disabled to allow properly injecting `use client` directive banner (Rollup tree-shaking removes it); track https://github.com/egoist/tsup/issues/835
// treeshake: true,
sourcemap: true,
minify: true,
clean: true,
splitting: false,
format: ["cjs", "esm"],
// NB: `peerDeps`, among others, are excluded (marked external) by default
// see https://tsup.egoist.dev/#excluding-packages
external: [
"@ark-ui/react",
"react-icons",
"next",
"framer-motion",
"react-hot-toast",
],
outDir: "build",
esbuildOptions: (opt, _ctx) => {
// https://esbuild.github.io/api/#resolve-extensions
const defaultExtensions = [".tsx", ".ts", ".jsx", ".js", ".css", ".json"];
// filter out extensions from `esbuild` defaults
const selectedDefaultExtensions = defaultExtensions.filter(
(ext) => ![".css", ".json"].includes(ext),
);
// extend recognized extensions to include explicit ESM extensions
opt.resolveExtensions = [...selectedDefaultExtensions, ".mts", ".mjs"];
},
onSuccess: async () => {
console.log("Generating type declarations...");
// NB: below is used as alternative to `tsup` config `dts: true` option to avoid race condition with local package publish (at the cost of less concurrency)
spawnSync("bun", ["tsup", "--dts-only"], spawnProcessOptions);
console.log("Publishing local package...");
spawnSync("bun", ["knit", "push"], spawnProcessOptions);
},
});
export default tsupConfig;