Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Build and Analyze Your JavaScript Bundles with Poi


    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.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: 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.

    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()).

    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.

    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.