我有一个使用此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文件包含为依赖项?
答案 0 :(得分:3)
您可以使用安装后脚本以及诸如 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"
}
}
答案 1 :(得分:1)
正如您已经发现的,您无法通过 package.json 中的 URL 引用远程文件,但您可以在此处进行一些选择: