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

Avoid having Webpack load the UMD module #42

Merged
merged 1 commit into from
Oct 28, 2020
Merged

Avoid having Webpack load the UMD module #42

merged 1 commit into from
Oct 28, 2020

Conversation

realityking
Copy link
Contributor

Depending on the configuration bundlers like Webpack will load the browser fielder instead of the main file. Besides users older versions of Webpack that don't support module this also affects us because we currently disable module in our project due to some bug.

This change removes the browser field but forces both unpkg and jsdelivr to use the UMD version.

@realityking
Copy link
Contributor Author

The CI is due to missing env variables for Browserstack. I suspect this is failing because it's a PR from a fork.

@niksy
Copy link
Owner

niksy commented Oct 28, 2020

I can see your point, but I would like to leave browser field and point it to index.esm.js (which is module version).

@realityking
Copy link
Contributor Author

@niksy Obviously this is your call but I'd be curios why? AFAIK there's no advantage to delivering UMD builds to bundlers which are the main consumer of the browser field. In fact I just looked it up and Webpack 5 actually prefers the browser field over the module field: https://webpack.js.org/configuration/resolve/#resolveimportsfields

I think that's very undesirable.

@niksy
Copy link
Owner

niksy commented Oct 28, 2020

But if browser points to ESM build, you won’t load UMD code. Your addition for unpkg and jsdelivr will point to UMD build.

Also, I have unpushed code which will add support for exports field and then all other fields will be ignored.

@realityking
Copy link
Contributor Author

But if browser points to ESM build, you won’t load UMD code. Your addition for unpkg and jsdelivr will point to UMD build.

But browser today is not pointing to ESM, it's pointing to UMD. My change is letting it point to CJS. As you can see in my link above Webpack's default order is browser, module, main. Today, that means for throttle-debounce an UMD build is loaded. With my change an ESM build is loaded.

Also, I have unpushed code which will add support for exports field and then all other fields will be ignored.

exports would be excellent but it's only supported by Node.js and Webpack 5. There are a lot of users of Webpack 4 (and even 3!) still out there, not to mention parcel, rollup, etc.

@niksy
Copy link
Owner

niksy commented Oct 28, 2020

OK, I see your point. Could you please add new entry to CHANGELOG?

@realityking
Copy link
Contributor Author

Done! Let me now if the entry is unclear.

@niksy niksy merged commit d62b93c into niksy:master Oct 28, 2020
@niksy
Copy link
Owner

niksy commented Oct 28, 2020

Rebased and merged! I will prepare new version tomorrow.

@realityking
Copy link
Contributor Author

Thank you @niksy!

@realityking realityking deleted the umd branch October 28, 2020 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants