-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsup.config.ts
58 lines (50 loc) · 1.96 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
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",
},
// 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", "framer-motion", "react-icons"],
outDir: "build",
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", ["link"], spawnProcessOptions);
},
esbuildOptions: (opts, _ctx) => {
// https://esbuild.github.io/api/#resolve-extensions
const defaultExtensions = [".tsx", ".ts", ".jsx", ".js", ".css", ".json"];
// extend recognized extensions to include explicit ESM extensions
opts.resolveExtensions = [...defaultExtensions, ".mts", ".mjs"];
opts.banner = {
// TODO remove, necessary for e.g. context, most ark components, etc. but try to set at a more granular level or not set at all
js: '"use client";',
};
},
});
export default tsupConfig;