从'rxjs/Observable'导入{Observable}与从'rxjs'导入{Observable}有什么区别? [英] is there any difference between import { Observable } from 'rxjs/Observable' and import { Observable } from 'rxjs'?

查看:156
本文介绍了从'rxjs/Observable'导入{Observable}与从'rxjs'导入{Observable}有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在angular 2中使用rxjs时 之间有什么区别 import { Observable } from 'rxjs/Observable'import { Observable } from 'rxjs'?

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

推荐答案

是的,捆绑包大小略有不同.如果您没有使用像rollup.js这样的摇摇晃晃的库来删除所有不必要的代码,则从'rxjs'导入时,您的包将很大,因为即使您仅使用Observable,也要导入所有内容.另一方面,如果您从"rxjs/Observable"导入,则只会导入所需的内容,并且捆绑包会更小.

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)

参考: https://github.com/ReactiveX/rxjs

这篇关于从'rxjs/Observable'导入{Observable}与从'rxjs'导入{Observable}有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆