Angular-cli: Feature request: Add ability to add polyfill in library

Created on 19 Oct 2018  路  5Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [X] feature request

Command (mark with an x)

- [ ] new
- [X] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

node --version:

v10.11.0

npm --verison

6.4.1

ng --version:

Angular CLI: 6.1.1
Node: 10.11.0
OS: linux x64
Angular: 6.1.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.7.1
@angular-devkit/build-angular 0.7.1
@angular-devkit/build-ng-packagr 0.7.1
@angular-devkit/build-optimizer 0.7.1
@angular-devkit/build-webpack 0.7.1
@angular-devkit/core 0.7.1
@angular-devkit/schematics 0.7.1
@angular/cli 6.1.1
@ngtools/json-schema 1.1.0
@ngtools/webpack 6.1.1
@schematics/angular 0.7.1
@schematics/update 0.7.1
ng-packagr 3.0.6
rxjs 6.2.2
typescript 2.9.2
webpack 4.9.2

Current behavior

If I build an Angular library that has a dependency and that dependency requires a polyfill, I need to inform the consumer of my library to add the polyfill to their application polyfill.ts. The CLI does not provide the ability to define a polyfill within a library and have it be bundled into the application.

Desired functionality

The desired behavior is to enable libraries to include the polyfill and abstract that knowledge from the library consumer.

In angular.json, a polyfills field exists for the @angular-devkit/build-angular:browser builder. Is it possible to add a polyfills field for the @angular-devkit/build-ng-packagr:build builder?

Mention any other details that might be useful

I asked if this feature was available on StackOverflow. Based on the up votes on the question it appears that I am not the only one with this use case.

library feature

Most helpful comment

IMHO, a library should never bundle a polyfill. It鈥檚 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鈥檛 want that a library that I am using has an embedded polyfill.

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

All 5 comments

IMHO, a library should never bundle a polyfill. It鈥檚 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鈥檛 want that a library that I am using has an embedded polyfill.

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

@alan-agius4 that is a very good point!

I will close this issue since @alan-agius4's response is pretty convincing to me :smile:

@alan-agius4 I think this could be worth reopening. What if we want to compile a library as a web component to be reused in any framework? Then we should be able to add the following:

import "@webcomponents/custom-elements/src/native-shim";
import "@webcomponents/custom-elements/custom-elements.min";

Unless there is a guideline I'm not aware of?

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rwillmer picture rwillmer  路  3Comments

MateenKadwaikar picture MateenKadwaikar  路  3Comments

JanStureNielsen picture JanStureNielsen  路  3Comments

brtnshrdr picture brtnshrdr  路  3Comments

hareeshav picture hareeshav  路  3Comments