|
| 1 | +// @ts-check |
| 2 | +// Local tsup config for @imtbl/audience. |
| 3 | +// |
| 4 | +// Overrides the monorepo's root tsup config by setting `noExternal` to the |
| 5 | +// explicit list of `@imtbl/*` workspace deps that should be inlined into the |
| 6 | +// built bundle. The same list is used by scripts/prepack.mjs to strip those |
| 7 | +// deps from the published package.json. Keeping the two in sync via a shared |
| 8 | +// module prevents the "tsup silently bundles a new dep but prepack leaves |
| 9 | +// workspace:* in package.json" class of bugs. |
| 10 | +import { defineConfig } from 'tsup'; |
| 11 | +import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill'; |
| 12 | +import { replace } from 'esbuild-plugin-replace'; |
| 13 | +import pkg from './package.json' with { type: 'json' }; |
| 14 | +import { BUNDLED_WORKSPACE_DEPS } from './scripts/bundled-workspace-deps.mjs'; |
| 15 | + |
| 16 | +export default defineConfig((options) => { |
| 17 | + if (options.watch) { |
| 18 | + return { |
| 19 | + entry: ['src/index.ts'], |
| 20 | + outDir: 'dist/browser', |
| 21 | + format: 'esm', |
| 22 | + target: 'es2022', |
| 23 | + platform: 'browser', |
| 24 | + bundle: true, |
| 25 | + noExternal: BUNDLED_WORKSPACE_DEPS, |
| 26 | + esbuildPlugins: [ |
| 27 | + nodeModulesPolyfillPlugin({ |
| 28 | + globals: { Buffer: true, process: true }, |
| 29 | + modules: ['crypto', 'buffer', 'process'], |
| 30 | + }), |
| 31 | + replace({ |
| 32 | + __SDK_VERSION__: pkg.version === '0.0.0' ? '2.0.0' : pkg.version, |
| 33 | + }), |
| 34 | + ], |
| 35 | + }; |
| 36 | + } |
| 37 | + |
| 38 | + return [ |
| 39 | + // Browser ESM bundle |
| 40 | + { |
| 41 | + entry: ['src/index.ts'], |
| 42 | + outDir: 'dist/browser', |
| 43 | + platform: 'browser', |
| 44 | + format: 'esm', |
| 45 | + target: 'es2022', |
| 46 | + minify: true, |
| 47 | + bundle: true, |
| 48 | + noExternal: BUNDLED_WORKSPACE_DEPS, |
| 49 | + treeshake: true, |
| 50 | + esbuildPlugins: [ |
| 51 | + nodeModulesPolyfillPlugin({ |
| 52 | + globals: { Buffer: true, process: true }, |
| 53 | + modules: ['crypto', 'buffer', 'process'], |
| 54 | + }), |
| 55 | + replace({ __SDK_VERSION__: pkg.version }), |
| 56 | + ], |
| 57 | + }, |
| 58 | + |
| 59 | + // Node CJS + ESM bundle |
| 60 | + { |
| 61 | + entry: ['src/index.ts'], |
| 62 | + outDir: 'dist/node', |
| 63 | + platform: 'node', |
| 64 | + format: ['esm', 'cjs'], |
| 65 | + target: 'es2022', |
| 66 | + minify: true, |
| 67 | + bundle: true, |
| 68 | + noExternal: BUNDLED_WORKSPACE_DEPS, |
| 69 | + treeshake: true, |
| 70 | + esbuildPlugins: [ |
| 71 | + replace({ __SDK_VERSION__: pkg.version }), |
| 72 | + ], |
| 73 | + }, |
| 74 | + ]; |
| 75 | +}); |
0 commit comments