Created
December 30, 2018 11:28
-
-
Save sibelius/8ca62bab78ee9644ae5caffb9f1b1ef4 to your computer and use it in GitHub Desktop.
Metro config to make react native play nice with monorepos
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
const path = require('path'); | |
const getWorkspaces = require('get-yarn-workspaces'); | |
const blacklist = require('metro-config/src/defaults/blacklist'); | |
const workspaces = getWorkspaces(__dirname); | |
module.exports = { | |
projectRoot: path.resolve(__dirname, 'packages/app'), | |
watchFolders: [ | |
path.resolve(__dirname, 'node_modules'), | |
...workspaces, | |
], | |
resolver: { | |
blacklistRE: blacklist( | |
workspaces.map( | |
workspacePath => | |
`/${workspacePath.replace( | |
/\//g, | |
'[/\\\\]' | |
)}[/\\\\]node_modules[/\\\\]react-native[/\\\\].*/` | |
), | |
), | |
extraNodeModules: { | |
'react-native': path.resolve(__dirname, 'packages/app/node_modules/react-native'), | |
}, | |
}, | |
}; |
hope to keep working well for new versions
hey zachariahtimothy thank you for the link but it is broken for me, is there another for you to post?
hey zachariahtimothy thank you for the link but it is broken for me, is there another for you to post?
Afraid not. I bailed on React Native a long time ago and have lived a happier, healthier life since. Hah. I love React but RN is an absolute nightmare.
@zachariahtimothy, you made me curious, what have you changed to? 😄
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have been trying to get build a monorepo with core libs, create react app, and react native for about 1.5 weeks now. Fix CRA, break CRNA, fix CRNS, break CRA. Been pulling my hair out with 10+ difference metro config approaches. Finally this config did the trick! I have it working with TS, HMR, etc in an idea setup. https://github.com/zachariahtimothy/react-native-monorepo for helping others see how it can work.
I just want to thank you and give a HUGE shoutout for sharing this! If there is a way for me to buy you a beer / coffee / tea please let me know.