For the complete documentation index, see llms.txt. This page is also available as Markdown.

esbuild

Applies to: applications bundled directly with esbuild (CLI or JavaScript API). Angular 17+ uses esbuild internally; see Angular.

Step 1: Bundle with source maps

npx esbuild src/index.tsx --bundle --minify --sourcemap \
  --format=esm --splitting --outdir=dist
// build.mjs
import * as esbuild from 'esbuild';

await esbuild.build({
  entryPoints: ['src/index.tsx'],
  bundle: true,
  minify: true,
  sourcemap: true,      // 'linked' (default for true) or 'external'
  format: 'esm',
  splitting: true,
  outdir: 'dist',
});
esbuild option
Effect on the scan

sourcemap: true / 'linked'

.map file plus sourceMappingURL comment. Works.

sourcemap: 'external'

.map file without the comment. Works: the map is found next to the bundle.

sourcemap: 'inline'

Works, but the map stays in the deployed bundle.

format: 'esm' (required for splitting)

Add --es6Modules to the scan.

format: 'iife' (the default for browser bundles)

Do not add --es6Modules.

outExtension: { '.js': '.cjs' }

Not scanned by default; set SL_fileExtensions=.js,.cjs.

Step 2: Scan and instrument

printf '%s' "$SEALIGHTS_AGENT_TOKEN" > sltoken.txt
npx slnodejs config --tokenFile sltoken.txt --appName my-web-app \
  --branchName "$BRANCH_NAME" --buildName "$BUILD_NUMBER"
npx slnodejs scan --tokenFile sltoken.txt --buildSessionIdFile buildSessionId \
  --scanDir dist --scmType git --es6Modules \
  --instrumentForBrowsers --outputPath sl_dist \
  --labId qa-env --excludeSourceMapFiles skipCopy

Copy your static files (index.html, assets) next to the bundles before the scan, or into sl_dist after it, so the deployed folder is complete. Deploy sl_dist.

esbuild-specific notes

Topic
What to do

Source paths in maps start with ../src/...

Expected; they resolve relative to dist. Run dryRun and check that sl-mapping.json points to files in your repository.

Third-party code inside the bundle

Framework packages are skipped by default; add others in .slignore.instrument (it replaces the built-in list; see Framework and Bundler Setups).

Watch / serve mode

Not supported for scanning: scan the output of a one-off production build.

Last updated

Was this helpful?