为什么我的 Angular 应用程序的 polyfills.js 36kb 而我的浏览器列表只是“最后 1 Chrome 版本”?
Why is my Angular app's polyfills.js 36kb when my browserslist is just `last 1 Chrome version`?
以下是我创建示例 Angular 应用程序所采取的步骤:
npm i -g @angular/cli
(已安装 Angular 11.2)
ng new foo
- 选择加入 SASS、Angular 路由器和分析
cd foo
- 将
.browserslistrc
的内容替换为last 1 Chrome version
。 (运行 npx browserslist
然后按预期仅打印 chrome 89
。)
ng build --prod
结果如下:
$ ng build --prod
✔ Browser application bundle generation complete.
✔ Copying assets complete.
✔ Index html generation complete.
Initial Chunk Files | Names | Size
main.feaf6a85348d901578d8.js | main | 211.52 kB
polyfills.00096ed7d93ed26ee6df.js | polyfills | 35.98 kB
runtime.7b63b9fd40098a2e8207.js | runtime | 1.45 kB
styles.09e2c710755c8867a460.css | styles | 0 bytes
| Initial Total | 248.95 kB
Build at: 2021-03-16T14:41:16.954Z - Hash: 57aec26226ae3eb0ee1b - Time: 12529ms
我很惊讶它编译了 36kb 的 polyfill,而我只支持最新版本的 Chrome。按照我的想法,这应该几乎不需要任何 polyfill。
这36kb有什么用?我很难说,因为文件被缩小了。
即使您删除 .browserlistrc
或注释掉所有内容,您也会得到:35.98 kB
.
仅此一行,browserlist
回落到 defaults
的值,其中包括:> 0.5%, last 2 versions, Firefox ESR, not dead
请注意,这些默认值主要与 Zone.js 支持相关,如您所见。尝试不带 --prod
标志的 ng build
,您会得到一个注释很好的 polyfills 文件:(仅显示前几行,对于 .browserlistrc
:last 1 Chrome version
)
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main^M
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/guide/browser-support
*/
中了解更多
以下是我创建示例 Angular 应用程序所采取的步骤:
npm i -g @angular/cli
(已安装 Angular 11.2)ng new foo
- 选择加入 SASS、Angular 路由器和分析
cd foo
- 将
.browserslistrc
的内容替换为last 1 Chrome version
。 (运行npx browserslist
然后按预期仅打印chrome 89
。) ng build --prod
结果如下:
$ ng build --prod
✔ Browser application bundle generation complete.
✔ Copying assets complete.
✔ Index html generation complete.
Initial Chunk Files | Names | Size
main.feaf6a85348d901578d8.js | main | 211.52 kB
polyfills.00096ed7d93ed26ee6df.js | polyfills | 35.98 kB
runtime.7b63b9fd40098a2e8207.js | runtime | 1.45 kB
styles.09e2c710755c8867a460.css | styles | 0 bytes
| Initial Total | 248.95 kB
Build at: 2021-03-16T14:41:16.954Z - Hash: 57aec26226ae3eb0ee1b - Time: 12529ms
我很惊讶它编译了 36kb 的 polyfill,而我只支持最新版本的 Chrome。按照我的想法,这应该几乎不需要任何 polyfill。
这36kb有什么用?我很难说,因为文件被缩小了。
即使您删除 .browserlistrc
或注释掉所有内容,您也会得到:35.98 kB
.
仅此一行,browserlist
回落到 defaults
的值,其中包括:> 0.5%, last 2 versions, Firefox ESR, not dead
请注意,这些默认值主要与 Zone.js 支持相关,如您所见。尝试不带 --prod
标志的 ng build
,您会得到一个注释很好的 polyfills 文件:(仅显示前几行,对于 .browserlistrc
:last 1 Chrome version
)
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main^M
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/guide/browser-support
*/
中了解更多