Skip to content
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

Should inject banner code after use strict #507

Open
anothertempore opened this issue Mar 17, 2024 · 1 comment
Open

Should inject banner code after use strict #507

anothertempore opened this issue Mar 17, 2024 · 1 comment

Comments

@anothertempore
Copy link

Environment

webpack@5.87.0, @sentry/webpack-plugin@2.10.2

Steps to Reproduce

This injection logic should be placed below use strict:

new BannerPlugin({
raw: true,
include: /\.(js|ts|jsx|tsx|mjs|cjs)$/,
banner: injectionCode,

In 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:

new BannerPlugin({
  raw: true,
  include: /\.(js|ts|jsx|tsx|mjs|cjs)$/,
  banner: injectionCode,
  footer: true,
})

However, from webpack side, better not to use BannerPlugin to inject code, it's not designed for this. Can refer to webpack/webpack#18202

@lforst
Copy link
Member

lforst commented Mar 18, 2024

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.

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
Development

No branches or pull requests

2 participants