现实需求: 执行‘npm install phantomjs-prebuilt’后,发现下载很慢,半个小时才走了 2%。 于是直接从 github 上下载了‘’phantomjs-prebuilt‘’的源代码,但是怎么把这个开源代码安装到项目的 node_modules 模块,却发现无从下手。跪求好心人指导一下,越详细越好,谢谢。 那个包 github 上面是一堆文件.
1
Rhianu 2020-08-04 18:13:46 +08:00
npm install username/reponame
|
2
wisunny 2020-08-04 18:15:32 +08:00 via Android
可以用镜像
|
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 |
4
yuang 2020-08-04 18:16:37 +08:00 via Android
package.json 文件中可以使用 file: 前缀的方式加载本地的包,第三方包就是这样开发测试的
|
5
ZhouWenhao529 OP @Jirajine 谢谢回复,我试一下
|
6
ZhouWenhao529 OP @yuang 谢谢回复,我试一下
|
7
ZhouWenhao529 OP @wisunny 这个要具体怎么操作呢?
|
8
ZhouWenhao529 OP @Rhianu 看不懂
|
9
wisunny 2020-08-04 19:30:25 +08:00 via Android
|
10
renmu123 2020-08-04 19:43:18 +08:00 via Android
package.json 也可以加载 github 的文件,推荐的应该是用阿里的镜像
|
11
ZhouWenhao529 OP @renmu123 谢谢回答,我试试
|
12
retanoj 2020-08-04 21:09:41 +08:00 via iPhone
npm install github:Medium/phantomjs-prebuilt
这样可以嘛? 不过好像这个库已经处于废弃状态了 |
13
ZhouWenhao529 OP @retanoj 是的,这是一个旧的代码
|
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 (淘宝源)吧。 |