|
| 1 | +// @ts-check |
| 2 | +// Local tsup config for @imtbl/audience. |
| 3 | +// |
| 4 | +// Extends the monorepo's root tsup config but overrides `noExternal` so that |
| 5 | +// every `@imtbl/*` workspace dep (audience-core, its transitive metrics dep) |
| 6 | +// is inlined into the built bundle. This makes the package installable as a |
| 7 | +// standalone tarball without the pnpm `workspace:*` protocol. |
| 8 | +import { defineConfig } from 'tsup'; |
| 9 | +import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill'; |
| 10 | +import { replace } from 'esbuild-plugin-replace'; |
| 11 | +import pkg from './package.json' assert { type: 'json' }; |
| 12 | + |
| 13 | +const IMTBL_WORKSPACE = /^@imtbl\//; |
| 14 | + |
| 15 | +export default defineConfig((options) => { |
| 16 | + if (options.watch) { |
| 17 | + return { |
| 18 | + entry: ['src/index.ts'], |
| 19 | + outDir: 'dist/browser', |
| 20 | + format: 'esm', |
| 21 | + target: 'es2022', |
| 22 | + platform: 'browser', |
| 23 | + bundle: true, |
| 24 | + noExternal: [IMTBL_WORKSPACE], |
| 25 | + esbuildPlugins: [ |
| 26 | + nodeModulesPolyfillPlugin({ |
| 27 | + globals: { Buffer: true, process: true }, |
| 28 | + modules: ['crypto', 'buffer', 'process'], |
| 29 | + }), |
| 30 | + replace({ |
| 31 | + __SDK_VERSION__: pkg.version === '0.0.0' ? '2.0.0' : pkg.version, |
| 32 | + }), |
| 33 | + ], |
| 34 | + }; |
| 35 | + } |
| 36 | + |
| 37 | + return [ |
| 38 | + // Browser ESM bundle |
| 39 | + { |
| 40 | + entry: ['src/index.ts'], |
| 41 | + outDir: 'dist/browser', |
| 42 | + platform: 'browser', |
| 43 | + format: 'esm', |
| 44 | + target: 'es2022', |
| 45 | + minify: true, |
| 46 | + bundle: true, |
| 47 | + noExternal: [IMTBL_WORKSPACE, '@uniswap/swap-router-contracts'], |
| 48 | + treeshake: true, |
| 49 | + esbuildPlugins: [ |
| 50 | + nodeModulesPolyfillPlugin({ |
| 51 | + globals: { Buffer: true, process: true }, |
| 52 | + modules: ['crypto', 'buffer', 'process'], |
| 53 | + }), |
| 54 | + replace({ __SDK_VERSION__: pkg.version }), |
| 55 | + ], |
| 56 | + }, |
| 57 | + |
| 58 | + // Node CJS + ESM bundle |
| 59 | + { |
| 60 | + entry: ['src/index.ts'], |
| 61 | + outDir: 'dist/node', |
| 62 | + platform: 'node', |
| 63 | + format: ['esm', 'cjs'], |
| 64 | + target: 'es2022', |
| 65 | + minify: true, |
| 66 | + bundle: true, |
| 67 | + noExternal: [IMTBL_WORKSPACE, '@uniswap/swap-router-contracts'], |
| 68 | + treeshake: true, |
| 69 | + esbuildPlugins: [ |
| 70 | + replace({ __SDK_VERSION__: pkg.version }), |
| 71 | + ], |
| 72 | + }, |
| 73 | + ]; |
| 74 | +}); |
0 commit comments