Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More import options #10

Open
5 tasks
asg017 opened this issue May 2, 2021 · 4 comments
Open
5 tasks

More import options #10

asg017 opened this issue May 2, 2021 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@asg017
Copy link
Owner

asg017 commented May 2, 2021

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 a export default function define() definition
  • Any local .js file that has a export 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
@asg017 asg017 modified the milestones: v1, Beta May 2, 2021
@asg017 asg017 added the enhancement New feature or request label May 2, 2021
@Jiahao01121
Copy link

+1 on the npm import. Is there a way to use jsdelivr now?

@asg017
Copy link
Owner Author

asg017 commented May 18, 2021

@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.

@declann
Copy link

declann commented May 30, 2021

+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)

@a10k
Copy link

a10k commented Jun 4, 2021

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;
      })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants