yocontra / react-responsive

CSS media queries in react - for responsive design, and more.
https://contra.io/react-responsive
MIT License
7.04k stars 298 forks source link

feat: build with rollup, add esm distribution #310

Closed mihkeleidast closed 1 year ago

mihkeleidast commented 1 year ago

Fixes #305, fixes #306.

This switches the distribution bundle builder from webpack to rollup. Webpack is not really meant for bundling libraries (it works better for apps), while rollup is meant just for that. I've verified that at least for me changing this fixes the issues. I published my fork under @mihkeleidast/react-responsive.

I'm not entirely sure if the UMD (and minified) distribution files are necessary, maybe you can specify what they're for currently (i.e. are they meant for loading directly to the browser in some workflow)? Then we could try to figure out how to build them (I'm sure it's possible) and how to reference them in package.json for bundlers.

Note: I'm also not entirely sure how the perfect package.json distribution setup should look like, nowadays there are lots of different fields that can be used there (e.g. export maps and the like). Not sure if this basic setup can break for anyone or not.

yocontra commented 1 year ago

Thanks for this - will review soon. The UMD stuff is for loading in the browser via a head tag, I'm not sure anyone is really doing that anymore so if it's a pain we can probably get rid of it.

mihkeleidast commented 1 year ago

But how should it get to the browser? I.e. is there some CDN service that tries to load it, or is there some documented way of copying the files over from node_modules? Just thinking that if we do keep it, does it need to be marked up in package.json in some field or not.

I also agree that likely anyone using this library in 2023 is on some sort of a bundler, so shouldn't need this UMD behavior, so dropping it is definitely easier.

yocontra commented 1 year ago

@mihkeleidast Using unpkg.com or similar sites should fill this gap without needing UMD stuff - UMD stuff was more for directly including it via a script tag which creates globals, I think unpkg takes any module and does that wrapping for you so shouldnt be needed for us to build that anymore.

Edit: looks like unpkg has a specific spot where you do need to put a UMD build, but I still think this is an edge case we don't need to handle anymore.

mihkeleidast commented 1 year ago

@yocontra friendly ping - any update on when you'll be able to review this?

denchen commented 1 year ago

Hi, for some reason we've just started seeing the same issue as in #306 , even though that issue was opened three months ago. I'm hoping this PR will resolve the "not a function" problem. Any chance this gets reviewed/merged anytime soon?

doichev-kostia commented 1 year ago

@yocontra, could you take a look at this pr once again, please?🥺 ESM support is essential

Fasaloft commented 1 year ago

What's the update of this PR? I also need the Vite support in next release, cause now its breaking my app.

Kodnot commented 1 year ago

We could also really use this, facing issues similar to #306 🥺

yocontra commented 1 year ago

I'm going to publish this as a 10.0 beta and let you all test it out for a bit

yocontra commented 1 year ago

Published as 10.0.0-beta.1 - please test and report any issues. One issue with this PR is it broke the tests with the changes to tsconfig, @mihkeleidast