This app is a Pokédex, but it's so much more! It's also a demo app for teaching developers how to reduce the bundle size of their React apps.
We'll explore concepts like:
- Using
webpack-bundle-analyzer
to inspect the makeup of our JavaScript bundles - Using
React.lazy
andReact.Suspense
to code split our page routes - Using dynamic imports to code split heavyweight functionality
- Using https://bundlephobia.com/ to choose our third-party dependencies wisely
This project was bootstrapped with Create React App and then ejected.
Before beginning, install your dependencies with npm install
. Also install the serve
package globally by running npm install -g serve
.
As you make changes to the app, you'll want to take note of the amount of JavaScript bundles, the size of the JavaScript bundles, and when they are loaded while using the app.
With each change that you'd like to inspect, do the following:
npm run build:stats
serve -s build
- View the locally hosted app in your browser
- Open the Network tab in your browser's dev tools and see the JavaScript bundles that are used
npm run analyze
- View the visualizer locally in your browser to see th makeup of your JavaScript bundles
npm run analyze
: Analyzes the bundle stats from the production appnpm run build
: Builds the production appnpm run build:stats
: Builds the production app and generates a stats bundlenpm run format
: Formats the code using Prettiernpm run format:watch
: Runs Prettier in watch modenpm start
: Starts the development server on port 3000npm test
: Runs the tests in watch modenpm run test:coverage
: Runs the tests not in watch mode and collects coverage