> For the complete documentation index, see [llms.txt](https://docs.sealights.io/knowledgebase/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/browser-agent/framework-setups/esbuild.md).

# esbuild

> **Applies to:** applications bundled directly with esbuild (CLI or JavaScript API). Angular 17+ uses esbuild internally; see [Angular](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/browser-agent/framework-setups/angular.md).

## Step 1: Bundle with source maps <a href="#source-maps" id="source-maps"></a>

{% tabs %}
{% tab title="CLI" %}

```bash
npx esbuild src/index.tsx --bundle --minify --sourcemap \
  --format=esm --splitting --outdir=dist
```

{% endtab %}

{% tab title="JavaScript API" %}

```js
// 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',
});
```

{% endtab %}
{% endtabs %}

| 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 <a href="#scan" id="scan"></a>

```bash
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 <a href="#notes" id="notes"></a>

| 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](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/browser-agent/framework-setups.md#common)). |
| Watch / serve mode                           | Not supported for scanning: scan the output of a one-off production build.                                                                                                                                                                                                                  |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/browser-agent/framework-setups/esbuild.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
