:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { build } from 'esbuild'
import { readFileSync, writeFileSync, mkdirSync } from 'fs'
import { resolve, dirname } from 'path'
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url))
const result = await build({
entryPoints: [resolve(__dirname, 'src/standalone-player.ts')],
bundle: true,
write: false,
format: 'iife',
platform: 'browser',
target: 'es2020',
minify: true,
sourcemap: false,
metafile: true,
define: {
'process.env.NODE_ENV': '"production"',
'process.env.LANG': '""',
'process.env': '{}',
},
})
const js = result.outputFiles[0].text
const html = readFileSync(resolve(__dirname, 'src/index.html'), 'utf-8')
// The `__CSP_NONCE__` placeholder is swapped for a per-request nonce (or stripped) by the
// rasterizer's CSP handling — see servePlayer in nodejs recording-rasterizer/request-interceptor.ts.
// Use a replacer function to avoid $ replacement patterns in the JS being interpreted.
const outputHtml = html.replace('<!-- INLINE_JS -->', () => `<script nonce="__CSP_NONCE__">${js}</script>`)
mkdirSync(resolve(__dirname, 'dist'), { recursive: true })
writeFileSync(resolve(__dirname, 'dist/player.html'), outputHtml)
// Build protocol module as CJS for nodejs consumers (e.g. recording-rasterizer)
await build({
entryPoints: [resolve(__dirname, 'src/protocol.ts')],
bundle: false,
outfile: resolve(__dirname, 'dist/protocol.js'),
format: 'cjs',
platform: 'node',
target: 'es2020',
})