Last active
January 18, 2024 11:01
-
-
Save vanGalilea/cf78fc588ddd3944f373dc38c8bac272 to your computer and use it in GitHub Desktop.
React native/expo project that is a part of a mono repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO: for React Native CLI require from '@react-native/metro-config' | |
const {getDefaultConfig} = require('@react-native/metro-config'); | |
// TODO: for Expo require from 'expo/metro-config' | |
// const {getDefaultConfig} = require('expo/metro-config'); | |
const path = require('path'); | |
// Find the project and workspace directories | |
const projectRoot = __dirname; | |
// This can be replaced with `find-yarn-workspace-root` | |
const workspaceRoot = path.resolve(projectRoot, '../..'); | |
const config = getDefaultConfig(projectRoot); | |
// Watch all files within the mono repo (sanity check with no packages) | |
config.watchFolders = [workspaceRoot]; | |
// Watch the local app folder, and the shared packages (uncomment if you have shared packages | |
// that are being used between the mono repo's apps) | |
// TODO: change 'myCompany' to your company/proj. name and 'packages/api', 'packages/components' | |
// to the real shared packages name. | |
// const monorepoPackages = { | |
// '@myCompany/api': path.resolve(workspaceRoot, 'packages/api'), | |
// '@myCompany/components': path.resolve(workspaceRoot, 'packages/components'), | |
// }; | |
// config.watchFolders = [projectRoot, ...Object.values(monorepoPackages)]; | |
// Let Metro know where to resolve packages and in what order | |
config.resolver.nodeModulesPaths = [ | |
path.resolve(projectRoot, 'node_modules'), | |
path.resolve(workspaceRoot, 'node_modules'), | |
]; | |
// Force Metro to resolve (sub)dependencies only from the `nodeModulesPaths` | |
config.resolver.disableHierarchicalLookup = true; | |
module.exports = config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This snippet is a part of the article 🚀 Configuration of React Native CLI/Expo Apps in Monorepos 🏗️