-
Notifications
You must be signed in to change notification settings - Fork 0
/
__tsup.config.ts
104 lines (87 loc) · 2.34 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { defineConfig } from 'tsup';
import { CLIENT_PKGS } from '@thencc/any-wallet';
// helpful plugin logic from: https://github.com/evanw/esbuild/issues/1685
import { readFileSync } from 'fs';
const excludeVendorFromSourceMapPlugin = ({ filter }) => ({
name: 'excludeVendorFromSourceMap',
setup(build) {
build.onLoad({ filter }, (args) => {
if (args.path.endsWith('.js')) {
return {
contents:
readFileSync(args.path, 'utf8') +
'\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==',
loader: 'default',
};
}
});
},
});
export default defineConfig({
entry: ['./src/index.ts'],
outDir: './dist',
clean: true, // cleans outDir before build
dts: true, // requires typescript peer dep
sourcemap: true,
format: ['esm', 'cjs'],
tsconfig: './tsconfig.json',
// legacyOutput: true,
outExtension({ format }) {
// console.log('format', format);
// return {
// js: `.${format}.js`,
// }
if (format == 'cjs') {
return {
js: `.cjs`
}
} else if (format == 'esm') {
return {
js: `.mjs`
}
} else {
return {
js: `.${format}.js`,
}
}
},
// iife / global build
// if doing this, add tp pkg.json
// "browser": "dist/index.global.js",
// add "iife" to format field like: ['esm', 'cjs', 'iife']
// globalName: 'w3w3w', // for iife, but really who will use this...
// DONT bundle wallet-specific libs
external: [
...CLIENT_PKGS,
],
// aka DO BUNDLE these:
noExternal: [
'algosdk',
'buffer',
'@thencc/any-wallet'
],
esbuildPlugins: [
// needed to keep .map file down in size!
excludeVendorFromSourceMapPlugin({ filter: /node_modules/ })
],
// entire esbuild config avail
// esbuildOptions(options, context) {
// // options.define.foo = 'bar';
// options.alias = {
// };
// },
platform: 'browser', // makes sure "crypto" isnt needed
// platform: 'neutral', // TODO should we do neutral? try but make sure all env tests pass + build size isnt crazy big...
bundle: true, // TODO we shouldnt bundle our lib. assume frontends/final users will do that. (for dux w/out bundlers use jsdelvr )
shims: true,
// optimized config:
keepNames: false,
splitting: false,
minify: true,
treeshake: true,
// dev/debug config:
// keepNames: true,
// splitting: true,
// minify: false,
// treeshake: false,
});