npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@plrthink/webpack-sentry-plugin

v1.9.2

Published

Webpack plugin to upload source maps to Sentry

Downloads

4

Readme

Sentry plugin

Build Status

A webpack (v1 or 2) plugin to upload source maps to Sentry.

Installation

Using npm:

$ npm install webpack-sentry-plugin --save-dev

Using yarn:

$ yarn add webpack-sentry-plugin --dev

Usage

  1. Require webpack-sentry-plugin:

    var SentryPlugin = require('webpack-sentry-plugin');
  2. Configure webpack to output source maps. Recommended reading: webpack docs, Sentry docs

  3. Add to webpack config:

    var config = {
      plugins: [
        new SentryPlugin({
          // Sentry options are required
          organisation: 'your-organisation-name',
          project: 'your-project-name',
          apiKey: process.env.SENTRY_API_KEY,
             
          // Release version name/hash is required
          release: function() {
            return process.env.GIT_SHA
          }
        })
      ]
    }

Options

  • organisation: Required, Sentry organisation to upload files to

  • project: Required, Sentry project to upload files to

  • apiKey: Required, Sentry api key (Generate one here, ensure that project:write, project:read and project:releases are selected ,under scopes)

  • release: Required, string or function that returns the release name. See What is a release? below for details

  • exclude: RegExp to match for excluded files

    var config = {
      plugins: [
        new SentryPlugin({
          // Exclude uploading of html
          exclude: /\.html$/,
          ...
        })
      ]
    }
  • include: RegExp to match for included files

    var config = {
      plugins: [
        new SentryPlugin({
          // Only upload foo.js & foo.js.map
          include: /foo.js/,
          ...
        })
      ]
    }
  • filenameTransform: Function to transform filename before uploading to Sentry. Defaults to prefixing filename with ~/, which is used by Sentry as a host wildcard

    var config = {
      plugins: [
        new SentryPlugin({
          filenameTransform: function(filename) {
            return 'a-filename-prefix-' + filename
          }
        })
      ]
    }
  • suppressErrors: Display warnings instead of failing webpack build - useful in case webpack compilation is done during deploy on multiple instances

  • baseSentryURL: URL of Sentry instance. Shouldn't need to set if using sentry.io, but useful if self hosting

  • deleteAfterCompile: Boolean determining whether source maps should be deleted after the webpack compile finishes. Defaults to false

What is a release?

A release is a concept that Sentry uses to attach source maps to a known version of your code. The plugin creates one for you, but you need to provide a "name" for a particular version of your code, which is just a string. Sentry can then use the release to say that a it found an error in this known version of your code.

Passing the string to the plugin really depends on your setup. There are three main approaches:

A git commit hash is very useful for releases - it is a string that defines a particular version of your code. For example, deploying to Heroku with a git hook, you can access a SOURCE_VERSION environment variable that is the latest commit's hash. CircleCI provides the git hash in a CIRCLE_SHA1 environment variable. Travis provides TRAVIS_COMMIT. To supply it to the plugin you can configure the release option to be a function that returns the hash:

new SentryPlugin({
  // ...
  release: function() {
    // Note: this is just an example, it depends on your deployment pipeline 
    return process.env.SOURCE_VERSION;
  }
});

Alternatively you can use the webpack build hash. This is generated by webpack and is based on the contents of the build - so if you change the code, the hash also changes. This also is useful for Sentry releases as it identifies a particular version of your code. The plugin provides the webpack hash to you as the first argument to the release function:

new SentryPlugin({
  // ...
  release: function(hash) {
    return hash; // webpack build hash
  }
});

The final option is to manually provide a string to the release option:

new Sentry Plugin({
  // ...
  release: 'foo-release'
});

Keep in mind that this string will need to change when you update your code. The other options above are recommended.

Post deployment

After you deploy you need to tell the Sentry client (Raven) which release is the current release. There is an option called release that you pass when configuring it:

Raven.config({
    release: 'YOUR-RELEASE-STRING-HERE'
});

Thanks

Contributing

Contributions are welcome 😄. To run the tests, please ensure you have the relevant environment variables set up. You can cp .env.example .env and fill it in with test account credentials. An API key can be created here, assuming you are signed in.

Commands to be aware of

Warning ⚠️: The test suite will create releases & upload files. They should be cleaned up afterward, but ensure that you are not overwriting something important!

  • npm start: List available commands (in green at bottom)
  • npm test: Runs the test suite
  • npm start lint: Runs linting
  • npm start format: Formats code with prettier-eslint