Learn about recommended tools to optimize the web app when creating universal projects.
Expo uses react-native-web which is the highly optimized framework used to power major websites and PWAs like Twitter, Major League Soccer, Flipkart, Uber, The Times, DataCamp.
Many performance tools at your disposal will not only optimize your web app, but also improve the performance of your native app! Here is the officially recommended and most optimal set of tools to use when creating universal projects:
babel-preset-expo
extends the default react-native preset and adds support for all other Expo platforms. In the browser this has massive performance benefits by enabling tree-shaking of the unused react-native-web
modules.jest-expo
A universal solution for testing your code against all of the platforms it runs on. Learn more about Universal Testing.@expo/webpack-config
A default webpack config that's optimized for running react-native-web
apps and creating progressive web apps.To inspect bundle sizes, you can use a webpack plugin called Webpack Bundle Analyzer. This plugin will help you visualize the size of your static bundles. You can use this to identify unwanted large packages that you may not have bundled intentionally.
-
yarn add -D webpack-bundle-analyzer
npx expo customize webpack.config.js
.const createExpoWebpackConfigAsync = require('@expo/webpack-config');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
module.exports = async (env, argv) => {
const config = await createExpoWebpackConfigAsync(env, argv);
// Optionally you can enable the bundle size report.
// It's best to do this only with production builds because it will add noticeably more time to your builds and reloads.
if (env.mode === 'production') {
config.plugins.push(
new BundleAnalyzerPlugin({
path: 'web-report',
})
);
}
return config;
};
If you want to track down why a package was included, you can build your project in debug mode.
-
EXPO_WEB_DEBUG=true npx expo export:web
This will make your bundle much larger, and you shouldn't publish your project in this state.
You can now search for unwanted packages by name and see which files or methods are preventing them from being tree-shaken.
Lighthouse is a great way to see how fast, accessible, and performant your website is. You can test your project with the Audit tab in Chrome, or with the Lighthouse CLI.
After creating a production build with npx expo export:web
and serving it somewhere, run Lighthouse with the URL your site is hosted at.
lighthouse <url> --view