rollup / awesome

⚡️ Delightful Rollup Plugins, Packages, and Resources
MIT License
2.55k stars 139 forks source link

Add node-polyfills #92

Closed curran closed 3 years ago

curran commented 3 years ago

Awesome Contribution Checklist:

Please Provide a Link A Repository for Your Addition

https://github.com/ionic-team/rollup-plugin-node-polyfills

Please Describe Your Addition

This is a mature package that polyfills Node builtins (such as EventEmitter). It is actually recommended by a Rollup warning that reads as follows:

Creating a browser bundle that depends on Node.js built-in modules ("events"). You might need to include https://github.com/ionic-team/rollup-plugin-node-polyfills

So, I was surpised that it's not on this list! As I've been using this list as a reference so frequently, I figured I'd open this PR to add this entry.

Thanks for maintaining!

shellscape commented 3 years ago

Unfortunately that package is no longer maintained and the maintainers are next to impossible to work with. The rollup project no longer recommends it.

curran commented 3 years ago

Oh I see. Thanks for the tip!

Out of curiosity, what is the recommended way to get Node polyfills in a Rollup context? Browserify plugin?

curran commented 3 years ago

The Rollup source still recommends it: https://github.com/rollup/rollup/blob/ce2592df6b369b68d61f58c2ef8bf4695421146a/src/finalisers/shared/warnOnBuiltins.ts#L39

shellscape commented 3 years ago

yeah there have been some open issues about that line of code. while that legacy bit of code stays, we can't in good conscience add that to the list here for the reasons stated. there have been some other projects attempting to fill the void, but everything ends up incomplete and it's a bit overwhelming for maintainers to tackle

curran commented 3 years ago

Understood. Thanks!

I think I'll give the Browserify Rollup plugin a spin and see if that does the job. I recall from years ago that Browserify did polyfill Node builtins, but haven't touched it in years.

curran commented 3 years ago

Oh wow, that https://www.npmjs.com/package/rollup-plugin-browserify-transform module hasn't been published in 4 years.

curran commented 3 years ago

Found that other issue: Stop recommending node-globals/node-builtins plugin #2881.

curran commented 3 years ago

Submitted a patch upstream https://github.com/rollup/rollup/pull/4190

Looks like https://github.com/snowpackjs/rollup-plugin-polyfill-node is the clear winner.