代码之家  ›  专栏  ›  技术社区  ›  Chen Li Yong

如何在没有npm的情况下从github手动下载和导入节点模块,并将其安装在React Native项目中?

  •  0
  • Chen Li Yong  · 技术社区  · 4 年前

    在我的项目中,我们使用 react-native-azure-ad 插件。问题是,npm上的这个插件已经过时,并且使用了一种不推荐的访问webview的方式,这种方式已经从react native中提取出来,用于react natives webview。

    当我浏览 github page 观察那里的源代码,看起来github上的代码已经更新为使用react-native webview,这让我相信作者没有更新npm包以遵循github版本。

    只有一种方法可以解决这个问题,那就是直接从github下载模块并手动导入。问题是,我只知道如何通过npm安装导入模块。

    目前,这是基本的文件夹结构:

    Root
    - node_modules  
    - src  --> the app source code
    

    我想这样放置模块:

    Root
    - node_modules
    - node_updates
      - react-native-azure-ad
    - src
    

    我仍然希望能够像这样导入它:

    import {ReactNativeAD, ADLoginView} from 'react-native-azure-ad'
    

    当然,我会从package.json中删除react-native azure广告,并提前重新安装node_modules。

    这可能吗?

    我希望我不必依赖相对路径,比如:

    import {ReactNativeAD, ADLoginView} from '../../../node_updates/react-native-azure-ad'
    

    我看到了一些答案,比如 this ,但这要求我使用相对路径进行导入。

    0 回复  |  直到 4 年前
        1
  •  0
  •   Vahid Alimohamadi    4 年前

    使用 npm :

    npm install <git-host>:<git-user>/<repo-name>
    

    npm install <git repo url>
    

    使用公共git repo时。

    使用 yarn :

    yarn add <git remote url>
    

    yarn add <git remote url>#<branch/commit/tag> 当你需要特定的分支机构等时。