Bundler plugins
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.
- Vite
- webpack
- Rollup
- esbuild
- Rspack
npm install --save-dev @bugsee/vite-plugin
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.
npm install --save-dev @bugsee/webpack-plugin
const { bugseeWebpackPlugin } = require('@bugsee/webpack-plugin');
module.exports = {
devtool: 'source-map',
plugins: [bugseeWebpackPlugin()],
};
With ES modules, use import { bugseeWebpackPlugin } from '@bugsee/webpack-plugin';. Next.js has its own integration, withBugsee. See Next.js.
The Rollup, esbuild and Rspack plugins have no package of their own. Install @bugsee/bundler-plugin-core and import them from it. They are less exercised than the Vite and webpack plugins.
npm install --save-dev @bugsee/bundler-plugin-core
import { bugseeRollupPlugin } from '@bugsee/bundler-plugin-core';
export default {
input: 'src/index.js',
output: { dir: 'dist', sourcemap: true },
plugins: [bugseeRollupPlugin()],
};
The plugin stamps inside the build, in generateBundle, and uploads at writeBundle.
npm install --save-dev @bugsee/bundler-plugin-core
import { build } from 'esbuild';
import { bugseeEsbuildPlugin } from '@bugsee/bundler-plugin-core';
await build({
entryPoints: ['src/index.ts'],
bundle: true,
outdir: 'dist',
sourcemap: 'external',
plugins: [bugseeEsbuildPlugin()],
});
The plugin runs when the build ends and hands the CLI the files that this build wrote. See esbuild notes.
npm install --save-dev @bugsee/bundler-plugin-core
const { bugseeRspackPlugin } = require('@bugsee/bundler-plugin-core');
module.exports = {
devtool: 'source-map',
plugins: [bugseeRspackPlugin()],
};
Rspack emits no source maps by default in production (devtool: false), so the plugin finds nothing to upload and says so. Set devtool.
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.
| Bundler | When the stamp runs |
|---|---|
| Vite, Rollup | In generateBundle, before other plugins (order: 'pre'). |
| webpack 5, Rspack | In processAssets, just after the development-tooling stage. |
| esbuild, and the CLI on its own | After 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.
| Option | Type | Default | Description |
|---|---|---|---|
appToken | string | BUGSEE_APP_TOKEN | Your app token. Without one, the plugin does nothing. |
appVersion | string | BUGSEE_APP_VERSION, then the version of the nearest package.json, else 0.0.0 | The version recorded with the upload. A real value is also baked into the bundle for the SDK. |
appBuild | string | BUGSEE_APP_BUILD, then the commit id of your CI, else 0 | The build recorded with the upload. A real value is also baked into the bundle for the SDK. |
endpoint | string | BUGSEE_ENDPOINT, else https://api.bugsee.com | The API endpoint. |
deleteMaps | boolean | true | Delete the .map files from the output after a successful upload. |
stripSourcesContent | boolean | false | Upload 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. |
dryRun | boolean | false | Run the CLI in dry-run mode: nothing is uploaded or deleted, and the notices say what was captured. |
disabled | boolean | false | Turn the plugin off, for example in development builds. |
failOnError | boolean | false | Fail the build when the upload fails. By default a failed upload only warns, so a telemetry problem never breaks a deploy. |
registerBuild | 'release' | 'always' | false | BUGSEE_REGISTER_BUILD, else 'release' | Which builds are registered with Bugsee. See Build registration. |
packageId | string | the name of the nearest package.json, scope included | The package id of the registered build. |
vcs | boolean | true | Capture the commit, branch and repository of the build. false records nothing, even an explicit commit. |
commit | string | BUGSEE_BUILD_COMMIT, else detected | The commit SHA of the build, 7 to 64 hexadecimal characters. An explicit value skips the dirty-tree check. |
allowDirtyCommit | boolean | false | Record the commit even when tracked files have uncommitted changes. |
projectRoot | string | the working directory | The repository root that commit detection inspects. It does not change where the version is read from. |
uploadInDevelopment | boolean | false | esbuild and Rspack only. Upload from builds the bundler calls development. |
onError | (error) => void | a console warning | Receives a failure that was contained. |
onNotice | (message) => void | console.warn | Receives 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.
registerBuild | Registers |
|---|---|
'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. |
false | No 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
disabledfor 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 setuploadInDevelopment: true. esbuild states no mode, so onlyNODE_ENV=developmentmarks 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.mapand.d.ts.mapfiles that this build wrote have no debug ID and are deleted with them once something was uploaded. SetdeleteMaps: falseto 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. Withsourcemap: falsethere 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. WithfailOnError, 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
withBugseefrom@bugsee/nextjs/config, which handles both webpack and Turbopack. See Next.js. - Bun's bundler,
tscandswc. They have no hook. Use the CLI recipe.
Related pages
- Symbolication overview — how debug IDs work
- Manual upload with the CLI — tsup,
tsc, Bun and Angular - Environment and variables — tokens, versions and the
.env.bugsee-build-pluginfile - Source map doctor — check a build folder offline
- Source maps (CLI) — the commands that the plugins run