-
-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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 a way to configure the mainFields
for webpack
#8139
Provide a way to configure the mainFields
for webpack
#8139
Comments
Thanks for the suggestion! I don't think we're interested in supporting this at the moment; create-react-app is pretty against adding additional configuration except when it's necessary, and this is more of a performance optimization. Maybe we could add more resolutions by default if the community rallies more around a standard. I'm not very knowledgeable here though, so maybe that's already happened with |
@heyimalex what is the current code generation strategy for react scripts? Will they create ES5 code or ES2015 code. In the typescript case I assume that they will use what's defined in Would it be possible to add |
We use babel/preset-env and browserslist. It’s not so much that I don’t want to handle ES2015 code in node_modules (I’m pretty sure we currently do), but that I’m not sold on It’s also just easier to punt on this than to expect packages used by our end-users to have their I also can see the benefit, and maybe I’m overthinking it. Also I don’t speak for the whole team. I just got really strong deja vu and I actually think this has been discussed before, so maybe we should find that issue hahaha. |
Thanks for the explanation. I understand your conservative approach on this, once introduced it will be hard to remove it in the future if it turned out to be the wrong decision. Standardization on the module entry points in A sort of de-facto standard I am aware of is the Angular Package Format (https://goo.gl/jB3GVv). Despite having been defined by the competition, this is a concise spec and library generation is also well supported by tools such as So I think it would be a good step to align with APF. |
@CarstenLeue at the end of the README it says that if you need more customization you have alternatives. It seems very outdated. |
The application build relies on the default webpack resolution of entry points for imported libraries, which are
["browser", "module", "main"]
for a web application.Per spec (I believe) the
module
entry contains the ESM5 version of the library, i.e. tree shaken but transpiled to ES5.Some libraries, in particular those built with
ng-packagr
offer additional entry points, such asESM2015
that contains a tree shaken version compiled to ES2015.I suggest that the react scripts allow to override the desired priority order in which entry points are resolved, such that the application author can decide to consume a smaller version of a library (because it has been compiled to ES2015 instead to ES5).
In webpack this is accessible via the https://webpack.js.org/configuration/resolve/#resolvemainfields field, but this configuration is not exposed by react scripts.
The text was updated successfully, but these errors were encountered: