Skip to content
This repository was archived by the owner on Oct 29, 2026. It is now read-only.
This repository was archived by the owner on Oct 29, 2026. It is now read-only.

Add hook to customize source map file resolution #731

Closed

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)
        }
      },
    })
  ]
}

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Apr 28, 2025
  2. lforst commented on Apr 29, 2025

    @lforst

    Thanks for the suggestion. This seems like an extremely reasonable feature. Feel free to open a PR! Otherwise we'll get to it sometime in the future.

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Apr 29, 2025
  4. Lms24 commented on Apr 29, 2025

    @Lms24
    Member

    Just for me to understand: Why can't you use the sourcemaps.assets option to set the path to the source maps?

  5. thecodewarrior commented on Apr 30, 2025

    @thecodewarrior
    ContributorAuthor

    I didn't test that option, but as far as I understand it, using that might allow the sourcemaps to be uploaded, but they won't correctly have the debug IDs added and won't be associated with the correct JS files

  6. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Apr 30, 2025
  7. added a commit that references this issue on Apr 30, 2025
    b55feb0
  8. chargome commented on May 2, 2025

    @chargome
    Member

    @thecodewarrior thanks for the PR, we'll have a look!

  9. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on May 2, 2025
  10. added a commit that references this issue on May 13, 2025
    b33725e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions