-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Switch build to Rollup? #5336
Comments
Of note, we switched over Redux and it's been great. Cleaner and smaller builds are great. Also, react-router-redux is already using it. |
It looks like Redux only uses it for the UMD builds, though, right? Are there plans for the |
File sizes aren't the only reason to do this, but since I mentioned them above, here are my results. Current:
Rollup:
The full size files are actually slightly bigger, but the minimized files are all smaller. 🤷♀️ I believe that I have identified the cause, which is the |
Thanks for bringing this up. It's been on my mind for some time now, but I just keep using webpack because it's the thing I already know. We currently use webpack in 3 places:
I realize you're only suggesting we switch the UMD builds to use Rollup, but I'd like to avoid a situation where we're using 2 different bundlers in the same repo (I didn't realize We can pretty easily switch the UMD builds to use Rollup. I'm currently working on porting the test suite to Jest, so I think we'll be able to ditch the webpack We'll probably want to stick with webpack for the website, unless you're really determined to figure something else out. So for now I'd probably say let's just stick with webpack everywhere. Does that make sense? Or am I just being lazy?
Ya, I think you're right. We should probably change this line to say |
I was actually suggesting all of the builds, not just UMD. I have it working for I think that it would be fine to have the website built with webpack while everything else is rollup. That would keep to the "Use webpack for apps, and Rollup for libraries" idea. |
Sorry if I'm a little slow here, but what advantage is there to building our ES + CommonJS builds with rollup over just using babel? Also, I'm a bit confused as to why Rollup generates a single file instead of multiple files like we currently do for those builds. AFAICT we don't actually want a bundle for those builds. The separate files are what makes it easy for people to |
I was just reading through that Redux thread Tim linked earlier and saw one of his comments there:
The loss of "poor man's tree shaking" would definitely upset some people. It is definitely an extreme change to switch to a single file we could just switch to Rollup for the UMD (at least for the time being). The way that I look at this is:
Maybe it is too early to switch to a single file, but I think that at some point in time it will make sense to say "rely on your bundler" for optimization instead of cherry picking files. Then, we can still stick to multiple files, but that is more of an aesthetic choice. I'll revert the |
With the tests switched to jest, the diff between master and rollup is now a lot easier to go through: master...rollup. The only "controversial" thing might be that I moved the entire Babel config to a |
Since you've got it checked out and installed locally already, would you mind posting a gist with the output from Webpack and Rollup of the uncompressed UMD? Just to show the readability differences. For example, here are Redux's: Rollup UMD build Much cleaner to read through, which is important for good DX. I still maintain Webpack is for apps (like the website) and Rollup is for libs. BTW, I'm not totally against building the ES and CJS as bundles too. Those are also really clean: Babel index.js It's definitely worth exploring here. |
The only thing that I don't love about Rollup is the way that the // someModule/index.js
module.exports = { ... }
// is transformed to
var index = { ... }
export default index Not a huge concern, but prettier names would be nice for reading. I opened up a PR there, so we'll see if that changes gets considered (rollup/rollup-plugin-commonjs#208). |
I really wish this were the case, and I thought we were already there with webpack 2 but it doesn't look like it. In that PR, we're actually reverting back to cherry-picking files because webpack doesn't know how to tree-shake Would you be open to reducing the scope of this PR to use rollup for only the UMD builds? We can keep using babel for es/cjs so people can keep cherry-picking and perhaps take those up in a separate issue when it makes sense. |
The current As far as that PR goes, I want to say that the problem would disappear if we were using a single file, but I'd have to do some testing to figure out if that is true. I'll try to put together a demo project sometime soon and see whether a single file release will only include the relevant files. I've rethought my earlier statement and think that it would be appropriate to switch to single file |
Ah, sorry. I just assumed it was doing what you said before. I'll take another look at the code. |
Well, this all looks 👍 to me. Ready to merge, @pshrmn? |
I should probably switch |
Are we concerned about externalizing the |
Ideally |
Alright, I added |
Closed by #5343 |
Just an update about the idea of moving the other builds to rollup: for the time being, we cannot https://twitter.com/Rich_Harris/status/887993633823240192 Basically, every var inherits = function(sub, super) {...}
var C = function(_ReactComponent) {
inherits(C, _ReactComponent);
function C () {...};
return C;
}(React.Component); The I'm hoping that in the future we can inline the |
I just wanted to bring this up since there is some discussion happening related to the current builds (#5095).
I've been using Rollup in some of my projects to output a single file for each format and enjoying it. For React Router, that would mean that instead of a dozen
commonjs
files, a dozenes
files, and two UMD files, we would end up with four total files (react-router.common.js
,react-router.es.js
,react-router.js
, andreact-router.min.js
) . I think that that is the direction Facebook is heading with React and I know that that is what Vue is already doing.The only real "concern" I've had with that is source maps. Rollup can generate them for you, that isn't the problem. It is just that I end up having to use the
source-map-loader
to prevent the browser for asking for them. It is just a minor annoyance, but something to take into consideration. Vue doesn't even ship with sourcemap files, although I'm not sure what the reasoning behind that is.Another thing to think about is that only the top level exports get exported. Whether or not this is a good thing probably depends on who you ask. I like it because you don't have to worry about people importing private APIs from the package. If it isn't exported from
index.js
, they can't import it. I suppose that technically that is a breaking change for people who doimport Route from 'react-router/Route'
. It doesn't break the API, though, so I think that a minor bump would be enough.If there is interest, I can put together a PR to do this. I might go ahead and actually do that anyways to get an idea of the output file sizes.
The text was updated successfully, but these errors were encountered: