bugsnag / webpack-bugsnag-plugins

Webpack plugins for common BugSnag actions.
MIT License
32 stars 29 forks source link

Query strings applied to source map names. #36

Open vincemukiiri opened 5 years ago

vincemukiiri commented 5 years ago

I'm using webpack 3.12 and I do codesplitting on my js into chunks and use query strings to version them e.g. page1.chunk.js?id=abcdef. The file is then saved as page1.chunk.js. Problem is, the query string is applied to the source map names page1.chunk.js.map?id=abcdef and that is the name used when uploading to Bugsnag, this results is Bugsnag not matching the file page1.chunk.js to the map page1.chunk.js.map?id=abcdef. This is my webpack config that generates chunks names

module.exports = {
  output: {
    chunkFilename: '[name].chunk.js?id=[chunkhash]'
  },
}

I've come across issue #8 and saw the proposal to have a config option to determine the minifiedUrl. Is it possible to have something similar for the sourceMap option like so

new BugsnagSourceMapUploaderPlugin({
  apiKey: 'YOUR_API_KEY',
  appVersion: '1.2.3',
  getSourceMap: (sourceMapName) => {
    // this will remove the query string from the sourcemap name
    return sourceMapName.replace(/\?id=.*/, '')
  }
})

This would enable me to get rid of the query string in the sourcemap name so that Bugsnag can match the file and the map correctly.


I've looked into source-map-uploader-plugin.js and seen that there a function used to strip query strings from sourcemap

const outputSourceMapLocation = stripQuery(compiler.outputFileSystem.join(outputPath, map))

// ...

// removes a querystring from a file path
const stripQuery = file => {
  const queryStringIdx = file.indexOf('?')
  if (queryStringIdx < 0) return file
  return file.substr(0, queryStringIdx)
}

But the query strings are still being included in the source map during upload.

vincemukiiri commented 5 years ago

Similar issue #34