Skip to content

Add hook to customize source map file resolution #731

@thecodewarrior

Description

@thecodewarrior

The sentry plugin currently uses heuristics to locate sourcemap files for a given bundle file, but in some build configurations this is insufficient. Specifically if the sourcemaps are being written to a separate directory. It would be good to have a hook, similar to sourcemaps.rewriteSources, that would allow you to manually resolve the .map files.

In our specific webpack build we're writing our sourcemaps into a separate directory so they can be bundled up and hosted separately. To do this we configure the SourceMapDevToolPlugin with a custom filename pattern and //# sourceMappingURL line. However, the sentry plugin doesn't know about or understand any of these configs, so it's unable to locate the source map files.

Here's an example of how our solution might look:

module.exports = {
  devtool: false,
  plugins: [
    new webpack.SourceMapDevToolPlugin({
      filename: `../sourcemaps/[file].map`,
      append: `\n//# sourceMappingURL=${SOURCE_MAP_HOST}/[file].map`,
    }),
    sentryWebpackPlugin({
      sourcemaps: {
        resolveSourceMap(bundlePath, sourceMappingUrl) { 
          return sourceMappingUrl.replace(SOURCE_MAP_HOST, SOURCEMAP_DIR)
        }
      },
    })
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions