UMD模块的命名导入(UMD不是应该在浏览器中工作吗?Deno似乎类似于浏览器?):
import { range } from "https://unpkg.com/@reactivex/rxjs@6.6.3/dist/global/rxjs.umd.js";
import { operators } from "https://unpkg.com/@reactivex/rxjs@6.6.3/dist/global/rxjs.umd.js";
中的结果
error: Uncaught SyntaxError: The requested module 'https://unpkg.com/@reactivex/rxjs@6.6.3/dist/global/rxjs.umd.js' does not provide an export named 'operators'
error: Uncaught SyntaxError: The requested module 'https://unpkg.com/@reactivex/rxjs@6.6.3/dist/global/rxjs.umd.js' does not provide an export named 'range'
也直接从ES2015 进口
import { range } from "https://unpkg.com/@reactivex/rxjs@6.6.3/dist/esm2015/index.js";
import { filter, map } from "https://unpkg.com/@reactivex/rxjs@6.6.3/dist/esm2015/operators/index.js";
似乎在工作,加载了很多内部模块,然后崩溃:
Download https://unpkg.com/@reactivex/rxjs@6.6.3/dist/esm2015/internal/observable/fromEvent
/// downloads 150 internal modules
Download https://unpkg.com/@reactivex/rxjs@6.6.3/dist/esm2015/internal/util/Immediate.js // 5 minutes later
error: Import 'https://unpkg.com/@reactivex/rxjs@6.6.3/dist/esm2015/internal/symbol/observable.js' failed: 500 Internal Server Error
at https://unpkg.com/@reactivex/rxjs@6.6.3/dist/esm2015/index.js:4:0
RxJS似乎是一个维护得相当好的库-我不认为它打包错误,但由于它确实开始下载内部es2015模块,我认为导入是正确的
更新:UMD的使用仍未解决,目前还不清楚"dist/global/rxjs.UMD.js"是如何工作的
有文献记载——找不到引用——unpkg将esm2015包分解为子包(esm2015/operators/index.js)
但是,找不到从UMD导入的方法:
// @deno-types="https://unpkg.com/rxjs@6.6.3/index.d.ts"
//unpkg
import { range } from "https://unpkg.com/@reactivex/rxjs@6.6.3/dist/esm2015/index.js";
import { filter, map } from "https://unpkg.com/@reactivex/rxjs@6.6.3/dist/esm2015/operators/index.js";
// skypack or pika.dev
import { range }from 'https://cdn.skypack.dev/rxjs'; // WORKS!!!
import { map, filter }from 'https://cdn.skypack.dev/rxjs/operators';
// jspm
import { range } from "https://jspm.dev/npm:rxjs@6.6.3"; // WORKS!!!
import { map, filter } from "https://jspm.dev/npm:rxjs@6.6.3/operators";
// code to verify imports work properly
range(1, 200)
.pipe(
filter((x:number) => x % 2 === 1),
map((x:number) => x + x)
)
.subscribe((x:number) => console.log(x));
/*
2
6
10
14
...
390
394
398
*/
需要进一步研究:
- https://cdn.esm.sh=>quot;esm.sh将用https://deno.land/std/node以支持一些模块在Deno"中工作
- skypack.dev似乎能够支持比最初认为的
import { range } from "https://cdn.skypack.dev/pin/rxjs@v6.6.3-Hu9diWQqdrdn7RiydblX/mode=imports/optimized/rxjs.js";
更多的功能