Skip to content

Latest commit

 

History

History

webpack

Honeybadger's Webpack Source Map Plugin

Node CI npm version npm dm npm dt

Webpack plugin to upload JavaScript source maps to Honeybadger. You can also send deployment notifications.

Word Up! to the thredUP development team for a similar webpack plugin they have authored.

Installation

# npm
npm install @honeybadger-io/webpack --save-dev

# yarn
yarn add @honeybadger-io/webpack --dev

Configuration

Plugin parameters

These plugin parameters correspond to the Honeybadger Source Map Upload API and Deployments API.

apiKey (required)
The API key of your Honeybadger project
assetsUrl (required)
The base URL to production assets (scheme://host/path)*wildcards are supported. The plugin combines assetsUrl with the generated minified js file name to build the API parameter minified_url
endpoint (optional — default: "https://api.honeybadger.io/v1/source_maps")
Where to upload your source maps to. Perhaps you have a self hosted source map server you would like to upload your source maps to instead of honeybadger. If you are using our EU stack, this should be set to "https://eu-api.honeybadger.io/v1/source_maps".
revision (optional — default: "main")
The deploy revision (i.e. commit hash) that your source map applies to. This could also be a code version. For best results, set it to something unique every time your code changes. See the Honeybadger docs for examples.
silent (optional — default: "null/false")
If true, silence log information emitted by the plugin.
ignoreErrors (optional — default: false)
If true, webpack compilation errors are treated as warnings.
retries (optional — default: 3, max: 10)
This package implements fetch retry functionality via https://github.com/vercel/fetch-retry
Retrying helps fix issues like `ECONNRESET` and `SOCKETTIMEOUT` errors and retries on 429 and 500 errors as well.
workerCount (optional — default: 5, min: 1)
Source maps are uploaded in parallel by a configurable number of workers. Increase or decrease this value to configure how many source maps are being uploaded in parallel.
Limited parallelism helps with connection issues in Docker environments.
deployEndpoint (optional — default: "https://api.honeybadger.io/v1/deploys")
Where to send deployment notifications. If you are using our EU stack, this should be set to "https://eu-api.honeybadger.io/v1/deploys".
deploy (optional — default: false)
Configuration for deployment notifications. To disable deployment notifications, ignore this option. To enable deployment notifications, set this to true, or to an object containing any of these fields (see the API reference):
environment
The environment name, for example, "production"
repository
The base URL of the VCS repository (HTTPS-style), for example, "https://github.com/yourusername/yourrepo"
localUsername
The name of the user that triggered this deploy, for example, "Jane"
developmentEnvironments (optional — default: ["dev", "development", "test"])
Source maps upload will be skipped when the environment matches any of the values in this array or the webpack dev server is running.

Vanilla webpack.config.js

const HoneybadgerSourceMapPlugin = require('@honeybadger-io/webpack')
const ASSETS_URL = 'https://cdn.example.com/assets';
const webpackConfig = {
  plugins: [new HoneybadgerSourceMapPlugin({
    apiKey: 'abc123',
    assetsUrl: ASSETS_URL,
    revision: 'main',
    // You can also enable deployment notifications:
    deploy: {
       environment: process.env.NODE_ENV,
       repository: "https://github.com/yourusername/yourrepo"
    }
  })]
}

Rails Webpacker config/webpack/environment.js

const { environment } = require('@rails/webpacker')
const HoneybadgerSourceMapPlugin = require('@honeybadger-io/webpack')

// Assumes Heroku / 12-factor application style ENV variables
// named GIT_COMMIT, HONEYBADGER_API_KEY, ASSETS_URL
const revision = process.env.GIT_COMMIT || 'main'

environment.plugins.append(
  'HoneybadgerSourceMap',
  new HoneybadgerSourceMapPlugin({
    apiKey: process.env.HONEYBADGER_API_KEY,
    assetsUrl: process.env.ASSETS_URL,
    silent: false,
    ignoreErrors: false,
    revision: revision
  }))

module.exports = environment

Development

  1. Run npm install
  2. Run the tests with npm test
  3. Build/test on save with npm run build:watch and npm run test:watch

See the /example folder for a project to test against.

License

This package is MIT licensed. See the MIT-LICENSE file in this folder for details.