Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

angular - Angular2 2.0.x and Rx 5 beta.12 bundle

I am currently updating the dependencies of my project which uses the Angular2 npm packages and therefore RxJs as well. I am updating to the 2.0.2 stable release of angular which depends on Rx5 beta.12. For my web application i only deploy the Rx.min.js bundle and load it with a script tag in my index.html file. That approach worked perfectly before with the Rx umd bundle, but causes errors meanwhile, since it appears to me that the contributors of RxJs dropped the different bundle versions for the sake of one common bundle file. i.e. Rx.js instead of Rx.umd.js and so on.

I am using SystemJs module loader and if i do no additional steps these errors will occur with any symbol of the RxJs Framework:

GET http://localhost:8080/rxjs/Subject.js 404 (Not Found)

I recognized that Rx is now globally defined (window.Rx) and contains all the necessary stuff. So i tried to define those symbols in SystemJs manually by doing smth like this:

function defineGlobalModule( parentModuleName, simpleName, moduleValue ) {
  var fqModuleName = parentModuleName + simpleName;
  System.amdDefine( fqModuleName, ["require", "exports"], function (require, exports) {
       "use strict";
       exports[ simpleName ] = moduleValue;
  }); 

  if( typeof moduleValue === "object" )
     for( var key in moduleValue )
       defineGlobalModule( fqModuleName + "/", key, moduleValue[ key ] )
}

defineGlobalModule( "", "rxjs", global.Rx );

That made the 'rxjs/Subject' style imports work again. But now i get lots of errors like this:

GET http://localhost:8080/rxjs/operator/toPromise.js 404 (Not Found)
GET http://localhost:8080/rxjs/observable/fromPromise.js 404 (Not Found)

These files are imported by the angular forms.umd.js bundle for example.

What is the state of the art for Angular2 2.0.x when it comes to importing the Rx.js bundle without deploying the node_module itself. I need the bundled version! I was using the umd version of the Rx.js bundle before which seems not to exist anymore.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I did maybe exactly what you're looking for with Angular2 and [email protected] which is now distributed as globals and the umd package is probably not supported any more (just as you said):

See live demo: https://plnkr.co/edit/z4gg2XBoQDgYXev0Csuq

Basically, I just updated my SystemJS config:

paths: {
  'rxjs*': 'https://unpkg.com/@reactivex/[email protected]/dist/global/Rx.js'
},

Then I removed rxjs from map list. Now it loads a single Rx.js file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...