Angular CLI - 为什么<ng serve>捆绑比<ng build>更好? [英] Angular CLI - why does <ng serve> bundle better than <ng build>?

查看:25
本文介绍了Angular CLI - 为什么<ng serve>捆绑比<ng build>更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行一些 Angular CLI 命令以构建缩小的基本项目:

Performing a number of Angular CLI commands in order to build the minified basic project:

ng new project
cd project
ng build --prod

... 结果,我得到了生成的 dist 文件夹,其中包含许多包.最大的一个叫做vendor.[hash].js,它的大小约为855kB.

... as a result, I get the generated dist folder with a number of bundles. The largest one is called vendor.[hash].js and it's size about 855kB.

但是,如果我执行 ng serve --prod 代替:

However, if I perform ng serve --prod instead:

ng new project
cd project
ng serve --prod

...我可以看到由 localhost:4200 供应商加载的包重量约为 300kB 使用 Chrome 控制台.

... I can see the loaded by localhost:4200 vendor's bundle weight is about 300kB using Chrome console.

为什么会这样?有没有办法不用 ng serve 而用 ng build 来实现第二个结果?

Why is that happens? Is there a way to achieve the second result without ng serve but rather with ng build?

推荐答案

正如通过评论发现的,您只是比较了两个不同的值:文件系统中非 gzipped 文件的大小,以及 gzipped 文件的大小在浏览器控制台中下载.

As was discovered through the comments, you simply compared two different values: the size of the non-gzipped file in the file system, and the size of the gzipped download in the browser console.

这篇关于Angular CLI - 为什么<ng serve>捆绑比<ng build>更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆