Skip to content

Commit

Permalink
Fix examples metro config
Browse files Browse the repository at this point in the history
  • Loading branch information
alabsi91 committed Nov 2, 2023
1 parent d842fb4 commit 8168610
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
41 changes: 20 additions & 21 deletions Example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ 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('../package.json');

const root = path.resolve(__dirname, '..');
const modules = Object.keys({...pak.peerDependencies});

function createRegExp(pkg) {
return new RegExp(`^${escape(path.join(root, 'node_modules', pkg))}\\/.*$`);
}

function createPkgEntry(pkg) {
return {
[pkg]: path.join(__dirname, 'node_modules', pkg),
};
}

/**
* Metro configuration
Expand All @@ -16,28 +24,19 @@ const modules = Object.keys({...pak.peerDependencies});
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: {
blacklistRE: exclusionList(
modules.map(
m => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`),
),
),
blacklistRE: exclusionList([
createRegExp('react-native-reanimated'),
createRegExp('react-native-gesture-handler'),
createRegExp('react-native'),
createRegExp('react'),
]),

extraNodeModules: {
'react-native-reanimated': path.join(
__dirname,
'node_modules',
'react-native-reanimated',
),
'react-native-gesture-handler': path.join(
__dirname,
'node_modules',
'react-native-gesture-handler',
),
'react-native': path.join(__dirname, 'node_modules', 'react-native'),
react: path.join(__dirname, 'node_modules', 'react'),
...createPkgEntry('react-native-reanimated'),
...createPkgEntry('react-native-gesture-handler'),
...createPkgEntry('react-native'),
...createPkgEntry('react'),
},
},

Expand Down
31 changes: 22 additions & 9 deletions ExampleExpo/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ const path = require('path');
const escape = require('escape-string-regexp');
const { getDefaultConfig } = require('@expo/metro-config');
const exclusionList = require('metro-config/src/defaults/exclusionList');
const pak = require('../package.json');

const root = path.resolve(__dirname, '..');
const modules = Object.keys({ ...pak.peerDependencies });

const defaultConfig = getDefaultConfig(__dirname);

function createRegExp(pkg) {
return new RegExp(`^${escape(path.join(root, 'node_modules', pkg))}\\/.*$`);
}

function createPkgEntry(pkg) {
return {
[pkg]: path.join(__dirname, 'node_modules', pkg),
};
}

/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
Expand All @@ -21,18 +29,23 @@ const config = {
projectRoot: __dirname,
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: {
...defaultConfig.resolver,

blacklistRE: exclusionList(modules.map(m => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`))),
blacklistRE: exclusionList([
createRegExp('react-native-reanimated'),
createRegExp('react-native-gesture-handler'),
createRegExp('react-native'),
createRegExp('react'),
createRegExp('expo'),
]),

extraNodeModules: {
'react-native-reanimated': path.join(__dirname, 'node_modules', 'react-native-reanimated'),
'react-native-gesture-handler': path.join(__dirname, 'node_modules', 'react-native-gesture-handler'),
'react-native': path.join(__dirname, 'node_modules', 'react-native'),
react: path.join(__dirname, 'node_modules', 'react'),
...createPkgEntry('react-native-reanimated'),
...createPkgEntry('react-native-gesture-handler'),
...createPkgEntry('react-native'),
...createPkgEntry('react'),
...createPkgEntry('expo'),
},
},
};
Expand Down

0 comments on commit 8168610

Please sign in to comment.