简体   繁体   English

用于在React Native metro bundler中使用动态纱线工作空间路径将节点模块列入黑名单的正则表达式

[英]regex for blacklisting node module with dynamic yarn workspace path in React Native metro bundler

Similar to: How to blacklist specific node_modules of my package's dependencies in react-native's packager? 类似于: 如何在react-native的packager中将我的包的依赖项的特定node_modules列入黑名单?

I am trying to exclude react native from metro packager using the blacklist option which needs to return a regexp. 我试图使用需要返回正则表达式的黑名单选项从地铁包装器中排除本机反应。

What I need is to return something like: 我需要的是返回类似的东西:

/\/DYNAMIC_PROJECT_DIRECTORY\/node_modules\/react-native\/.*/,

where I can insert a variable into the DYNAMIC_PROJECT_DIRECTORY as it will change dependant on the yarn workspace path of the other module. 我可以在DYNAMIC_PROJECT_DIRECTORY中插入一个变量,因为它将根据另一个模块的纱线工作空间路径而改变。

I just have no familiarity with regex! 我对正则表达式并不熟悉!

Thanks 谢谢

Edit: I tried hard coding in the path into that format and it still didn't work to blacklist, so if someone can point me in the right direction on what works to exclude that folder and everything in it that would be much appreciated! 编辑:我尝试在该格式的路径中进行硬编码,但仍然无法使用黑名单,所以如果有人可以指出我正确的方向,那么排除该文件夹及其中的所有内容将非常感激!

You can create a regular expression that uses dynamic variables with the RegExp constructor: 您可以使用RegExp构造函数创建使用动态变量的正则表达式:

new RegExp(`\/${DYNAMIC_PROJECT_DIRECTORY}\/node_modules\/react-native\/.*`);

Note: 注意:

  • This example is using a template string to insert the DYNAMIC_PROJECT_DIRECTORY ; 此示例使用模板字符串插入DYNAMIC_PROJECT_DIRECTORY ; you could just as well write: 你也可以写:
    new RegExp('\\/' + DYNAMIC_PROJECT_DIRECTORY + '\\/node_modules\\/react-native\\/.*');
  • The leading and trailing slashes are omitted when using this method of creating a regular expression 使用此方法创建正则表达式时,将省略前导和尾部斜杠

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM