Expo Web Setup (Beta)
Some additional steps are necessary for supporting expo web. The example-expo app in the repository runs on the web with this setup (yarn example:expo web); there is also a standalone example here.
Step 1 - Install required deps
npx expo install @10play/react-native-web-webview react-native-web react-dom expo-crypto
expo-crypto and the crypto alias below are only needed by older versions of @10play/react-native-web-webview; the example-expo app runs version 0.0.3 without them. Keeping them does no harm.
Several editors on one page work with any version of @10play/react-native-web-webview: the shim delivers every editor's messages to every WebView on the page, so 1.1 tags each message with an editor id and every editor ignores messages meant for another one. A custom onMessage on RichText only receives its own editor's messages too.
Step 2 - Configuring your bundler
Which bundler are you using?
- Metro
- Webpack
Create config file if not already npx expo customize metro.config.js
Into your metro.config.js add the following configuration
const { getDefaultConfig } = require('expo/metro-config');
/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);
const webAliases = {
'react-native': 'react-native-web',
'react-native-webview': '@10play/react-native-web-webview',
'react-native/Libraries/Utilities/codegenNativeComponent':
'@10play/react-native-web-webview/shim',
'crypto': 'expo-crypto',
};
config.resolver.resolveRequest = (
context,
realModuleName,
platform,
moduleName
) => {
if (platform === 'web') {
const alias = webAliases[realModuleName];
if (alias) {
return {
filePath: require.resolve(alias),
type: 'sourceFile',
};
}
}
return context.resolveRequest(context, realModuleName, platform, moduleName);
};
module.exports = config;
Create config file if not already npx expo customize webpack.config.js
Into your webpack.config.js add the following configuration
const createExpoWebpackConfigAsync = require('@expo/webpack-config');
module.exports = async function (env, argv) {
const config = await createExpoWebpackConfigAsync(env, argv);
// Alias react-native-webview and crypto
config.resolve.alias = {
...config.resolve.alias,
'react-native': 'react-native-web',
'react-native-webview': '@10play/react-native-web-webview',
'crypto': 'expo-crypto',
};
// Shim codegenNativeComponent
config.resolve.fallback = {
...config.resolve.fallback,
'react-native/Libraries/Utilities/codegenNativeComponent':
'@10play/react-native-web-webview/shim',
};
return config;
};
Step 3 - Restart Metro
Restart metro for changes to take effect and the editor should load
Notes
dynamicHeightworks on web: the height is applied to the iframe'sstyle, which is the only style the shim reads.- Custom keyboards render under the toolbar, but the browser's own keyboard isn't hidden on web. They use the JavaScript driver; there is no native module on web.
- On web the
Toolbarrenders its items without aFlatList, soListComponentisn't used.