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

Provide first-class support for multiple explicitly chosen UMD versions #126

Closed
nickserv opened this issue Aug 21, 2018 · 5 comments
Closed

Comments

@nickserv
Copy link

Cross posting @gaearon from facebook/react#13450 (comment):

Unpkg could provide first-class support for multiple explicitly chosen UMD versions.
For example:

https://unpkg.com/react:development
https://unpkg.com/react:production

https://unpkg.com/react-dom:development
https://unpkg.com/react-dom:production

This works with versions too:

https://unpkg.com/react-dom:[email protected]

Since : is reserved, it won't cause clashes.

This could work by special fields in package.json, e.g.

 "umd:development": "umd/react.development.js",
 "umd:production": "umd/react.production.js"

For packages that opted into this, unpkg could display a better error page when you attempt to load https://unpkg.com/react directly — and show disambiguating links right there. Seems like best of both worlds to me.

@nickserv
Copy link
Author

nickserv commented Aug 21, 2018

I'm also thinking we should give packages the possibility of a network error like 404 on the default /PACKAGE_NAME route if there isn't a single default entry point and a specific entry point is required, like with React.

@gaearon
Copy link

gaearon commented Aug 21, 2018

I think it's odd that https://unpkg.com/react gives me a CommonJS entry point. Why is this useful? Do lots of packages publish UMD as main entry points?

@nickserv
Copy link
Author

nickserv commented Aug 21, 2018

I think the assumption is that some npm packages have a default entry point in main that's already web compatible (for example, jQuery), or that it at least might work when the package has one file and no dependencies. umd is more of a web-friendly guarantee though.

I can see how defaulting to CJS is confusing, but we definitely don't want to break packages as big as jQuery.

@mjackson
Copy link
Member

We default to using main because some packages publish web-friendly versions there. In hindsight, it probably wasn't the best decision because not a lot of packages do that. There are a few major exceptions, like jQuery. But most packages that are published to npm point to a CJS version with main.

However, I have a feeling it's also useful for people who are building tooling on top of unpkg, like bundlers. Our URLs work like the file system, with similar semantics to CommonJS' require function.

That said, we do provide a convenient way to override the default behavior for package authors using the unpkg field. You can use this field to point to a UMD version and that will be served as the default. e.g. d3 uses the unpkg field to override main on unpkg.com:

screen shot 2018-08-27 at 10 27 27 am

Unpkg could provide first-class support for multiple explicitly chosen UMD versions.

Please see #93 for my current thoughts on this.

@nickserv
Copy link
Author

Thanks, I'll mark this as a duplicate and continue in #93.

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