How to blacklist specific node_modules of my package's dependencies in react-native's packager?

陌路散爱 提交于 2019-12-29 00:39:25

问题


I'm putting together a streamlined development process with react and react-native that:

  • encourages packages,
  • uses babel to transform es6 to js (it compiles before publishing/installing),
  • has a playground that let's you play with both native and web components.

The web part of it is perfectly fine. It's the native one that's causing issues and it has to do with react-native's packager.

The bottom line is: if the package is either linked through npm link or required directly from the playground as in require('../../') react-native's dependency resolver will go forever trying to identify dependencies inside my package's node_modules, most times it never finishes doing it.

The temporary solution I've found is to install the package in playground but this involves re-installing it every time I do an update, which isn't great because you can't see your changes right away (even if it would be automated, it would take time).

I believe that a better solution would be to ask the dependency resolver to ignore those specific modules I don't need (those in devDependencies mainly!). I tried mangling react-native/packager/blacklist.js by adding paths to that list and even putting checks against the dependency resolver but none of that would work.

Can someone with more experience with the packager give me a hint as to how I'd go about making the dependency resolver pass? Alternatively, it would be great if the packager could be separated and the transform process left to choice but I don't know if that would be doable either.


回答1:


I found out the following solution, based on the comment in default.config.js:

* If you need to override any of this functions do so by defining the file
* `rn-cli.config.js` on the root of your project with the functions you need
* to tweak.

Create a rn-cli.config.js in the root of your project with the following contents:

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

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

module.exports = config;

The second argument to the blacklist function is an additional list of blacklisted paths, which can be regular expressions. See react-native/packager/blacklist.js for more examples.



来源:https://stackoverflow.com/questions/30049111/how-to-blacklist-specific-node-modules-of-my-packages-dependencies-in-react-nat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!