Build and Analyze Your JavaScript Bundles with Poi

John Lindquist
InstructorJohn Lindquist

Share this video with your friends

Send Tweet
Published 4 years ago
Updated 3 years ago

Ever wonder where those extra KB in your bundle are coming from? This lesson walks you through running Poi's build process. Then we'll add a bundle analyzer to find where you may be able to trim down on your file size.

Instructor: [00:00] Build your project with poi build. This creates a dist folder. I'll go ahead and launch the dist folder with http-server and launch that folder. Now this is on 8080. Let's launch that. You can see we now have the same project, exact same content to serve statically now.

[00:17] To analyze our project, let's install the webpack-bundle-analyzer. Then we'll add it to our poi.config. We'll say BundleAnalyzer is the ('webpack-bundle-analyzer').BundleAnalyzerPlugin. Then we can add that to our plugins by saying config.plugins.push(new BundleAnalyzer()).

[00:46] Before we run this, we want to make sure we hide it behind a flag so it doesn't run every time. The way we can do that is by changing our exports to a function and then passing in some options. Now I'll wrap this in parens.

[01:02] Now I can pass in options and check to see if something like if (options.analyze) then do this. If I say poi build --analyze, this will hit this if block and use that plugin. We can see this automatically launched the BundleAnalyzer. We can go ahead and navigate through our bundles, click on these areas, zoom in, and see how we can optimize our project.