1--- 2title: Bundle with webpack 3description: Learn about different webpack bundler configurations that can be customized. 4--- 5 6import { Terminal } from '~/ui/components/Snippet'; 7 8When you run `npx expo start --web` or `expo export:web` the CLI will check to see if your project has a **webpack.config.js** in the root directory. If the project doesn't then Expo will use the default `@expo/webpack-config` (preferred). 9 10> This is similar to `react-scripts` and `create-react-app`. 11 12To edit the config, install `@expo/webpack-config` as a dev dependency and create a template **webpack.config.js** at the root of your project. This can be done by running the following command: 13 14<Terminal cmd={['$ npx expo customize webpack.config.js']} /> 15 16You can now make changes to a config object based on the default config and return it for Expo CLI to use. Deleting the config will cause Expo to fall back to the default again. 17 18If you create a new webpack config or make any changes to it you'll need to restart your webpack dev server by running: 19 20<Terminal cmd={['$ npx expo start']} /> 21 22## Example 23 24```js webpack.config.js 25const createExpoWebpackConfigAsync = require('@expo/webpack-config'); 26 27// Expo CLI will await this method so you can optionally return a promise. 28module.exports = async function (env, argv) { 29 const config = await createExpoWebpackConfigAsync(env, argv); 30 // If you want to add a new alias to the config. 31 config.resolve.alias['moduleA'] = 'moduleB'; 32 33 // Maybe you want to turn off compression in dev mode. 34 if (config.mode === 'development') { 35 config.devServer.compress = false; 36 } 37 38 // Or prevent minimizing the bundle when you build. 39 if (config.mode === 'production') { 40 config.optimization.minimize = false; 41 } 42 43 // Finally return the new config for the CLI to use. 44 return config; 45}; 46``` 47 48## Polyfills 49 50React Native for Web uses [some advanced browser features](https://github.com/necolas/react-native-web/blob/e4ed0fd3c863e6c61aa3ea8afeff79b7fa74b461/packages/docs/src/introduction.stories.mdx#install) that might not be available in every browser. Expo web tries to include these features with `@expo/webpack-config`. 51 52### `ResizeObserver` 53 54**TL;DR:** To fully support `onLayout` install `resize-observer-polyfill`. 55 56The `onLayout` prop that's used in all of the core primitives such as View, Image, Text, ScrollView, and so on, requires an API called [`ResizeObserver`](https://drafts.csswg.org/resize-observer-1/). This API isn't fully [supported across all browsers](https://caniuse.com/#feat=resizeobserver), for example, iOS Safari (in iOS 13). If the device doesn't support `ResizeObserver` then `react-native-web` will fallback on `window.onresize` and you'll see a warning in the logs: 57 58``` 59onLayout relies on ResizeObserver which is not supported by your browser. 60Please include a polyfill, e.g., https://github.com/que-etc/resize-observer-polyfill. 61Falling back to window.onresize. 62``` 63 64To get everything working properly, you'll want to install and include a global polyfill for `ResizeObserver`. 65 66### Adding `ResizeObserver` 67 68- Install the polyfill: 69 <Terminal cmd={['$ npx expo install resize-observer-polyfill']} /> 70- Restart the project and `@expo/webpack-config` will automatically include the polyfill. 71 72The reason it automatically includes the polyfill is that `react-native-web` needs it included immediately. webpack can inject the polyfill before any of the application code has been executed. Alternatively, you can customize the webpack config and include the polyfill in the `entry` field yourself. 73 74### Testing the `ResizeObserver` polyfill 75 76- Open the running Expo project in iOS Safari. 77- Connect the device to an Apple computer. 78- Open Safari on the computer in go to `Develop > [YOUR DEVICE] > [YOUR HOST]`. 79- Ensure the logs don't have the `onLayout relies on ResizeObserver...` warning. 80 81## Editing static files 82 83You can also use `npx expo customize` to generate the static project files: **index.html**, **serve.json**, and so on. These can be used to customize your project more familiarly. 84 85All of the files you select from the terminal prompt will be copied to a **web** directory in your project's root directory. Think of this directory as **public** in Create React App. The **web** is used instead of **public** because Expo webpack is web-only, the static directory does not work for Android or iOS apps. For mobile platforms, the platform-specific project files are included in **android** and **ios** directories. 86 87Deleting any of these files will cause Expo webpack to fallback to their respective default copies. 88 89### Why 90 91- Customizing the favicon icon. 92- Adding third-party API code to the `<head/>` in your **index.html**. 93- Changing the caching policy in the **serve.json** file. 94