技术解析

如何本地 npm 安装从 github 上面下载的开源包。
0
2021-08-16 20:46:20
idczone

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


npm install username/reponame

可以用镜像

npm install :
Install the package in the directory as a symlink in the current project. Its dependencies will be installed before it's linked. If 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 :
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

package.json 文件中可以使用 file: 前缀的方式加载本地的包,第三方包就是这样开发测试的

谢谢回复,我试一下

谢谢回复,我试一下

这个要具体怎么操作呢?

看不懂

https://developer.aliyun.com/mirror/NPM

package.json 也可以加载 github 的文件,推荐的应该是用阿里的镜像

谢谢回答,我试试

npm install github:Medium/phantomjs-prebuilt
这样可以嘛?
不过好像这个库已经处于废弃状态了

是的,这是一个旧的代码

直接复制或链接到你的 node_modules 里就可以了。
在你项目目录里
```
确保下载的包目录名字为 phantomjs-prebuilt
直接复制到 node_modules 里
cp -r 你下载包的位置 /phantomjs-prebuilt ./node_modules/
安装依赖
npm i
```
不过有可能其他包也下不下来,这种情况要么挂代理,要么用 cnpm (淘宝源)吧。

数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服