-
Notifications
You must be signed in to change notification settings - Fork 3
/
tsup.config.ts
48 lines (45 loc) · 1.69 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
import path from "path"
import { defineConfig } from "tsup"
export default defineConfig((options) => {
const isBrowser = options.env?.NODE_ENV === 'browser'
const rootDir = process.cwd()
const alias = {
'@sdk/grpcTransport': path.resolve(rootDir, isBrowser ? 'src/grpcTransport.web.ts' : 'src/grpcTransport.node.ts')
}
return {
entry: ['src/index.ts'],
splitting: false,
clean: true,
dts: {
resolve: true,
compilerOptions: {
paths: {
"@sdk/*": ["./src/*"],
"@sdk/grpcTransport": ["./src/grpcTransport.node.ts", "./src/grpcTransport.web.ts"]
}
}
},
format: isBrowser ? ['esm'] : ['cjs', 'esm'],
outDir: isBrowser ? 'lib/browser' : 'lib/node',
define: {
'process.env.NODE_ENV': JSON.stringify(options.env?.NODE_ENV || 'development')
},
alias,
esbuildOptions(options) {
options.alias = alias
if (isBrowser) {
options.mainFields = ['browser', 'module', 'main']
options.define = {
...options.define,
global: 'window' // Ensure `global` is available in the browser
}
options.inject = [path.resolve('node_modules/buffer/index.js')] // Inject the buffer polyfill
} else {
options.mainFields = ['module', 'main']
}
},
noExternal: isBrowser ? ['@connectrpc/connect', '@connectrpc/connect-web', '@connectrpc/connect-node'] : [],
sourcemap: true,
tsconfig: path.resolve(rootDir, 'tsconfig.json'),
}
})