nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
22.6k stars 2.26k forks source link

enable polyfills for older browsers #26452

Open MeMeMax opened 3 weeks ago

MeMeMax commented 3 weeks ago

Documentation issue

Is there a specific documentation page you are reporting?

browser-support

Additional context or description

I have a nx angular project which has to support Chrome 88. In Chrome 88 the function string.prototype.at() was not available yet. Therefore I created a .browserslistrc to polyfill the missing functions. This is my .browserslistrc

Chrome >= 88
Edge >= 88
Firefox >= 80

When looking into the documentation it states: The official Nx plugins rely on [browserslist](https://github.com/browserslist/browserslist) for configuring application browser support. This affects builds, both production and development, and will decide on which transformations will be run on the code when built.

This implies for me that changing the .browserslistrc nx/babel/.browserslistrc takes care of providing polyfills for the specified browsers. Unfortunately when testing my application on a chrome 88 the string.prototype.at() function is not available.

Looks like I have to do more than just providing the .browserslistrc but nothing is mentioned in the documentation.

MeMeMax commented 3 weeks ago

I did a bit of research on this. Looks like Angular itself doesn't provide automatic polyfilling through babel according to this github issue: https://github.com/angular/angular-cli/issues/27510

From my perspective this would be a great feature to avoid manual work (research on the necessary polyfills for a specific browser version). I wonder if that would be achieveable through nx even if angular doesn't want to implement it?

MillerSvt commented 3 weeks ago

I wonder if that would be achieveable through nx even if angular doesn't want to implement it?

👍 I disagree with Angular's decision not to implement autopolyfills. It would be nice to have this implemented at least in nx...

In general, we need to add an option for auto-polyfills (default is disable). Also we need the ability to specify a list of node_modules libraries that should be processed, and path to browserlists file (default <projectRoot>/.browserslist)