is there any difference between import { Observabl

2020-08-27 00:23发布

问题:

When using rxjs in angular 2, is there any difference between import { Observable } from 'rxjs/Observable' and import { Observable } from 'rxjs'?

回答1:

Yes there is a slight difference which is the bundle size. If you aren't using tree shaking library like rollup.js which remove all unnecessary codes, your bundle will be large when importing from 'rxjs' as you are importing everything even if you are using only the Observable. On the other hand if you import from 'rxjs/Observable' you are only importing what you need and the bundle will be smaller.

Import only what you need and patch Observable (this is useful in size-sensitive bundling scenarios)

Ref: https://github.com/ReactiveX/rxjs



标签: angular rxjs