-
-
Notifications
You must be signed in to change notification settings - Fork 363
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 a UMD build to support older environments #81
Conversation
This does not transpile the code to ES5, so extremely old environments are still not supported out of the box. Rather, this makes it easy to import ky in non-ESM environments, such as Node.js.
What are your thoughts on using the Per https://babeljs.io/blog/2018/06/26/on-consuming-and-publishing-es2015+-packages |
Co-Authored-By: sholladay <me@seth-holladay.com>
I thought about this for a bit and IMO, it is probably unnecessary. Here is the impact as I see it:
So the choice appears to be between giving preferential treatment to ESM users on unpkg or CJS users on Node. The former seems like the obvious choice to me. |
Good points. I agree. Let's not do it. Webpack also seems to have several problems with the |
Should we update https://github.com/sindresorhus/ky#download and https://github.com/sindresorhus/ky#how-do-i-use-this-without-a-bundler-like-webpack to also have a UMD version? |
I added to the "without Webpack" FAQ, but not to the download links. Just thought it would be a bit cluttered otherwise, since the list is of alternative CDNs. I suppose we could reformat it as a table, but I just left it alone for now. |
Agreed. Looks good now :) |
In case you ever want to revisit this, it's fairly unexpected for @sholladay you mention that the choice is between "giving preferential treatment to ESM users on unpkg or CJS users on Node". You could support everyone with: // Node.js loads umd
"main": "umd.js",
// Bundlers load esm
"module": "index.js",
// Unpkg loads esm
"unpkg": "index.js",
Happy to submit a quick PR if there's interest. |
Thanks for the suggestion. I'm not entirely opposed to that, although it would be much better if unpkg just respected Do you know if there are any plans for that? |
Agreed, I can't find the tweet right now but I remember Michael Jackson sharing regrets that he'd built this for "main" and not "module"/"umd" but feeling that it would break too many consumers to change it now. "module" is pretty well supported right now as the "esm"/"web" entrypoint for packages. I've been tracking it's growth over here: https://www.pikapkg.com/about/stats. Pikapkg.com is a catalog of ESM packages, and it uses "module" to detect which packages export web-friendly ESM (since bundlers are the only real consumers of it, it's a safe, feasible guaranteed way to go about it). I'm not sure about those webpack bugs shared above, but both seem to deal with CJS/ESM interop problems that wouldn't affect this library (in UMD you export your default under the correct |
Closes #44
Following the discussions in #44 and #46, we decided to only convert module syntax. This does not transpile the code to ES5, so extremely old environments are still not supported out of the box. Rather, this makes it easy to import ky in non-ESM environments, such as Node.js.
I went with Rollup instead of Babel, because it is simpler to configure and its output is slightly better (easier to read 👀 and no hardcoded AMD ID).