How to use RxJs with Require.JS

40 Views Asked by At

I try to use RxJs with Require.JS on Html page (without Angular or WebPack), this is my test

    <script src="http://requirejs.org/docs/release/2.3.6/comments/require.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/7.8.1/rxjs.umd.min.js"></script>
    <script type="text/javascript">
    require.config({
      paths: {
          "rxjs": "https://cdnjs.cloudflare.com/ajax/libs/rxjs/7.8.1/rxjs.umd.min.js"
      }
    });
    require (['rxjs'], (x) => x.of(1,2,3,4,5).subscribe(console.log));
    //-- before this line all working fine

    var rxjs_1 = require (['rxjs'], (x) => x);
    rxjs_1.of(6,7,8,9,10).subscribe(console.log);
    ....
    </script>

First way working fine, I see on console 1,2,3,4,5, but I don't want rewrite something my huge code and want to receive reference to RxJs in variable rxjs_1 and than simple working with variable rxjs_1.
Something lacks in my code, maybe await or other functions from rxjs_1 obj, current code get me in rxjs_1 variable only ref to 'function localRequire(deps, callback, errback)' instead reference to RxJs and Observable. And, of course, OF() in rxjs_1 is undefined.
What lack in this code?

0

There are 0 best solutions below