Build and Analyze Your JavaScript Bundles with Poi

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 6 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.

egghead
egghead
~ 17 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today