Angular6基础(三):使用webpack bundle analyzer(可视化)分析打包文件大小

One of the most important factors to improve the loading performance of a web app is its bundle size.Here we’ll go over how to use tool to easily analyze your app’s bundle size: webpack bundle analyzer.

First, install webpack-bundle-analyzer in your project as a dev dependency.

npm install webpack-bundle-analyzer --save-dev

Then, build your app for production using the Angular CLI and specify the --stats-json so that the webpack stats data gets exported too in the dist folder.

ng build --prod --stats-json

Next, add a new npm script that calls webpack-bundle-report in package.json file.

"bundle-report": "webpack-bundle-analyzer dist/[projectName]/stats.json"

Now, run the local webpack-bundle-analyzer against the stats.json file using npm.

npm run bundle-report

You will get the bundle report like below.


image
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • This project was bootstrapped with Create React App. Belo...
    unspecx阅读 5,232评论 0 2
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,460评论 0 10
  • 上学20年,人生25年,第一次被人说字丑。。。。 小学老师夸写字好看,让我改作业出板报;初中后,身边写字好看的人越...
    lxwvvv阅读 507评论 1 1
  • 325期。。 绝杀26789尾! 参考出尾34尾为今天重点关注和尾!
    张巍宝阅读 191评论 0 0
  • 更大的心,才有更大的世界。 一直也没有去过日本,之前对日本的关注也不是很多,虽然在日本公司工作过,但对日本...
    金三十阅读 844评论 0 50