首页 > 解决方案 > 在没有模块加载器的 ES6 模块系统(在浏览器中)中使用 rxjs

问题描述

我有来自 npm 的 rxjs v6。我想将它用作import浏览器中使用 ES6 模块的一部分(Chrome v71)

从我在这里看到的https://github.com/ReactiveX/rxjs和我的一般情况来看,看起来我不能将它用作import.

有没有什么小东西我可以把它包装起来(考虑 CDN 包),让我可以将它用作 ES6 模块系统的一部分,而不需要像 Webpack 这样的东西?

标签: javascriptrxjses6-modules

解决方案


https://github.com/ReactiveX/rxjs#cdn

CDN
For CDN, you can use unpkg:

https://unpkg.com/rxjs/bundles/rxjs.umd.min.js

The global namespace for rxjs is rxjs:

const { range } = rxjs;
const { map, filter } = rxjs.operators;

range(1, 200).pipe(
  filter(x => x % 2 === 1),
  map(x => x + x)
).subscribe(x => console.log(x));


推荐阅读