-
Notifications
You must be signed in to change notification settings - Fork 3
/
tsup.config.ts
78 lines (76 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
66
67
68
69
70
71
72
73
74
75
76
77
78
import esbuild from "esbuild";
import { defineConfig } from "tsup";
process.env.NODE_ENV = process.env.NODE_ENV || "production";
process.env.VERSION = process.env.VERSION || "0.0.0";
export default defineConfig([
// SDK for NodeJS.
{
cjsInterop: true,
dts: true,
entry: ["src/lib/index.ts"],
env: {
NODE_ENV: process.env.NODE_ENV,
VERSION: process.env.VERSION,
},
format: ["cjs", "esm"],
minify: process.env.NODE_ENV === "production",
outDir: "dist/lib",
shims: true,
sourcemap: true,
// CJS interop is broken without splitting, see:
// * https://github.com/egoist/tsup/issues/992#issuecomment-1763540165
splitting: true,
target: "esnext",
},
// SDK for Browser.
{
dts: true,
entry: ["src/lib/index.ts"],
env: {
BROWSER_BUILD: "true",
NODE_ENV: process.env.NODE_ENV,
VERSION: process.env.VERSION,
},
format: ["cjs", "esm"],
minify: process.env.NODE_ENV === "production",
outDir: "dist/lib/browser",
shims: true,
sourcemap: true,
splitting: true,
target: "esnext",
treeshake: "smallest",
// Produce an IIFE bundle for use with a <script> tag in a browser.
onSuccess: async () => {
await esbuild.build({
bundle: true,
entryPoints: ["dist/lib/browser/index.mjs"],
format: "iife",
footer: {
js: "var sindri = sindriExports.default;",
},
globalName: "sindriExports",
minify: process.env.NODE_ENV === "production",
outfile: "dist/lib/browser/sindri.iife.js",
platform: "browser",
sourcemap: true,
});
},
// Additional browser-specific configuration will go here (e.g. polyfills).
},
// CLI Tool.
{
bundle: true,
dts: true,
entry: ["src/cli/index.ts"],
env: {
NODE_ENV: process.env.NODE_ENV,
VERSION: process.env.VERSION,
},
format: ["cjs"],
minify: process.env.NODE_ENV === "production",
outDir: "dist/cli",
shims: true,
sourcemap: true,
target: "node18",
},
]);