关闭。这个问题需要details or clarity .它目前不接受答案。
想改进这个问题?通过 editing this post 添加详细信息并澄清问题.
去年关闭。
Improve this question
以下是我创建示例 Angular 应用程序的步骤:
npm i -g @angular/cli
(已安装 Angular 11.2)ng new foo
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。以我的思维方式,这应该需要很少的 polyfills。这些 36kb 有什么作用?我很难说,因为文件被缩小了。
最佳答案
即使您删除 .browserlistrc
或注释掉所有内容,你会得到:35.98 kB
.
就这一行,browserlist
回退到 defaults
的值,其中包括:> 0.5%, last 2 versions, Firefox ESR, not dead
请注意,这些默认值主要与 Zone.js 支持相关,您可以自己查看。试试 ng build
没有 --prod
标记,你会得到一个注释很好的 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
*/
在 https://angular.io/guide/browser-support 中了解更多信息
关于javascript - 当我的 browserslist 只是 `last 1 Chrome version` 时,为什么我的 Angular 应用程序的 polyfills.js 是 36kb?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66657659/