Skip to content

Add hook to customize source map file resolution #731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
thecodewarrior opened this issue Apr 28, 2025 · 4 comments · May be fixed by #732
Open

Add hook to customize source map file resolution #731

thecodewarrior opened this issue Apr 28, 2025 · 4 comments · May be fixed by #732

Comments

@thecodewarrior
Copy link

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)
        }
      },
    })
  ]
}
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Apr 28, 2025
@lforst
Copy link
Member

lforst commented Apr 29, 2025

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.

@Lms24
Copy link
Member

Lms24 commented Apr 29, 2025

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

@thecodewarrior
Copy link
Author

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

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Apr 30, 2025
thecodewarrior added a commit to thecodewarrior/sentry-javascript-bundler-plugins that referenced this issue Apr 30, 2025
@chargome
Copy link
Member

chargome commented May 2, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
4 participants