Skip to content

Instantly share code, notes, and snippets.

@foxyblocks
Last active August 1, 2016 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxyblocks/d0186f9a8d58ebef071ba2f2ab14ea6f to your computer and use it in GitHub Desktop.
Save foxyblocks/d0186f9a8d58ebef071ba2f2ab14ea6f to your computer and use it in GitHub Desktop.
A simple isomorphic bugsnag module. (requires that process.env.IS_BROWSER be present in browser build)
// The bugsnag javascript libraries are not isomorphic so we need to specify which one we want to use depending on environment.
let Bugsnag;
if (process.env.IS_BROWSER) {
Bugsnag = require('bugsnag-js');
Bugsnag.apiKey = process.env.MY_BROWSER_PROJECT_API_KEY;
} else {
Bugsnag = require('bugsnag-node');
Bugsnag.register(process.env.MY_NODE_PROJECT_API_KEY);
}
// Re-export it so the rest of the app can use it.
module.exports = Bugsnag;
@foxyblocks
Copy link
Author

foxyblocks commented Aug 1, 2016

For usage with webpack add the following to webpack.config.js

module.exports = {
  plugins: [
    new webpack.DefinePlugin({
      'process.env': {
         IS_BROWSER: true,
         MY_BROWSER_PROJECT_API_KEY: 'abc123'
      },
    }),
],
}

@joshunger
Copy link

@wordofchristian thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment