V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
ZhouWenhao529
V2EX  ›  JavaScript

如何本地 npm 安装从 github 上面下载的开源包。

  •  
  •   ZhouWenhao529 · 2020-08-04 18:10:55 +08:00 · 2306 次点击
    这是一个创建于 1332 天前的主题,其中的信息可能已经有所发展或是发生改变。

    现实需求: 执行‘npm install phantomjs-prebuilt’后,发现下载很慢,半个小时才走了 2%。 于是直接从 github 上下载了‘’phantomjs-prebuilt‘’的源代码,但是怎么把这个开源代码安装到项目的 node_modules 模块,却发现无从下手。跪求好心人指导一下,越详细越好,谢谢。 那个包 github 上面是一堆文件.

    14 条回复    2020-08-06 10:38:51 +08:00
    Rhianu
        1
    Rhianu  
       2020-08-04 18:13:46 +08:00
    npm install username/reponame
    wisunny
        2
    wisunny  
       2020-08-04 18:15:32 +08:00 via Android
    可以用镜像
    Jirajine
        3
    Jirajine  
       2020-08-04 18:16:18 +08:00 via Android
    npm install <folder>:

    Install the package in the directory as a symlink in the current project. Its dependencies will be installed before it's linked. If <folder> sits inside the root of your project, its dependencies may be hoisted to the toplevel node_modules as they would for other types of dependencies.

    npm install <tarball file>:

    Install a package that is sitting on the filesystem. Note: if you just want to link a dev directory into your npm root, you can do this more easily by using npm link.

    Tarball requirements:

    The filename must use .tar, .tar.gz, or .tgz as the extension.
    The package contents should reside in a subfolder inside the tarball (usually it is called package/). npm strips one directory layer when installing the package (an equivalent of tar x --strip-components=1 is run).
    The package must contain a package.json file with name and version properties.

    Example:

    npm install ./package.tgz
    yuang
        4
    yuang  
       2020-08-04 18:16:37 +08:00 via Android
    package.json 文件中可以使用 file: 前缀的方式加载本地的包,第三方包就是这样开发测试的
    ZhouWenhao529
        5
    ZhouWenhao529  
    OP
       2020-08-04 18:24:04 +08:00
    @Jirajine 谢谢回复,我试一下
    ZhouWenhao529
        6
    ZhouWenhao529  
    OP
       2020-08-04 18:24:23 +08:00
    @yuang 谢谢回复,我试一下
    ZhouWenhao529
        7
    ZhouWenhao529  
    OP
       2020-08-04 18:24:45 +08:00
    @wisunny 这个要具体怎么操作呢?
    ZhouWenhao529
        8
    ZhouWenhao529  
    OP
       2020-08-04 18:25:06 +08:00
    @Rhianu 看不懂
    wisunny
        9
    wisunny  
       2020-08-04 19:30:25 +08:00 via Android
    renmu123
        10
    renmu123  
       2020-08-04 19:43:18 +08:00 via Android
    package.json 也可以加载 github 的文件,推荐的应该是用阿里的镜像
    ZhouWenhao529
        11
    ZhouWenhao529  
    OP
       2020-08-04 20:42:27 +08:00
    @renmu123 谢谢回答,我试试
    retanoj
        12
    retanoj  
       2020-08-04 21:09:41 +08:00 via iPhone
    npm install github:Medium/phantomjs-prebuilt

    这样可以嘛?
    不过好像这个库已经处于废弃状态了
    ZhouWenhao529
        13
    ZhouWenhao529  
    OP
       2020-08-04 22:42:54 +08:00
    @retanoj 是的,这是一个旧的代码
    libook
        14
    libook  
       2020-08-06 10:38:51 +08:00
    直接复制或链接到你的 node_modules 里就可以了。

    在你项目目录里
    ```
    # 确保下载的包目录名字为 phantomjs-prebuilt
    # 直接复制到 node_modules 里
    cp -r 你下载包的位置 /phantomjs-prebuilt ./node_modules/

    # 安装依赖
    npm i
    ```

    不过有可能其他包也下不下来,这种情况要么挂代理,要么用 cnpm (淘宝源)吧。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4002 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 00:58 · PVG 08:58 · LAX 17:58 · JFK 20:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.