React-native: packager: a way to blacklist some folders/files in a RN app?

Created on 28 Apr 2016  路  12Comments  路  Source: facebook/react-native

Hi,
I have some folders under my root app like for instance a standalone node project that are not used by the app but for something else. How can I tell the packager to ignore these? It breaks when packager try to read the content of node_modules of that sub project, it shouldn't have enter there in the first place (because I never depend on it from any of the RN app jsbundle !!)

Locked

Most helpful comment

As of react-native 47 I have to do something like:

const metroBundler = require('metro-bundler');

module.exports = {
  getBlacklistRE: function() {
    return metroBundler.createBlacklist([/coverage\/.*/]);
  }
};

All 12 comments

There is a blacklist.js in react-native/packager.
Make a rn-cli.config.js in your project root and do something like this:

var blacklist = require('react-native/packager/blacklist');

var config = {
  getBlacklistRE(platform) {
    return blacklist(platform, [
      /node_modules\/my-package\/excluded-directory\/.*/
    ]);
  }
};

module.exports = config;

thanks @radko93 !!

The code above is outdated or was incorrect, getBlacklistRE and blacklist do not take any parameters.

`var blacklist = require('react-native/packager/blacklist');

var config = {
getBlacklistRE() {
return blacklist([
/node_modules\/my-package\/excluded-directory\/.*/
]);
}
};

module.exports = config;`

I was suffering the same thing at https://github.com/facebook/react-native/issues/12582

My code ended up being

const blacklist = require('react-native/packager/blacklist');

module.exports = {
  getBlacklistRE: () => blacklist([
    /coverage\/.*/,
  ]),
};

and my package.json start script became

"start": "react-native run-ios --config=rn-cli.config.js",

blacklist does not exist anymore in react-native 46 :( so after a little bit of research, i found out that we have to use metro-bundler/build/blacklist instead of react-native/packager/blacklist.

thanks @alinz that works for me

As of react-native 47 I have to do something like:

const metroBundler = require('metro-bundler');

module.exports = {
  getBlacklistRE: function() {
    return metroBundler.createBlacklist([/coverage\/.*/]);
  }
};

@azundo That doesn't work for me as of react-native 0.48.3 and metro-bundler 0.11.0: https://github.com/facebook/metro-bundler/issues/58

@samuela
Seems to work that way now (yey, folder changes...)

const blacklist = require('metro-bundler/src/blacklist')
var config = {
  getBlackListRE() {
    return blacklist([ 
      // your folders here
    ]);
  }
};

module.exports = config;

( Correction: I had wrong case Change getBlackListRE -> getBlacklistRE )

After trying most all of the half-dozen above variations...

blacklist du jour

  • ### 2018 February 20 answer that works with RN 0.53

const blacklist = require('metro/src/blacklist');
```
const config = {
getBlackListRE() { // <---- * Error here : Change getBlackListRE -> getBlacklistRE
// Do not include /react-codemod folder in packager
return blacklist([
/react-codemod\/.*/,
]);
},
};

module.exports = config;
````

@esutton
getBlackListRE -> getBlacklistRE

@theRealRobG Thank you for taking the time to point out my mistake!

Was this page helpful?
0 / 5 - 0 ratings