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 · 2 comments
Open

Should inject banner code after use strict #507

anothertempore opened this issue Mar 17, 2024 · 2 comments

Comments

@anothertempore
Copy link

Environment

[email protected], @sentry/[email protected]

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

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 2 Mar 17, 2024
@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.

@s1gr1d
Copy link
Member

s1gr1d commented Dec 10, 2024

Closing this in favor of clean-up. Feel free to open it again.

@s1gr1d s1gr1d closed this as completed Dec 10, 2024
@lforst lforst reopened this Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants