Skip to content

Instantly share code, notes, and snippets.

@colonelpanic8
Created February 1, 2024 21:40
Show Gist options
  • Save colonelpanic8/d8b3ff6ff39498284c584692819724e3 to your computer and use it in GitHub Desktop.
Save colonelpanic8/d8b3ff6ff39498284c584692819724e3 to your computer and use it in GitHub Desktop.
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config')
const path = require('path')
const escape = require('escape-string-regexp')
const exclusionList = require('metro-config/src/defaults/exclusionList')
const pak = require('./react-native-vision-camera/package/package.json')
const root = path.resolve(__dirname, "./react-native-vision-camera/package")
const modules = Object.keys({ ...pak.peerDependencies })
/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
*
* @type {import('metro-config').MetroConfig}
*/
const config = {
watchFolders: [root],
// We need to make sure that only one version is loaded for peerDependencies
// So we block them at the root, and alias them to the versions in example's node_modules
resolver: {
resolveRequest: (context, realModuleName, platform) => {
console.log('Resolving:', realModuleName);
try {
var resolutionRequest = context.resolveRequest(context, realModuleName, platform)
} catch (err) {
console.warn('Resolution failure:', realModuleName, 'Context: ', context);
throw err
}
return resolutionRequest;
},
blacklistRE: exclusionList(
modules.map(
(m) =>
new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
)
),
extraNodeModules: modules.reduce((acc, name) => {
acc[name] = path.join(__dirname, 'node_modules', name)
return acc
}, {}),
},
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
}
module.exports = mergeConfig(getDefaultConfig(__dirname), config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment