This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Build and Analyze Your JavaScript Bundles with Poi

    John LindquistJohn Lindquist

    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.

    webpackwebpack
    javascriptJavaScript
    Code

    Code

    Become a Member to view code

    You must be a 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
    Transcript

    Transcript

    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.

    Discuss

    Discuss