-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Bundle cjs and es formats #2358
Conversation
Can you show build output comparison? |
I'm not sure what this gets us though. We only need to compile out ES.next stuff for these builds, as they're only used in the context of a module-aware system (node, webpack, rollup, etc). We don't need to bundle for these systems. |
It's about optimization for bundlers and node. |
Sure, but that will show up in stack traces as just Also, if the bundle is bad in some way, we wouldn't know, as the tests run against the code as-is (transpiled through babel), not in its bundled form. Optimization should come at the end of the bundle process, not at the library level. Our early optimization might conflict with a later optimization or prevent one from occurring. We should just ship code and let the user bundle and optimize however they want. I get where you're coming from, but unfortunately, this is going to cause more problems than it might solve. |
I dunno, isn't this exactly what we're doing for React? |
That's why I opened this PR. I think debug is not so significant here. Redux is small library. Function names are more than descriptive. Producing smaller packages, smaller in count of files, we are forcing the most optimal versions of libraries independent of build tools. Better UX |
I agree with @TrySound and I would like this to be reconsidered. There is very little surface area in Redux, and IMO the argument around tests just means we need better integration tests for result bundles. Personally I’m coming to the conclusion that the end user can’t be trusted to optimize efficiently, and also doesn’t have enough leverage (e.g. can’t easily remove junk code at the module boundaries if they use Webpack). |
@TrySound Can you suggest a testing approach that would work well? IMO it would be nice to have a way to run all existing tests on result bundles in addition to the source. They should be testing the public API anyway. |
@timdorr It's. Try |
Sorry, I meant React 16. I thought we were pretty vocal about moving to Rollup and flat bundles :P |
Forgive me for weighing in — have been passively aware of this conversation since I was @-ed yesterday. My view is that libraries should always bundle their own source code unless they have a compelling reason not to — @gaearon rightly points out that generating the best possible output (fewest bytes, quickest startup) requires a certain level of expertise, and for the app developer to be using particular tools. It's quite easy to end up with various unnecessary overhead such as unnecessarily transpiled import declarations, or the cruft that most bundlers introduce at module boundaries. By pointing @timdorr you raise two excellent points:
Just my 2c — I don't have a dog in this fight but thought I'd try and articulate why I think this is a good direction for the ecosystem to go in. |
Ah, OK. I haven't yet tried out the alphas myself. But I would point out React has different design and performance goals than Redux. To be honest, the "well, it's what React does" argument doesn't ever sway me. React can afford to jump through certain hoops because the benefits are often multiplied as they make their way downstream (both in code and the ecosystem surrounding it). And yes, Redux is orders of magnitude smaller and simpler, so there is less potential "damage" from things like this. However, I don't see the benefit in making the build, testing, and debugging processes more complex for no practical benefit to any stakeholder. So, since this is central to my concerns, I'll ask it more directly: what specific and practical gains does library bundling get us? Anecdotally, I would never apply this to a library like React Router, as one of the bundle-slimming techniques we use is encouraging direct imports ( |
Clean, readable code without junk and indirections. Output like this is suboptimal: if (!(0, _isPlainObject2['default'])(action)) {
throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.');
} Especially in hot paths (we have to dereference This also doesn't look great: exports.__esModule = true;
exports.compose = exports.applyMiddleware = exports.bindActionCreators = exports.combineReducers = exports.createStore = undefined;
var _createStore = __webpack_require__(2);
var _createStore2 = _interopRequireDefault(_createStore);
var _combineReducers = __webpack_require__(7);
var _combineReducers2 = _interopRequireDefault(_combineReducers);
var _bindActionCreators = __webpack_require__(6);
var _bindActionCreators2 = _interopRequireDefault(_bindActionCreators);
var _applyMiddleware = __webpack_require__(5);
var _applyMiddleware2 = _interopRequireDefault(_applyMiddleware);
var _compose = __webpack_require__(1);
var _compose2 = _interopRequireDefault(_compose);
var _warning = __webpack_require__(3);
var _warning2 = _interopRequireDefault(_warning);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } when it all could’ve been top-level functions referencing each other. I’m not sure I understand the concerns about testing and debugging. How often do we release Redux updates? How fast is it changing? I can understand the concern if there is a lot of churn, but I don’t quite see why this is an issue here. Testing the output bundles will only make the process more solid (and help avoid release bugs). |
I guess internal and interface testing are both possible with babel. We can import interface part from entry point and internal stuff from source files. That's what I did here. |
One other point for bundling is babel. It adds helpers in every file. Rollup adds 'em only once. So for end user is not possible to make optimal build other then babel source files of the library. And this is awful UX. Because of this I reduced component based library recompose in two times. It's not small redux. |
Ok, now I'm starting to get it 😄
I'm only concerned with stack traces pointing back to code that's different than what they see in the repo. Namely, if they see I guess a lot of my concerns stem from couching this discussion on code running in the browser. But I'm running of steam wanting to talk through transpiled code compatibility issues... Anyways, I guess this looks good to me. Even though we don't guarantee it, this will break anyone using direct imports. Would we want to break this behavior on a minor or major? If major, then can I rebase this PR against |
Yeah, I think it should be released as major. |
That’s the only part that’s concerning me. I’d like to have a good way forward there. What should libraries depending on specifically |
OK, I'm going to edit this to be against |
Oh yeah, ignore all that interim junk 😄 |
OK, there we go. Merge conflicts resolved.
We could keep transpiling individual files into
I'm confused, isn't that already in this? It's just bundled together, but the |
Fixed up some merge conflicts and got this using the latest rollup config syntax. For sizing comparison on the current ⇶ wc lib/* lib/utils/*
63 308 2323 lib/applyMiddleware.js
50 286 2038 lib/bindActionCreators.js
144 840 6317 lib/combineReducers.js
35 134 927 lib/compose.js
266 1373 9873 lib/createStore.js
45 200 1944 lib/index.js
0 0 0 lib/utils
13 61 381 lib/utils/actionTypes.js
24 103 694 lib/utils/warning.js
640 3305 24497 total And this PR: ⇶ wc lib/*
566 3100 22032 lib/redux.js So, a nice size reduction, and therefore a bit of complexity reduction too. Here's the latest output: https://gist.github.com/timdorr/f6d76d41508bf5a352846ba685322a6c |
OK, I'm feeling good on this. It's well-tested and has a sensible reasoning for the change. We'll be sure to communicate that change to users when it lands in 4.0. Thanks, @TrySound! |
* Bundle cjs and es formats * Test generated bundle * Missed a yarn command in the merge process * Updates to the rollup config.
* Bundle cjs and es formats * Test generated bundle * Missed a yarn command in the merge process * Updates to the rollup config.
* Bundle cjs and es formats * Test generated bundle * Missed a yarn command in the merge process * Updates to the rollup config.
Sorry, I have confused branches. I think this will be a breaking change and should be merge to next branch.