Skip to content

Instantly share code, notes, and snippets.

@jgcmarins
Last active July 17, 2020 11:44
Show Gist options
  • Save jgcmarins/8e6b2460801409e8c2830db46eabb390 to your computer and use it in GitHub Desktop.
Save jgcmarins/8e6b2460801409e8c2830db46eabb390 to your computer and use it in GitHub Desktop.
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
const path = require('path');
const { FileStore } = require('metro-cache');
const getWorkspaces = require('get-yarn-workspaces');
const blacklist = require('metro-config/src/defaults/exclusionList');
const workspaces = getWorkspaces(__dirname);
const packages = [];
module.exports = {
projectRoot: path.resolve(__dirname, '.'),
watchFolders: [
path.resolve(__dirname, '../../node_modules'),
...packages.map(pkg => path.resolve(__dirname, `../${pkg}`)),
],
resolver: {
blacklistRE: blacklist([
...workspaces
.filter(workspacePath => workspacePath.indexOf('packages/app') === -1)
.map(workspacePath => new RegExp(`^${escape(path.resolve(__dirname, workspacePath, 'node_modules'))}\\/.*$`)),
new RegExp(`^${escape(path.resolve(__dirname, '../../node_modules', 'react'))}\\/.*$`),
]),
resolverMainFields: ['react-native-ts', 'browser-ts', 'main-ts', 'react-native', 'browser', 'main'],
// https://github.com/facebook/metro/issues/1#issuecomment-453450709
extraNodeModules: new Proxy(
{},
{
get: (target, name) => path.join(process.cwd(), `node_modules/${name}`),
},
),
},
// http://facebook.github.io/react-native/blog/2019/03/12/releasing-react-native-059#faster-app-launches-with-inline-requires
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
cacheStores: [
new FileStore({
root: path.join(__dirname, 'metro-cache'),
}),
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment