Add polyfill to Angular library
Asked Answered
A

1

10

Is there a way within an Angular CLI project to have a library provide a polyfill? Within angular.json, the main app is by default configured with "polyfills": "src/polyfills.ts". This option is not available for a library project.

My specific use case is that my library has a dependency that requires a polyfill. Without the ability of the library automatically providing the polyfill upon it being imported in an application, I need to document and inform the library user of adding the polyfill themselves.

Addams answered 13/9, 2018 at 17:23 Comment(4)
I created a feature request on the Angular CLI repo. Let's see if anything comes of it.Addams
Seems like they are never going to implement something like that, for everybody looking for this.Sempach
@SamHerrmann can you close this ticket, since the Feature request is closed , there is no point for this ticket.Fontana
Thanks for the reminder Jeba Prince, I have closed this question.Addams
A
6

This capability is not available in the CLI and it will not become available for good reasons. The following is A. Agius' comment on the GitHub issue that I had created to enquire about this feature:

IMHO, a library should never bundle a polyfill. It’s up to the consumers of the library based on their targeted browsers to include a polyfill or not.

If I want to target only ever green browsers I certainly don’t want that a library that I am using has an embedded polyfill.

As an application develop, I don’t want to end up having duplicate polyfills for the same thing, because it was already shipped in library that I am using.

Addams answered 26/3, 2019 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.