Skip to content

Instantly share code, notes, and snippets.

@EvanBacon
Created December 22, 2021 20:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvanBacon/40eeea40466013d8d22446c445eb2222 to your computer and use it in GitHub Desktop.
Save EvanBacon/40eeea40466013d8d22446c445eb2222 to your computer and use it in GitHub Desktop.
Using Realm with Expo Metro config "Exotic" bundling.
const { createExoticTransformer } = require("@expo/metro-config/transformer");
module.exports = createExoticTransformer({
// Add realm packages to the list of modules to transpile locally.
transpileModules: ["@realm/", "realm"],
});
// From docs: https://github.com/expo/expo-cli/tree/master/packages/metro-config
const { getDefaultConfig } = require("expo/metro-config");
const baseConfig = getDefaultConfig(__dirname, {
// Initialize in exotic mode.
// If you want to preserve `react-native` resolver main field, and omit cjs support, then leave this undefined
// and skip setting the `EXPO_USE_EXOTIC` environment variable.
mode: "exotic",
});
// Use the new transformer
baseConfig.transformer.babelTransformerPath = require.resolve(
"./metro-transformer"
);
// Optionally, you can add support for the `react-native` resolver field back
// doing this will increase bundling time and size as many community packages ship untransformed code using this feature.
// Other packages like `nanoid` use the field to support `react-native` so you may need to enable it regardless.
// defaultConfig.resolver.resolverMainFields.unshift('react-native');
module.exports = baseConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment