-
Notifications
You must be signed in to change notification settings - Fork 109
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
How to control which distribution of a dependency gets used #102
Comments
It's hard to guess the best default here that works for everyone. And while we could make it configurable, the problem is that it takes effect globally. Apps and addons all need to agree, or they will break each other's dependencies. (Lots of things about webpack config are not composable, in the sense that separate packages cannot have their own opinions about their own dependencies.) There is a workaround you can use for your specific case. You can set an alias for the particular library you use that picks the exact entrypoint you really want: // In your ember-cli-build.js file
let app = new EmberApp(defaults, {
autoImport: {
alias: {
'the-library': 'the-library/path/to/modules/entrypoint'
}
}
}); The downside of this is that it effectively hard codes the current value of the library's |
Thanks! That seems like a perfectly reasonable workaround.
I think that would be useful. I think you could get away w/ using |
@ef4 could you explain what kind of breakage can be expected, e.g. when importing an ESM build instead of UMD? This turns out to be a bit annoying as I believe most users expect that Also for addons that depend on |
If the library ships with a browser build, that's a pretty clear decision from the library author about how they think their library should be used in browsers. Prioritizing Also, we currently follow the webpack defaults. Since webpack is so popular, I think library authors are more likely to test their library with the webpack defaults than with any alternative config. I hear what you're saying, but we're really just stuck here with the state of the art of NPM package metadata. |
The problem is that people use |
Got it, yeah, that would be bad! 😩 Unfortunately then a lot of library (and library boilerplates) come with a rollup/etc. config that does this, even when they are browser-only or "isomorphic":
|
You had me at
FWIW - I think you should keep doing that. :) |
There is some good discussion here, and looks like all questions are resolved! 🎉 if that happens to not be the case, please feel free to open a new issue with more questions 🥳 |
My addon depends on a library that is distributed as CJS, ESM, and UMD, as the package
main
,module
, andbrowser
fields respectively.I'm still learning how ember-auto-import works, but what I think I want is have it import the ESM files so that webpack can tree shake them as they get brought into the app, right?
However, it appears that what is being brought in is the UMD files, I'm guessing b/c this line gives preference to the
browser
field:https://github.com/ef4/ember-auto-import/blob/0dadde0de99a107bc51f26304c504cc3b91ffe46/ts/splitter.ts#L18
Is there a way to give preference to the
module
field so that ESM files will be used instead?The text was updated successfully, but these errors were encountered: