将 polyfill 添加到 Angular 库
Add polyfill to Angular library
有没有办法在 Angular CLI 项目中让库提供 polyfill?在 angular.json
内,主应用程序默认配置为 "polyfills": "src/polyfills.ts"
。此选项不适用于库项目。
我的具体用例是我的库有一个需要 polyfill 的依赖项。如果库无法在应用程序中导入 polyfill 时自动提供 polyfill,我需要记录并通知库用户自己添加 polyfill。
此功能在 CLI 中不可用,并且出于充分的原因将无法使用。以下是我为查询此功能而创建的A. Agius' comment on the GitHub issue:
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.
有没有办法在 Angular CLI 项目中让库提供 polyfill?在 angular.json
内,主应用程序默认配置为 "polyfills": "src/polyfills.ts"
。此选项不适用于库项目。
我的具体用例是我的库有一个需要 polyfill 的依赖项。如果库无法在应用程序中导入 polyfill 时自动提供 polyfill,我需要记录并通知库用户自己添加 polyfill。
此功能在 CLI 中不可用,并且出于充分的原因将无法使用。以下是我为查询此功能而创建的A. Agius' comment on the GitHub issue:
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.