dataflow
dataflow copied to clipboard
More import options
Only observablehq and local imports are supported now. Here are other places we should support importing from:
- [ ] Any
.js
file on the internet that has aexport default function define()
definition - [ ] Any local
.js
file that has aexport default function define()
definition - [ ] Github (proxy to raw.githubusercontent.com)
- [ ] gists
- [ ] NPM (maybe should just document how to use https://www.jsdelivr.com instead of doing npm resolution ourselves
+1 on the npm import. Is there a way to use jsdelivr now?
@Jiahao01121 yup, Dataflow uses the same require
functions as the notebooks on Observable, which uses d3-require under the hood. So
// notebook.ojs
moment = require("moment")
moment(new Date)
imports moment from jsdelivr.
+1 for local imports, this can be a big + vs observablehq for local js dev
I use a workaround to bring local js into observablehq, which also works for dataflow, but dataflow workflow has much nicer potential with local imports
(workaround = https://observablehq.com/@observablehq/require section URL)
For gists, etc., this works for me in the import resolver:
fetch(path)
.then((res) => res.text())
.then((js) => {
const blob = new Blob([js], {
type: 'text/javascript',
});
const objectURL = URL.createObjectURL(blob);
return objectURL;
})