Report builds and upload source maps to BugSnag using Vite
Use our Vite plugins to:
Install the vite-plugin-bugsnag
module.
npm install --save-dev @bugsnag/vite-plugin-bugsnag
BugsnagBuildReporterPlugin
reports your application’s build to BugSnag.
This plugin hooks into the buildEnd
hook once bundles have been generated by the Vite compiler. If anything causes the compilation to fail before this step, the build report will not get sent.
Here’s an example:
/* vite.config.js */
import { BugsnagBuildReporterPlugin } from "@bugsnag/vite-plugin-bugsnag";
export default defineConfig({
base: "https://example.com/",
build: {
sourcemap: true,
},
plugins: [
BugsnagBuildReporterPlugin({
apiKey: "YOUR_API_KEY",
appVersion: "1.2.3",
metadata: {
buildServer: "build1",
buildReason: "Releasing JIRA-1234"
}
})
]
});
The appVersion
must match the app version in your notifier configuration.
See the configuration section for detailed instructions on how to configure build reporting in your application.
BugsnagSourceMapUploaderPlugin
uploads your application’s sourcemaps to BugSnag. When Vite is done producing output, this plugin detects source maps for any output chunks and uploads them to BugSnag.
Here’s an example:
/* vite.config.js */
import { BugsnagSourceMapUploaderPlugin } from "@bugsnag/vite-plugin-bugsnag";
export default defineConfig({
base: "https://example.com/",
build: {
sourcemap: true,
},
plugins: [
BugsnagSourceMapUploaderPlugin({
apiKey: "YOUR_API_KEY",
appVersion: "1.2.3"
})
]
});
The appVersion
must match the app version in your notifier configuration.
The default behavior is to reject uploads if a source map has already been uploaded for the same path and app version. In this case HTTP status 409 received from upload API
will be shown in the plugin output. Set the overwrite
option to true
to allow new uploads to replace existing uploads. This means that events subsequently received from the previous build may not be mapped correctly.
See the configuration section for detailed instructions on how to configure source map uploading in your application.
const { BugsnagBuildReporterPlugin } = require('@bugsnag/vite-plugin-bugsnag')
const plugin = BugsnagBuildReporterPlugin(options)
options
An object describing the build payload to be reported to BugSnag.
Property | Type | Description |
---|---|---|
apiKey |
string |
your BugSnag API key [required] |
appVersion |
string |
the version of the application you are building [required] (this should match the appVersion configured in your notifier) |
autoAssignRelease |
boolean |
automatically associate this build with any new error events and sessions that are received for the releaseStage until a subsequent build notification is received. If this is set to true and no releaseStage is provided the build will be applied to 'production' . You should only use this option if you aren’t able to set an appVersion in your notifier. |
builderName |
string |
the name of the person/machine that created this build (defaults to the result of the whoami command) |
metadata |
object |
key-value pairs containing any custom information about the build (e.g. configuration parameters, dependency versions, etc). The keys and values must be strings. Nested objects aren’t supported. |
releaseStage |
string |
'production' , 'staging' , etc. (Leave blank if this build applies to multiple releaseStage s. New releases will be created when events are received with their respective releaseStage ) |
sourceControl |
object |
an object describing the source control of the build (if not specified, the module will attempt to detect source control information from .git , .hg and the nearest package.json ) |
sourceControl.provider |
string |
can be one of: 'github' , 'github-enterprise' , 'gitlab' , 'gitlab-onpremise' , 'bitbucket' , 'bitbucket-server' |
sourceControl.repository |
string |
a URL (git /ssh /https ) pointing to the repository, or webpage representing the repository |
sourceControl.revision |
string |
the unique identifier for the commit (e.g. git SHA) |
endpoint |
string |
Defaults to https://build.bugsnag.com . If you are using BugSnag On-premise use your BugSnag Build API endpoint |
logLevel |
string |
Sets the level of logging to debug , info , warn or error |
logger |
object |
provide a different logger object { debug, info, warn, error } |
path |
string |
the path to search for source control info, defaults to process.cwd() |
const { BugsnagSourceMapUploaderPlugin } = require('@bugsnag/vite-plugin-bugsnag')
const plugin = BugsnagSourceMapUploaderPlugin(options)
options
Provide options to the source map uploader.
Property | Type | Description |
---|---|---|
apiKey |
string |
Your BugSnag API key [required] |
appVersion |
string |
The version of the application you are building (this should match the appVersion configured in your notifier). Defaults to the version set in your project’s package.json file, if one is specified there. |
base |
string |
The URL of the base directory for the minified JavaScript files that the source maps relate to. The relative path is appended onto this for each file. Defaults to base from your Vite configuration. |
codeBundeId |
string |
A unique identifier for the JavaScript bundle. |
mode |
string |
Defaults to development for serve, production for build |
projectRoot |
string |
The path to your bundled assets as it appears in a stack trace. For an app running in a browser this is typically a URL. Defaults to root from your Vite configuration. |
overwrite |
boolean |
Whether you want to overwrite previously uploaded source maps for the same path and appVersion . Defaults to false . |
endpoint |
string |
Defaults to https://upload.bugsnag.com/sourcemap . If you are using BugSnag On-premise use your BugSnag Upload API endpoint |
logLevel |
string |
Sets the level of logging to debug , info , warn or error |
logger |
object |
provide a different logger object { debug, info, warn, error } |
path |
string |
the path to search for source control info, defaults to process.cwd() |
For more information relating to source maps, see source map support and source map upload FAQs.