-
Notifications
You must be signed in to change notification settings - Fork 915
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
Add experimental support to polyfill/shim builtin modules #6
Conversation
It's been about a month and I haven't heard any complaints/comments/asks for this, so I might just leave this in purgatory. If you run into a valid use case where this is needed, lmk. |
I think I'm a little late to the game but I have a use case 😅
So I'm using:
I wanted to add power assert for better assertions in the tests So now I bundle it manually, place it But if this PR gets merged, it will all be handled magically with |
23f3188
to
f7ea1be
Compare
/cc @dmnsgn who started this convo on our discussion board as well: https://www.pika.dev/npm/snowpack/discuss/52 So after looking back into this, it looks like Rollup's node builtin story is pretty weak. There's an unofficial plugin for it, but the author is absent. The Rollup team tried to bring it into their org, but realized it was unlicensed. There's a fork with some issues fixed that this PR uses, but that's also about a year out of date now. So it's a bit of a mess. While I was searching though, I also came across this: https://github.com/jvilk/BrowserFS
I think those are the most commonly used packages needing shim, and I bet we could get away with just supporting those at least to start. BrowserFS is ~3 packages total, while the rollup plugin was going to add ~80. |
Hmm, BrowserFS is a bit weird too, due to the fact that it's heavily using UMD it's expecting a lot of heavy lifting to be done by a |
:sad In my use case the built in module |
Your package uses crypto on the frontend? Can you send a link? |
We're using |
My couple of cents. And it feels great. Too many browser packages use default node builtins. To estimate - have a look at direct dependents of buffer, stream, path, util, events etc, browserify shims builtins with these packages (here). Consider also the amount of indirect dependents. Many orgs (used to) take browserify as normal practice: https://github.com/scijs, https://github.com/stackgl, https://github.com/gl-vis etc. The history of browserifying things has long roots. There are solutions for almost everything, even fs - eg. brfs inlines file content in bundle, so for user that feels seamless. The main drawback of browserified builtins is bundle size. For example, |
|
(Looks like your comment was marked as "off topic" accidentally. Since I asked for feedback in the first comment above, that feedback was perfectly fine. Sorry about that! /cc @monchi @DangoDev lets reserve comment hiding for spam/abusive comments only.) +1, at this point I'm on board with adding this feature as an opt-in. It's almost always a better option to find a better, more web-friendly dependency that won't bloat your app like the 230kb crypto polyfill will, but I understand that a better dep may not always exist. The major issue, though, is that the only good plugin that does this for Rollup is 3rd party, and has been abandoned (~3 years without a push, and lots of "outdated dependency" bugs). I've just posted to the Rollup team to see if they're still interested in building a new, official plugin for this now that they have their "official plugins" repo. If you are at all interested in helping build that, both teams would be really thankful! |
Update: we may support this via user-provided plugins instead: https://www.pika.dev/npm/snowpack/discuss/79 |
I'm creating this PR verrrrry tentatively, since I'm worried it will give the false impression that any Node dependency is fine with this option, when really it's a sign that some dependency in your tree probably isn't meant for the web.
I may end up restricting this to just a set of packages that we feel comfortable with, like "path"/"fs"/"url" and continue to fail if more complex packages like "fs"/"http"/"crypto" are encountered.