-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsup.config.ts
More file actions
85 lines (82 loc) · 2.27 KB
/
Copy pathtsup.config.ts
File metadata and controls
85 lines (82 loc) · 2.27 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
import { defineConfig } from 'tsup';
import path from 'path';
const NODE_BUILTINS = [
'http', 'https', 'url', 'net', 'dns', 'module', 'crypto', 'async_hooks', 'perf_hooks',
'node:http', 'node:https', 'node:url', 'node:net', 'node:dns', 'node:module',
'node:crypto', 'node:async_hooks', 'node:perf_hooks'
];
const workerContextPlugin = {
name: 'worker-context',
setup(build: any) {
build.onResolve({ filter: /context$/ }, (args: any) => {
if (args.path === './context' || args.path === '../core/context') {
return {
path: path.resolve(args.resolveDir, args.path.replace(/context$/, 'context.worker.ts')),
};
}
return null;
});
build.onResolve({ filter: /instrumentation/ }, (args: any) => {
const UTILITY_MODULES = ['dummy', 'framework', 'hook', 'http', 'patch', 'runtime', 'span'];
const basename = args.path.split('/').pop()?.replace(/\.ts$/, '');
if (basename && UTILITY_MODULES.includes(basename)) {
return null;
}
if (args.path.startsWith('../instrumentation/') || args.path.startsWith('./instrumentation/')) {
return {
path: path.resolve(__dirname, 'src/instrumentation/dummy.ts'),
};
}
return null;
});
},
};
export default defineConfig([
// 1. Node.js Build (CommonJS + ESM)
{
entry: ['src/index.ts', 'src/register.ts', 'src/lambda-handler.ts'],
format: ['cjs', 'esm'],
outExtension({ format }) {
return {
js: format === 'esm' ? '.node.mjs' : '.js',
};
},
dts: true,
clean: true,
minify: true,
sourcemap: true,
splitting: false,
external: NODE_BUILTINS,
noExternal: [],
},
// 2. Cloudflare Workers / Edge Build (ESM only)
{
entry: {
'index': 'src/index.ts',
},
format: ['esm'],
outExtension() {
return {
js: '.worker.mjs',
};
},
dts: false,
clean: false,
minify: true,
sourcemap: true,
splitting: false,
external: NODE_BUILTINS,
esbuildPlugins: [workerContextPlugin],
},
// 3. Browser IIFE Build
{
entry: ['src/index.ts'],
format: ['iife'],
clean: false,
minify: true,
sourcemap: true,
splitting: false,
external: NODE_BUILTINS,
esbuildPlugins: [workerContextPlugin],
}
]);