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

Allow configurable bundles #3599

Closed
thekevinbrown opened this issue May 31, 2021 · 4 comments
Closed

Allow configurable bundles #3599

thekevinbrown opened this issue May 31, 2021 · 4 comments

Comments

@thekevinbrown
Copy link

Clear and concise description of the problem

  • We use React PDF.
  • It bundles in server side code which needs global and a few other things shimmed (e.g. react-pdf is not compatible without shims #3405)
  • When using the workaround in the issue, the code works in development but does not work with a rollup production build.
    • This is because the stuff in index.html gets pulled into the user code bundle, which runs after the vendor bundle.
    • I created a local NPM module so this code would end up in the vendor bundle, and it does indeed end up in the vendor bundle then.
    • But importing it still happens in my user code, which is loaded after my vendor bundle, so we still get a Buffer is undefined error even when it's a part of the vendor bundle.

Suggested solution

Allow us to configure this polyfill to be injected at the top of the vendor bundle.

I couldn't find a rollup plugin (or vite plugin for that matter) that would allow this arbitrary code to get injected in the vendor bundle.

Happy to do this however I need to. I'm running out of options, and am thinking of gross things like a postinstall script to inject this at the top of the package if I can't find a way to configure Rollup to inject it.

Alternative

I'm also working on fixing React PDF itself so it works properly in modern environments and doesn't need all these shims, but I'm really struggling to even get a dev environment with a running example up for that package, so it'll be slow going. I think it'd be nice to allow developers to configure these types of workarounds when needed for other packages that they can't change.

Additional context

N/A

@bluwy
Copy link
Member

bluwy commented Mar 9, 2022

Hi @thekevinbrown, is this feature request still needed? It sounds like a very niche case that should be fixed within react-pdf. Regarding the global shim, I think doing window.global = window should work too? If you put it in your entry file.

@thekevinbrown
Copy link
Author

There was a bunch of workarounds required to make this work: https://github.com/exogee-technology/vite-plugin-shim-react-pdf

I still think it'd be useful to have the loading order of scripts in the production bundle the same as the dev bundle to minimise issues like this.

@bluwy
Copy link
Member

bluwy commented Mar 14, 2022

The Vite plugin looks fine to me. It's intended to polyfill those nodejs modules manually if you use them.

Re loading order, is it similar to #7264? You can configure rollupOptions if you need something specific in your bundle. So I think this feature is already covered today. Can you clarify if there's anything else not covered yet, and what's the desired API?

@thekevinbrown
Copy link
Author

Yup, that looks like a more concise version of what I'm asking for. I'll close this as a duplicate of #7264.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants