Skip to main content

Bundler plugins

Beta

This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas.

A bundler plugin does the whole symbolication job at the end of the build: it stamps the bundles and maps with a debug ID, uploads the maps, and deletes the local .map files so they are not deployed. The plugins run the Bugsee CLI, which is installed with them. See Source maps for what the CLI does.

Without an app token, a plugin does nothing, so local builds are unaffected.

Set up​

Turn on source maps in your bundler, add the plugin and give it your app token. The plugin reads BUGSEE_APP_TOKEN from the environment itself, and fills a blank variable from .env.bugsee-build-plugin, so the examples pass no appToken. Passing appToken: process.env.BUGSEE_APP_TOKEN explicitly would override that file value with a blank one and disable the plugin.

npm install --save-dev @bugsee/vite-plugin
vite.config.ts
import { defineConfig } from 'vite';
import { bugseeVitePlugin } from '@bugsee/vite-plugin';

export default defineConfig({
build: { sourcemap: true },
plugins: [bugseeVitePlugin()],
});

Use this plugin for frameworks that build on Vite as well.

Where the stamp happens​

Where the bundler has a hook that runs before it writes files, the plugin stamps the debug IDs inside the build. That way any Subresource Integrity (SRI) hash taken later describes the stamped bytes, and a page that pins hashes keeps loading while its maps are uploaded.

BundlerWhen the stamp runs
Vite, RollupIn generateBundle, before other plugins (order: 'pre').
webpack 5, RspackIn processAssets, just after the development-tooling stage.
esbuild, and the CLI on its ownAfter the files are written.

List the Bugsee plugin before any SRI plugin, so the hashes are taken after the stamp.

If an in-build stamp fails or is not possible (an older Rollup, or sourcemap: 'inline'), the plugin falls back to stamping after the files are written, where the SRI refusal still applies. With failOnError, a failed in-build stamp fails the build instead.

Every stamp is verified: each bundle still parses, its sourceMappingURL comment is intact, the bytes are the original plus the appended stamp, and the map carries the bundle's debug ID. A bundle that fails the check keeps or gets its original bytes back, and the failure is reported. An in-build stamp is checked again on disk and against the integrity pins in your pages.

To check a finished build folder yourself, without a network, run the source map doctor.

Options​

All options are optional. A token is needed to upload, and it may come from the environment. See Environment and variables for the lookup order and the .env.bugsee-build-plugin file.

OptionTypeDefaultDescription
appTokenstringBUGSEE_APP_TOKENYour app token. Without one, the plugin does nothing.
appVersionstringBUGSEE_APP_VERSION, then the version of the nearest package.json, else 0.0.0The version recorded with the upload. A real value is also baked into the bundle for the SDK.
appBuildstringBUGSEE_APP_BUILD, then the commit id of your CI, else 0The build recorded with the upload. A real value is also baked into the bundle for the SDK.
endpointstringBUGSEE_ENDPOINT, else https://api.bugsee.comThe API endpoint.
deleteMapsbooleantrueDelete the .map files from the output after a successful upload.
stripSourcesContentbooleanfalseUpload the maps without the embedded source code. Positions still resolve, but reports show no source lines. The maps on disk are not changed. Stripping can fail open: a map the CLI cannot process is uploaded unstripped with a warning. For a strict no-source policy, strip and verify the maps before upload.
dryRunbooleanfalseRun the CLI in dry-run mode: nothing is uploaded or deleted, and the notices say what was captured.
disabledbooleanfalseTurn the plugin off, for example in development builds.
failOnErrorbooleanfalseFail the build when the upload fails. By default a failed upload only warns, so a telemetry problem never breaks a deploy.
registerBuild'release' | 'always' | falseBUGSEE_REGISTER_BUILD, else 'release'Which builds are registered with Bugsee. See Build registration.
packageIdstringthe name of the nearest package.json, scope includedThe package id of the registered build.
vcsbooleantrueCapture the commit, branch and repository of the build. false records nothing, even an explicit commit.
commitstringBUGSEE_BUILD_COMMIT, else detectedThe commit SHA of the build, 7 to 64 hexadecimal characters. An explicit value skips the dirty-tree check.
allowDirtyCommitbooleanfalseRecord the commit even when tracked files have uncommitted changes.
projectRootstringthe working directoryThe repository root that commit detection inspects. It does not change where the version is read from.
uploadInDevelopmentbooleanfalseesbuild and Rspack only. Upload from builds the bundler calls development.
onError(error) => voida console warningReceives a failure that was contained.
onNotice(message) => voidconsole.warnReceives notices about configuration, such as a skipped upload or a dropped commit. Notices are strings, not errors.

The version and build are also baked into your bundle as __BUGSEE_APP_VERSION__ and __BUGSEE_APP_BUILD__, so the SDK reports the same release without you passing appVersion to launch(). This happens even without a token. disabled: true turns it off. See Environment and variables.

Build registration​

At the end of a production build, the plugin also registers the build with Bugsee. Registration records the build only. No files are uploaded with it.

registerBuildRegisters
'release'A build that the bundler calls production: the resolved production flag in Vite, mode: 'production' or an unset mode in webpack, otherwise NODE_ENV=production.
'always'Every build.
falseNo build.

A failed registration never fails the build unless failOnError is set. Registration happens once for each output folder, so a build that writes two folders registers two builds.

Commit information​

With vcs on, the plugin asks the CLI for the commit SHA, branch and repository of the build, reading your CI environment and falling back to git. It never fails a build: with no git, no repository or no commits, nothing is recorded.

If tracked files have uncommitted changes, the SHA no longer describes what was built, so it is dropped and the reason is printed. The check runs after the build wrote its output and covers the whole repository. A repository that commits generated files, or has an unrelated dirty package in a monorepo, can look dirty on every build. Pass allowDirtyCommit: true, or commit the generated files before building.

For a build made from an artifact, with no working tree, pass commit or set BUGSEE_BUILD_COMMIT.

Behavior to know​

  • Development builds. The Vite, webpack and Rollup plugins upload every build they run. Set disabled for builds you do not want uploaded. The esbuild and Rspack plugins skip builds that the bundler calls development, and leave the local maps alone, unless you set uploadInDevelopment: true. esbuild states no mode, so only NODE_ENV=development marks a development build there.
  • Subresource Integrity. The stamp rewrites each bundle, which would invalidate script hashes in your HTML. When the stamp happens inside the build (Vite, Rollup, webpack and Rspack), the hashes are taken afterwards and describe the stamped bytes. The plugin still checks for hashes that no longer match and warns. When it runs after the output is written, it refuses to stamp a build whose HTML pins a hash of a script. The page stays as the bundler emitted it, and the maps are not uploaded.
  • Source maps are deleted only after a confirmed upload of that map, and only when it carries a debug ID. This is why the browser no longer finds them. The .css.map and .d.ts.map files that this build wrote have no debug ID and are deleted with them once something was uploaded. Set deleteMaps: false to keep them. A dry run deletes nothing.
  • Watch mode. The plugins keep no state between rebuilds, and builds that share an output folder do not wait for each other.

esbuild notes​

  • If you did not set sourcemap, the plugin sets it to 'external'. An explicit value is kept. With sourcemap: false there is nothing to upload, and the plugin says so.
  • The plugin asks esbuild for its metafile and uploads only the bundles and maps of this build. It never walks the output folder, so it never deletes a file it did not upload.
  • It works with any tool that takes esbuild plugins and lets esbuild write the files. tsup is not covered: tsup tells esbuild not to write, and writes the files itself afterwards, so nothing is on disk when the plugin runs. Use the CLI recipe instead.
  • A build with sourcemap: 'inline' has no map files. With failOnError, it fails. Otherwise the plugin only says so.

What the plugins do not cover​

  • Angular. Its builder does not accept esbuild plugins. Use ng add @bugsee/angular, which uploads the maps for you. See Angular.
  • Next.js. Use withBugsee from @bugsee/nextjs/config, which handles both webpack and Turbopack. See Next.js.
  • Bun's bundler, tsc and swc. They have no hook. Use the CLI recipe.
Found an issue, typo, or wrong statement on this page? Report it now →