 {"id":456,"date":"2021-01-18T12:36:02","date_gmt":"2021-01-18T20:36:02","guid":{"rendered":"https:\/\/www.mavice.com\/blog\/?p=456"},"modified":"2021-03-03T11:45:12","modified_gmt":"2021-03-03T19:45:12","slug":"visualizing-the-size-of-your-vue-react-angular-bundles","status":"publish","type":"post","link":"https:\/\/www.mavice.com\/blog\/visualizing-the-size-of-your-vue-react-angular-bundles\/","title":{"rendered":"Visualizing the Size of your Vue\/React\/Angular Bundles"},"content":{"rendered":"\n<p>Knowing exactly what and how much each individual bundle in your project is used can help you optimize your project. If your web application is packaged with <a href=\"https:\/\/webpack.js.org\/\" data-type=\"URL\" data-id=\"https:\/\/webpack.js.org\/\">Webpack<\/a>, there are a few ways you can analyze your bundles.<\/p>\n\n\n\n<h2>Analyzing Bundles<\/h2>\n\n\n\n<p>There is a handful of third-party packages that will allow you to get a more detailed view of exactly what modules in your application are being used and how significant they are to your project in terms of size. \u201c<a rel=\"noreferrer noopener\" href=\"https:\/\/www.npmjs.com\/package\/webpack-bundle-analyzer\" target=\"_blank\"><strong>webpack-bundle-analyzer<\/strong><\/a><strong>\u201d<\/strong> is one that I use frequently. This plugin renders and opens a webpage with information about your bundles after you run a build. It also gives you three separate views: parsed, stat, and gzipped.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"800\" height=\"617\" src=\"https:\/\/www.mavice.com\/blog\/wp-content\/uploads\/2021\/01\/1_V9EG7W-TnuOPw4jaIRzo0w.jpeg\" alt=\"\" class=\"wp-image-457\" srcset=\"https:\/\/www.mavice.com\/blog\/wp-content\/uploads\/2021\/01\/1_V9EG7W-TnuOPw4jaIRzo0w.jpeg 800w, https:\/\/www.mavice.com\/blog\/wp-content\/uploads\/2021\/01\/1_V9EG7W-TnuOPw4jaIRzo0w-300x231.jpeg 300w, https:\/\/www.mavice.com\/blog\/wp-content\/uploads\/2021\/01\/1_V9EG7W-TnuOPw4jaIRzo0w-768x592.jpeg 768w, https:\/\/www.mavice.com\/blog\/wp-content\/uploads\/2021\/01\/1_V9EG7W-TnuOPw4jaIRzo0w-360x278.jpeg 360w, https:\/\/www.mavice.com\/blog\/wp-content\/uploads\/2021\/01\/1_V9EG7W-TnuOPw4jaIRzo0w-640x494.jpeg 640w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><figcaption>webpack-bundle-analyzer rendered page after running \u201cvue-cli-service build\u200a\u2014\u200amode production\u201d<\/figcaption><\/figure>\n\n\n\n<h3>How to use<\/h3>\n\n\n\n<p>Open a terminal with the path to your application and execute the command <strong>npm install\u200a\u2014\u200asave-dev webpack-bundle-analyzer.&nbsp;<\/strong><\/p>\n\n\n\n<p>Next, locate the <strong>webpack.config.js<\/strong> file within your project and add this to the plugins property.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;\n\nmodule.exports = {\n   plugins: [\n      new BundleAnalyzerPlugin()\n   ]\n}\n<\/code><\/pre>\n\n\n\n<p>After this is added, build your project and when it is finished you will see a rendered page load up in your browser.<\/p>\n\n\n\n<p><em>If you are using Vue CLI with a Vue application, the Vue CLI already has a build configuration packaged with the webpack-bundle-analyzer. Just run vue-cli-service build &#8211;report and it will generate a report.html file within your \/dist folder.<\/em><\/p>\n\n\n\n<h3>Report Detail<\/h3>\n\n\n\n<p>In the report, you should notice three levels of bundle sizes.<\/p>\n\n\n\n<ul><li>Stat &#8211; Obtained from <a href=\"https:\/\/webpack.js.org\/configuration\/stats\/\">webpack&#8217;s stats object<\/a>, the &#8220;input&#8221; size of your files, before any transformations like minification.<\/li><li>Parsed &#8211; This is the &#8220;output&#8221; size of your files including minification and any other plugins that are augmenting the output files.<\/li><li>Gzipped &#8211; The size of your bundles after running them through gzip compression.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"323\" height=\"189\" src=\"https:\/\/www.mavice.com\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-18-at-3.27.58-PM.png\" alt=\"\" class=\"wp-image-458\" srcset=\"https:\/\/www.mavice.com\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-18-at-3.27.58-PM.png 323w, https:\/\/www.mavice.com\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-18-at-3.27.58-PM-300x176.png 300w\" sizes=\"(max-width: 323px) 100vw, 323px\" \/><\/figure><\/div>\n\n\n\n<p>Check out the <a href=\"https:\/\/www.npmjs.com\/package\/webpack-bundle-analyzer\">official npm page<\/a> for the &#8220;webpack-bundle-analyzer&#8221; to see all of the options and properties you could use to get more information about your bundles.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Knowing exactly what and how much each individual bundle in your project is used can help you optimize your project. If your web application is packaged with Webpack, there are a few ways you can analyze your bundles. Analyzing Bundles There is a handful of third-party packages that will allow&#8230;<\/p>\n","protected":false},"author":2,"featured_media":466,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":[],"categories":[39],"tags":[43,42,41,40],"_links":{"self":[{"href":"https:\/\/www.mavice.com\/blog\/wp-json\/wp\/v2\/posts\/456"}],"collection":[{"href":"https:\/\/www.mavice.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mavice.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mavice.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mavice.com\/blog\/wp-json\/wp\/v2\/comments?post=456"}],"version-history":[{"count":3,"href":"https:\/\/www.mavice.com\/blog\/wp-json\/wp\/v2\/posts\/456\/revisions"}],"predecessor-version":[{"id":488,"href":"https:\/\/www.mavice.com\/blog\/wp-json\/wp\/v2\/posts\/456\/revisions\/488"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mavice.com\/blog\/wp-json\/wp\/v2\/media\/466"}],"wp:attachment":[{"href":"https:\/\/www.mavice.com\/blog\/wp-json\/wp\/v2\/media?parent=456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mavice.com\/blog\/wp-json\/wp\/v2\/categories?post=456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mavice.com\/blog\/wp-json\/wp\/v2\/tags?post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}