-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtsup.config.ts
More file actions
92 lines (85 loc) · 2.44 KB
/
Copy pathtsup.config.ts
File metadata and controls
92 lines (85 loc) · 2.44 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
import { resolve } from 'path'
import { defineConfig } from 'tsup'
import type { Options } from 'tsup'
export default defineConfig((options) => {
const isNode = options.env?.TARGET === 'node'
const isBrowser = options.env?.TARGET === 'browser'
if (!isNode && !isBrowser) {
throw new Error(
'TARGET environment variable must be set to either "node" or "browser"'
)
}
const target = isNode ? 'node18' : 'esnext'
const platform = isNode ? 'node' : 'browser'
const outDir = isNode ? 'dist/node' : 'dist/browser'
const config: Options = {
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
target,
platform,
outDir,
outExtension: ({ format }) => {
return {
js: format === 'esm' ? `.${platform}.js` : `.${platform}.cjs`,
}
},
sourcemap: true,
minify: true,
clean: true,
dts: isNode,
external: [
// Node.js built-ins
...(isNode
? ['path', 'fs', 'crypto', 'stream', 'util', 'events', 'buffer']
: ['crypto', 'stream', 'util', 'events', 'buffer']),
// External dependencies that should not be bundled
'cosmjs-types',
'@cosmjs/amino',
'@cosmjs/crypto',
'@cosmjs/encoding',
'@cosmjs/math',
'@cosmjs/proto-signing',
'@cosmjs/stargate',
'@near-js/accounts',
'@near-js/crypto',
'@near-js/keystores',
'@near-js/transactions',
'@near-js/types',
'@near-wallet-selector/core',
'@scure/base',
'@solana/web3.js',
'bech32',
'bitcoinjs-lib',
'bn.js',
'bs58',
'chain-registry',
'coinselect',
'elliptic',
'js-sha3',
'near-api-js',
'viem',
],
treeshake: true,
splitting: false,
esbuildOptions: (options) => {
options.conditions = isNode
? ['node', 'import', 'default']
: ['browser', 'import', 'default']
options.mainFields = isNode
? ['module', 'main']
: ['browser', 'module', 'main']
options.alias = {
'@chain-adapters': resolve(__dirname, './src/chain-adapters'),
'@contracts': resolve(__dirname, './src/contracts'),
'@utils': resolve(__dirname, './src/utils'),
'@constants': resolve(__dirname, './src/constants.ts'),
'@types': resolve(__dirname, './src/types.ts'),
}
// Configure for proper ESM handling
if (options.format === 'esm') {
options.packages = 'external'
}
},
}
return config
})