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

Add unpkg and jsdelivr fields to point to browser build #523

Merged
merged 1 commit into from
Nov 1, 2019

Conversation

tmcw
Copy link
Contributor

@tmcw tmcw commented Nov 1, 2019

This adds unpkg & jsdelivr fields to package.json so that unpkg & jsdelivr can automatically find the right build to serve for browsers (and so can tools like d3-require).

@puzrin puzrin merged commit 3e93973 into nodeca:master Nov 1, 2019
@puzrin
Copy link
Member

puzrin commented Nov 28, 2020

Hm... seems this is not actual:

Could you comment? I plan to cleanup garbage in 4.0

@tmcw
Copy link
Contributor Author

tmcw commented Nov 30, 2020

Sure, if you look at the page https://www.jsdelivr.com/package/npm/js-yaml, the dist file is at the top and is marked as the "default file", and if you follow the patterns from the jsdelivr homepage and use the "default file" form, you get the correct file: https://cdn.jsdelivr.net/npm/js-yaml - and in versions before that PR, you don't: https://cdn.jsdelivr.net/npm/js-yaml@2

Similarly, https://unpkg.com/js-yaml refers to the correct default file and in previous versions, it refers incorrectly to the commonjs entry point: https://unpkg.com/js-yaml@2

Both unpkg & js-yaml have listing pages like the one you link, but the benefit of this PR is that their "default file" endpoints - what d3-require uses, and what people can use in their script tags - need this additional information to refer to the correct dist.

@puzrin
Copy link
Member

puzrin commented Nov 30, 2020

Ah, i'm not familiar with "serverless" webdev. Always thinked people use something like https://cdn.jsdelivr.net/npm/js-yaml@3/dist/js-yaml.min.js in script tag or web loaders.

What happens when i add .mjs build? /dist usually contains multiple builds like this: https://github.com/nodeca/pako/tree/master/dist. Does a partial [incomplete] solution worth keeping such indirect magic?

@tmcw
Copy link
Contributor Author

tmcw commented Nov 30, 2020

Yes - people should just use that URL in their script tag, to avoid the redirect. And the jsdelivr field in package.json helps them do that - before this PR, the page for js-yaml (here's the page for 3.1.0) would incorrectly recommend that they use the commonjs file in their script tag.

Mjs builds tend to be opt-in with all the systems and they all behave differently. unpkg's ?module option will use the module field in package.json instead of the unkpg field, and it looks like jsdelivr splits that off into a separate service, esm.run, which will also use the other field https://www.jsdelivr.com/esm

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

Successfully merging this pull request may close these issues.

2 participants