My RxJs code is currently running on Node, compiling to Script.js after TS compilation with the following lines:
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
...
Now, I want to run this code in a Browser. The first step is to address module support on the Browser, which can be achieved with this initial script:
<script>var exports = {};</script>
I'm not sure about the theoretical correctness, but it seems to be working. The next step for me is to install and configure Require.JS, like so:
<script src="http://requirejs.org/docs/release/2.3.6/comments/require.js"></script>
<script type="text/javascript">
require.config({
paths: {
"rxjs": "https://cdnjs.cloudflare.com/ajax/libs/rxjs/7.8.1/rxjs.umd.min.js",
"jquery": "https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min"
}
});
</script>
<script type="text/javascript">
require( ["jquery"],
function ($) {
console.log($("#myButton").val())
}
);
</script>
I don't currently need jQuery, I'm just testing how Require.JS functions with it. It seems to be working fine. However, the next challenge is linking RxJS and RxJs/Operator correctly - any suggestions on achieving this? I tried replacing () with [] in my Script.JS as required by RequireJS, starting from:
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require["rxjs"];
var operators_1 = require["rxjs/operators"];
...
But the Browser throws an error stating "Uncaught TypeError: rxjs_1 is undefined", indicating that RxJS is not loaded and its functions are not defined. How do I resolve this issue (without just defining the root namespace of RxJS, but also RxJS/Operators)?