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

Loading through a script tag misses many exports #280

Open
eliemichel opened this issue Nov 5, 2023 · 3 comments
Open

Loading through a script tag misses many exports #280

eliemichel opened this issue Nov 5, 2023 · 3 comments

Comments

@eliemichel
Copy link

If I try to simply include microformats using the script tag provided in the readme, I can only get CID, bytes, digest, hasher and varint:

<script src="https://unpkg.com/multiformats/dist/index.min.js"></script>
<script>
console.log(Multiformats);
</script>

image

Either the README misses something, or the dist/index.min.js does! For instance how can I get codecs from multiformats/codecs?

@rvagg
Copy link
Member

rvagg commented Nov 6, 2023

yeah, so that would be bundling https://github.com/multiformats/js-multiformats/blob/master/src/index.js but it sounds like you're after a more comprehensive https://github.com/multiformats/js-multiformats/blob/master/src/basics.js

@achingbrain what's the logic for aegir build and does it afford any ability to also bundle basics.js into a single package or is this too much of a technical stretch with the tools we have?

@eliemichel if you have the ability to bundle & serve a package for yourself, then basics.js would be the one you want if you don't want to be more selective in the pieces you want. It sounds like you're wanting something externally hosted though.

@achingbrain
Copy link
Member

Currently aegir is hard-coded to bundle the index file into index.min.js but it's because that code predates the rise of the exports map so it assumes a single entry point for a given module.

If a package.json has an exports map, there's no reason why we couldn't build a separate bundle for every entry instead.

@eliemichel
Copy link
Author

@eliemichel if you have the ability to bundle & serve a package for yourself, then basics.js would be the one you want if you don't want to be more selective in the pieces you want. It sounds like you're wanting something externally hosted though.

I typically use direct script tags when I want to quickly test a library from a single index.html file without setting up any sort of webpack and whatnot, to decide whether I will actually adopt it for a more solid project (however fast my package manager is, no package manager at all remains the fastest path for quick testing). So... if I have to build my own dist it kind of defeats the purpose.

In this use case, I am ok with downloading a couple of .js files to serve them next to my index.html, though the unpkg CDN is a nice plus.

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

No branches or pull requests

3 participants