@@ -3,32 +3,8 @@ import { defineConfig } from 'tsup';
33import { replace } from 'esbuild-plugin-replace' ;
44import pkg from './package.json' with { type : 'json' } ;
55
6- /**
7- * CDN bundle config for @imtbl/audience.
8- *
9- * Produces a single-file IIFE at dist/cdn/imtbl-audience.global.js that
10- * studios load via <script>. Bundles audience-core directly (no runtime
11- * dependency resolution), attaches globals via the src/cdn.ts side-effect
12- * entry point, and minifies for size.
13- *
14- * Runs alongside the main ESM build configured in tsup.config.js — they
15- * share the dist/ directory so `clean: false` is required to avoid wiping
16- * the ESM output. The package.json build script runs transpile (ESM/CJS)
17- * first, then transpile:cdn, then typegen, so the order-dependent dist/
18- * state is well-defined.
19- *
20- * The esbuild replace plugin substitutes '__SDK_VERSION__' with the
21- * actual package version at build time. Both @imtbl/audience and
22- * @imtbl /audience-core use '__SDK_VERSION__' as a placeholder in their
23- * source (config.ts / context.ts) so the real version gets stamped
24- * into context.libraryVersion on every message. Without this replacement
25- * the CDN bundle ships the literal placeholder and the backend 400s.
26- *
27- * Local dev builds have pkg.version === '0.0.0' because the real version
28- * is only written by `pnpm nx release version` in the publish workflow.
29- * We substitute '0.0.0-local' in that case so a hand-carried local build
30- * shows up as obviously non-production in context.libraryVersion logs.
31- */
6+ // IIFE bundle of @imtbl /audience for <script>-tag loading. Runs after the
7+ // ESM/CJS build in tsup.config.js — `clean: false` preserves that output.
328export default defineConfig ( {
339 entry : { 'imtbl-audience' : 'src/cdn.ts' } ,
3410 format : [ 'iife' ] ,
@@ -40,14 +16,9 @@ export default defineConfig({
4016 target : 'es2018' ,
4117 platform : 'browser' ,
4218 dts : false ,
43- // IIFE has no runtime module resolution, so every dep (including third-party
44- // npm deps) must be inlined. Can't reuse BUNDLED_WORKSPACE_DEPS from the sibling
45- // tsup.config.js — that list is workspace-only and would leave third-party deps
46- // as externals, breaking the <script>-tag use case.
19+ // IIFE has no runtime module resolution — inline everything, including npm deps.
4720 noExternal : [ / .* / ] ,
4821 esbuildPlugins : [
49- replace ( {
50- __SDK_VERSION__ : pkg . version === '0.0.0' ? '0.0.0-local' : pkg . version ,
51- } ) ,
22+ replace ( { __SDK_VERSION__ : pkg . version === '0.0.0' ? '0.0.0-local' : pkg . version } ) ,
5223 ] ,
5324} ) ;
0 commit comments