Skip to content

Instantly share code, notes, and snippets.

@jonoirwinrsa
Last active February 16, 2019 15:42
Show Gist options
  • Save jonoirwinrsa/c556cce342b0efeb409089556e373cde to your computer and use it in GitHub Desktop.
Save jonoirwinrsa/c556cce342b0efeb409089556e373cde to your computer and use it in GitHub Desktop.
Upload Create React App sourcemaps to Bugsnag - Step 2
const { upload } = require('bugsnag-sourcemaps');
const appVersion = require('./package.json').version;
/**
* Uploads the source map with accompanying sources
* @param sourceMap - single .map file
* @returns {Promise<string>} - upload to Bugsnag
*/
function uploadSourceMap(sourceMap) {
// Remove .map from the file to get the js filename
const minifiedFile = sourceMap.replace('.map', '');
// Remove absolute path to the static assets folder
const minifiedFileRelativePath = minifiedFile.split('build/')[1];
return upload({
apiKey: process.env.REACT_APP_BUGSNAG_API_KEY,
appVersion: appVersion,
overwrite: true,
minifiedUrl: `http*://${process.env.REACT_APP_SITE_HOSTNAME}/${minifiedFileRelativePath}`,
sourceMap,
minifiedFile,
projectRoot: __dirname,
uploadSources: true,
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment