gpt4 book ai didi

npm - 如何在我的 package.json 中使用单个 github 文件作为依赖项?

转载 作者:行者123 更新时间:2023-12-04 02:09:43 25 4
gpt4 key购买 nike

我有一个旧项目使用这个 project它基本上只是一个 JS 文件。我试过用几种方法添加它...

"jquery-highlight-regex": "jbr/jQuery.highlightRegex"

npm ERR! eisdir EISDIR: illegal operation on a directory, read
npm ERR! eisdir This is most likely not a problem with npm itself
npm ERR! eisdir and is related to npm not being able to find a package.json in
npm ERR! eisdir a package you are trying to install.

"jquery-highlight-regex": "https://raw.githubusercontent.com/jbr/jQuery.highlightRegex/master/highlightRegex.js"
npm ERR! not a package /var/folders/vf/mnj9dq116gvcww95cbk3r3n40000gp/T/npm-32798-d819bc7b/raw.githubusercontent.com/jbr/jQuery.highlightRegex/master/highlightRegex.js
npm ERR! Darwin 16.0.0
npm ERR! argv "/Users/.../bin/node" "/Users/.../apps/node/bin/npm" "install"

那么如何在没有 package.json 的情况下包含一个简单的 JS 文件作为依赖项?

最佳答案

您可以使用安装后脚本以及依赖项,例如 download-cli手动拉取文件。如果文件经常更改,这可能很有用,例如 mjaggard 的情况。

以下示例 package.json 将在安装时获取文件并将其放置在 /third-party 文件夹中。

{
"name": "so-npm-download-on-install",
"version": "1.0.0",
"scripts": {
"postinstall": "download --out third-party https://raw.githubusercontent.com/jbr/jQuery.highlightRegex/master/highlightRegex.js"
},
"dependencies": {
"download-cli": "^1.1.1"
}
}

Clone this example repo to try it out.

关于npm - 如何在我的 package.json 中使用单个 github 文件作为依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39752064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com