Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: expo SDK 51 does not seem to support webpack. Switch to metro #2

Open
cleemesser opened this issue Sep 3, 2024 · 1 comment

Comments

@cleemesser
Copy link

Documentation: expo SDK 51 does not seem to support webpack. It looks like migration to metro is required.

@cleemesser
Copy link
Author

This seems to work for me. (My first attempt at translating the webpack instructions to metro without being very familiar with either!)

create metro.config.js in the root of the project. And add the

// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');

/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);

const ALIASES = {
    'react-native': 'react-native-web',
    'react-native-webview': '@10play/react-native-web-webview'
};

/**
 * This maps moduleName: string -> newmoduleName: string given co
 * @param {T} context 
 * @param {string} moduleName 
 * @param {string} platform   in {"web", ... }
 * @returns 
 */
config.resolver.resolveRequest = (context, moduleName, platform) => {
    // Ensure you call the default resolver.
    if (platform === 'web') {
        return context.resolveRequest(
            context,
            // Use an alias if one exists.
            ALIASES[moduleName] ?? moduleName,
            platform
        );
    } 
    return context.resolveRequest(context, moduleName, platform);

};
module.exports = config;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant