我想这样做,所以npm install也会安装这个包。Json的../somelocallib或者更重要的是它的依赖项。
"dependencies": {
"express": "*",
"../somelocallib": "*"
}
我想这样做,所以npm install也会安装这个包。Json的../somelocallib或者更重要的是它的依赖项。
"dependencies": {
"express": "*",
"../somelocallib": "*"
}
当前回答
这是如何添加本地依赖项的:
npm安装文件:src/assets/js/FILE_NAME
把它添加到包中。json来自NPM:
保存文件:src/assets/js/FILE_NAME
直接添加到包。Json是这样的:
....
"angular2-autosize": "1.0.1",
"angular2-text-mask": "8.0.2",
"animate.css": "3.5.2",
"LIBRARY_NAME": "file:src/assets/js/FILE_NAME"
....
其他回答
NPM >= 2.0.0
该特性在npm 2.0.0版本中实现。本地路径可以使用npm install -S或npm install——save保存,使用以下任何一种形式:
../foo/bar
~/foo/bar
./foo/bar
/foo/bar
示例package.json:
{
"name": "baz",
"dependencies": {
"bar": "file:../foo/bar"
}
}
npm ls:
app@0.0.1 /private/tmp/app
└── somelocallib@0.0.1 -> /private/tmp/somelocallib
NPM < 2.0.0
在包中放入somelocallib作为依赖项。正常的Json:
"dependencies": {
"somelocallib": "0.0.x"
}
然后运行npm link ../somelocallib和NPM会将你正在使用的版本作为符号链接安装。
参考:链接(1)
实际上,从npm 2.0开始,现在已经支持本地路径了。
在2020年的这里,我正在用Windows 10操作系统工作
"dependencies": {
"some-local-lib": "file:../../folderY/some-local-lib"
...
}
然后进行npm安装。结果是在节点模块中创建文件夹的快捷方式。 这行不通。你需要一个硬链接-哪个窗口支持,但是 你必须在Windows中做一些额外的事情来创建一个硬符号链接。
因为我不是真的想要一个硬链接,我尝试使用一个url代替:
"dependencies": {
"some-local-lib": "file:///D:\\folderX\\folderY\\some-local-lib.tar"
....
}
这个很好用。 tar(你必须tar库的build / dist文件夹中的东西)被提取到node-modules中的一个真正的文件夹中,你可以像其他东西一样导入。 显然tar部分有点烦人,但由于'some-local-lib'是一个库(无论如何都要构建),我更喜欢这个解决方案,而不是创建一个硬链接或安装一个本地npm。
我知道npm install ../ somelocallib作品。
然而,我不知道你在问题中显示的语法是否可以从package.json中工作…
不幸的是,doc似乎只提到URL作为依赖项。
尝试file:///…/…tar.gz,指向压缩的本地库…告诉我们它是否有效。
现在可以在包中指定本地Node模块安装路径。直接json。从文档中可以看出:
Local Paths As of version 2.0.0 you can provide a path to a local directory that contains a package. Local paths can be saved using npm install -S or npm install --save, using any of these forms: ../foo/bar ~/foo/bar ./foo/bar /foo/bar in which case they will be normalized to a relative path and added to your package.json. For example: { "name": "baz", "dependencies": { "bar": "file:../foo/bar" } } This feature is helpful for local offline development and creating tests that require npm installing where you don't want to hit an external server, but should not be used when publishing packages to the public registry.