Reactive-Extensions / RxJS

The Reactive Extensions for JavaScript
http://reactivex.io
Other
19.48k stars 2.1k forks source link

Why the original Rx.js or Rx.min.js is not possible to use with Angular 2 #1386

Closed mlc-mlapis closed 7 years ago

mlc-mlapis commented 7 years ago

Hello,

there is a long discussion on an issue with using Rx.js or Rx.min.js (distributed as bundles with RxJS) at Angular 2 repo (https://github.com/angular/angular/issues/9359).

The main problem is that it is not possible to use directly the original files Rx.js or Rx.min.js and it is necessary to re-bundle RxJS sources first to a custom bundle which works correctly:

gulp.task('rxjs', function() {
    // SystemJS build options
    var options = {
        normalize: true,
        runtime: false,
        sourceMaps: true,
        sourceMapContents: true,
        minify: true,
        mangle: true
    };
    var builder = new systemjsbuilder('./');
    builder.config({
        paths: {
            "n:*": "node_modules/*",
            "rxjs/*": "node_modules/rxjs/*.js",
        },
        map: {
            "rxjs": "n:rxjs",
        },
        packages: {
            "rxjs": {main: "Rx.js", defaultExtension: "js"},
        }
    });
    builder.bundle('rxjs', './src/rxjs-bundle/Rx.min.js', options);
});

The size of a custom re-bundled file Rx.min.js (for 5.0.0-rc.5) is 262 488 Bytes and the original one is 139 368 Bytes.

Can anybody know how to explain this difference or answer what exactly the original Rx.min.js is and for what is intended?

mlc-mlapis commented 7 years ago

The answer is evident. Thanks to @robwormald from NG2 core team. Both files (Rx.min.js and Rx.js) have internally UMD structure (and not System.register that is possible to use with SystemJS loader) and that is why they can not be used directly with NG2 (deep import is not possible).