-
Notifications
You must be signed in to change notification settings - Fork 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
chore(build): Use rollup to bundle cjs build #2064
Conversation
While it brings additional steps of generating build, I'm 👍 since outcome looks good. One question - does sourcemap for min version points original code correctly? |
@kwonoj The sourcemaps are generated by GCC and they're based off the post-transpiled/post-bundled output (you have to pass But this brings up another point, and it's that the source maps should be based on pre-bundled output (maybe also pre-transpiled output). This would make them quite large (prob a few MB), but maybe more useful. |
(My personal 5c) I'd prefer sourcemap to be more accurate even it'll take more space. Prod. code can strip sourcemap anyway since it's not inlined. |
@kwonoj sure. Would you like me to make that change here or in another PR? (Since this PR keeps the original behavior) |
I agree with that, but let's consider that after got agreement on this PR and merged. I'm 👍 , need additional approval to check in. |
Hey – Rollup author here, I got alerted to this thread. The sourcemap thing is an issue I've had to deal with in a few different contexts, so I wrote a tool called sorcery to generate a sourcemap that accounts for an arbitrary number of sourcemap-generating transformations. It's not bulletproof (nothing involving sourcemaps is, in my experience!) but it might be useful so I thought I'd mention it. It ought to be possible to dedupe helpers using rollup-plugin-babel, though YMMV (I don't use it personally, so I'm not 100% sure it's kept up with changes to Babel) – in theory it will generate slightly leaner output, and the build will be faster than transpiling the whole bundle. |
LGTM, we're going to continue to discuss more accurate source map support. |
@Rich-Harris: I tried |
Thanks @jayphelps and @kwonoj! Nuclide would really appreciate a |
@zertosh side question, we've been trying to accumulate use cases from our Electron users who don't use a bundler. Since Nuclide is one of them, can you provide any insight? If a bundler is used, operator patching becomes the way to reduce the size of your shipped app. We've heard of several who are worried about file size but don't use bundling to reduce this (and reduce |
@jayphelps we don't bundle in Nuclide – for various reasons: we have several node binary modules, code in multiple languages (python and Java), and Nuclide is actually two apps the "client" and the "server" (we'd need two bundles - more dev overhead). All of these make bundling more complicated than what we're willing to deal with right now. Our concern is not so much with size but load times - though there's some correlation between the two, that's not always the case. Since bundling is not option right now, the next best thing is to load the UMD bundle - which is considerably faster to load than the unbundled entry point. This is transparent to devs because at transpile time, we convert the source on Loading
I'd love it if the UMD bundle were brought down to the root of the package - so that it's easier to manually require in scripts. Maybe rename |
@jayphelps we don't bundle it as well due to similar reason to nuclide. In short, when it comes electron having various native-binary modules, it is not trivial effort to setup bundler (to exclude those modules, and setup other routing to load those modules as well) in addition to it requires 2 set of bundles eventually, one for main process and other for browser renderer process. What we do in our codebase for Rx is straightforward - instead of import everything, import patch operator individually for necessary ones. (import '.../add/../xxx') |
Oh, and we don't patch import operators because we don't have a way to enforce via flow that you didn't forget something. |
@zertosh yup, we're able to do it since we're using TypeScript in our codebase. |
Interesting... @kwonoj can you show me what that looks like? |
@zertosh idea's simple - as latest typescript compiler (or language service) do understands module argumentation, if you write any consumer code like import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/of';
Observable.of //type inference will work since language service accepts module augmentation (I just wrote down code so it might not work via ctrl-v, but I assume you get idea) |
@zertosh @kwonoj @jayphelps it seems after this PR the files in |
@trxcllnt I'm seeing it here: https://unpkg.com/@reactivex/rxjs@5.0.0-rc.1/dist/global/Rx.js Also one of my demo jsbins still works: http://jsbin.com/jexomi/edit?html,js,output Can you clarify? (function (f) {
if(typeof exports === "object" && typeof module !== "undefined") {
module.exports = f()
} else if(typeof define === "function" && define.amd) {
define([], f)
} else {
var g;
if(typeof window !== "undefined") {
g = window
} else if(typeof global !== "undefined") {
g = global
} else if(typeof self !== "undefined") {
g = self
} else {
g = this
}
g.Rx = f()
}
}) |
@jayphelps was this PR included in the rc.1 build? I'm building the project locally and don't have the UMD wrapper. |
@trxcllnt nope! good catch!! I'm seeing the same thing locally. I'll check it out locally tomorrow (unless of course you find it). can you create a ticket to track? related: I've been planning to bring up at our next meeting the idea of publishing canary builds of master to npm. The community could then run their CI against it to keep an eye out for breaking changes and also bug us if we break something unknowingly before we cut a real release. |
@zertosh any initial thoughts? |
I think |
@Brooooooklyn we're talking about UMD bundles, which cannot have ES modules in them (would be a syntax error) were you maybe missing a step in there or am I misunderstanding? |
@jayphelps rollup is able to bundle ES6 module to UMD without babel, and if your code is compiled to ES5 by TypeScript using I've do such things for a long time in our project https://github.com/teambition/teambition-sdk/blob/master/tools/tasks/bundle.ts#L32 😉 |
@jayphelps I used it in node so CJS was enough. I'll add the UMD wrapper - sorry. @Brooooooklyn If you do |
My worry about this pull request is you introduce babel here, and there is |
I'd agree in general to have different transpilers in build chain is not ideal, it's tempting options to use TSXC entirely to generate global builds. |
Summary: This version has the optimized bundle from ReactiveX/rxjs#2064 ReactiveX/rxjs@5.0.0-rc.1...5.0.0-rc.2 Reviewed By: nmote Differential Revision: D4138010 fbshipit-source-id: 93c012b715b7c0b2a9127db627379160aff24487
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR changes how the "Global" (aka umd) build is bundled and transpiled.
Before: TS-to-ES5 -> Browserify
After: TS-to-ES6 -> Rollup -> Babel-to-ES5
The new build is considerably smaller and loads much faster:
To test load time, I ran
for i in {1..5}; do node -p "s=Date.now();require('path/to/bundle');Date.now()-s"; done
.A few notes: