The metro.config.js in the example directory is configured to handle a monorepo-style setup where the library source code resides in the parent directory (..).
Key configurations include:
watchFolders: Includes the project root to ensure Metro watches changes in the library source.resolver.blacklistRE: Prevents Metro from loading multiple versions of peerDependencies by blocking the versions located in the root node_modules.resolver.extraNodeModules: Aliases peerDependencies and the @simform_solutions/react-native-audio-waveform package to the specific versions/paths used within the example directory's node_modules or the local source path. This ensures the example app uses the local version of the library being developed.
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 rootPackage = require('../package.json');
const rootModules = Object.keys({
...rootPackage.peerDependencies,
});
const root = path.resolve(__dirname, '..');
module.exports = mergeConfig(getDefaultConfig(__dirname), {
projectRoot: __dirname,
watchFolders: [root],
resolver: {
blacklistRE: exclusionList(
rootModules.map(
m => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
)
),
extraNodeModules: {
...rootModules.reduce((acc, name) => {
acc[name] = path.join(__dirname, 'node_modules', name);
return acc;
}, {}),
'@simform_solutions/react-native-audio-waveform': path.resolve(
__dirname,
'..'
),
},
},
});