如何在 react-native 的打包程序中将我的包依赖项的特定 node_modules 列入黑名单? [英] How to blacklist specific node_modules of my package's dependencies in react-native's packager?

查看:29
本文介绍了如何在 react-native 的打包程序中将我的包依赖项的特定 node_modules 列入黑名单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 react 和 react-native 整合简化的开发流程:

  • 鼓励打包,
  • 使用 babel 将 es6 转换为 js(在发布/安装之前编译),
  • 有一个游乐场,让您可以同时玩原生和网络组件.
  • 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.

它的网络部分非常好.导致问题的是原生的,它与 react-native 的打包器有关.

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.

底线是:如果包通过 npm link 链接或直接从 Playground 需要,如 require('../../')react-native 的依赖解析器将永远尝试识别我的包的 node_modules 中的依赖,大多数时候它永远不会完成.

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).

我相信更好的解决方案是让依赖项解析器忽略那些我不需要的特定模块(主要是 devDependencies 中的模块!).我尝试修改 react-native/packager/blacklist.js 通过向该列表添加路径,甚至检查 依赖解析器 但这些都不起作用.

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.

推荐答案

根据 default.config.js 中的注释,我找到了以下解决方案:

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.

在项目的根目录中创建一个 rn-cli.config.js ,内容如下:

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;

blacklist 函数的第二个参数是一个额外的黑名单路径列表,可以是正则表达式.有关更多示例,请参阅 react-native/packager/blacklist.js.

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.

这篇关于如何在 react-native 的打包程序中将我的包依赖项的特定 node_modules 列入黑名单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆