Open anothertempore opened 5 months ago
Hi, thanks for writing in. We will most likely not dedicate much time to this in the short to medium-term future.
For posterity, I used the banner plugin because it was the most reliable way of injecting stuff at the top of bundles while preserving sourcemaps. We would likely want to build something similar ourselves, but I recall that doing non-trivial code modifications and preserving source maps is a major PITA. I legit couldn't get it to work.
Environment
webpack@5.87.0, @sentry/webpack-plugin@2.10.2
Steps to Reproduce
This injection logic should be placed below
use strict
: https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/febe9ce8dfa34c08ae1b7badc9c9e23182aa2ace/packages/webpack-plugin/src/index.ts#L157-L160In our case, TerserPlugin removes all the
use strict
because it is not at the top of the file.Possible Solution
A possible solution is to do like below:
However, from webpack side, better not to use BannerPlugin to inject code, it's not designed for this. Can refer to https://github.com/webpack/webpack/issues/18202