This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
tsup.config.ts
80 lines (78 loc) · 2.52 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
79
80
import { defineConfig } from "tsup";
import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";
import plugin from "node-stdlib-browser/helpers/esbuild/plugin";
import stdLibBrowser from "node-stdlib-browser";
export default defineConfig([
// build for node
{
name: "node",
entry: ["src/index.ts"],
sourcemap: true,
// we'll just manually "clean" the dist dir before running this (to avoid potential race conditions)
clean: false,
minify: false,
platform: "node",
replaceNodeEnv: true,
// now required because not defaulted anymore
shims: true,
// use rollup for build to get smaller bundle sizes with tree shaking
treeshake: true,
globalName: "ThirdwebSDK",
format: ["cjs", "esm"],
outDir: "dist/node",
banner: {
js: `import "cross-fetch/dist/node-polyfill.js";`,
},
},
// build for browser
{
name: "browser",
entry: ["src/index.ts"],
sourcemap: true,
// we'll just manually "clean" the dist dir before running this (to avoid potential race conditions)
clean: false,
minify: true,
platform: "browser",
replaceNodeEnv: true,
// now required because not defaulted anymore
shims: true,
// use rollup for build to get smaller bundle sizes with tree shaking
treeshake: true,
globalName: "ThirdwebSDK",
format: ["cjs", "esm"],
// contains node-only functions, aka has to be bundled in for browser
noExternal: ["cbor"],
inject: [`node_modules/node-stdlib-browser/helpers/esbuild/shim.js`],
define: {
Buffer: "Buffer",
},
esbuildPlugins: [NodeModulesPolyfillPlugin(), plugin(stdLibBrowser)],
outDir: "dist/browser",
},
// build for script-tag usage <script src="..."></script>
{
name: "script",
entry: ["src/index.ts"],
sourcemap: true,
// we'll just manually "clean" the dist dir before running this (to avoid potential race conditions
clean: false,
minify: true,
platform: "browser",
replaceNodeEnv: true,
// now required because not defaulted anymore
shims: true,
globalName: "_thirdweb",
format: ["iife"],
banner: {
js: "window.global=window;window.globalThis=window;",
},
// inject ThirdwebSDK into window
footer: { js: "window.ThirdwebSDK = window._thirdweb.ThirdwebSDK;" },
inject: [`node_modules/node-stdlib-browser/helpers/esbuild/shim.js`],
define: {
Buffer: "Buffer",
},
esbuildPlugins: [NodeModulesPolyfillPlugin(), plugin(stdLibBrowser)],
outDir: "dist/browser",
},
]);