我想这样做,所以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 link,你可以将这个添加到你的包中。Json“脚本”部分:

"scripts": {
    "postinstall": "npm link ../somelocallib",
    "postupdate": "npm link ../somelocallib"
  }

这感觉很俗气,但似乎很“管用”。从这个npm问题中得到了提示: https://github.com/npm/npm/issues/1558#issuecomment-12444454

这对我来说很有效:首先,确保npm目录有正确的用户

sudo chown -R myuser ~/.npm
sudo chown -R myuser /usr/local/lib/node_modules

那你就在你的包裹里。Json链接目录

"scripts": {
 "preinstall": "npm ln mylib ../../path/to/mylib"
}, 
"dependencies": {
  "mylib" : "*"
}

现在可以在包中指定本地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.

完整的本地开发有两个步骤:

提供包含包的本地目录的路径。

{ “名称”:“记者”, “依赖”:{ “酒吧”:“文件:. . / foo / bar” } }

符号链接包文件夹 CD ~/projects/node-redis #进入包目录 NPM link #创建全局链接 CD ~/projects/node-bloggy #进入其他包目录。 NPM link redis # link-install包

主项目

这是包裹。Json,你将用于主项目:

"dependencies": {
    "express": "*",
    "somelocallib": "file:./somelocallib"
}

其中,./somelocallib是相对于主项目package.json的库文件夹的引用。

参考:https://docs.npmjs.com/cli/v7/configuring-npm/package-json # local-paths


子工程

处理你的库依赖项。

除了运行npm install,你还需要运行(cd node_modules/somelocallib && npm install)。

这是一个已知的NPM错误。

参考资料:https://github.com/npm/npm/issues/1341(寻求最新的参考资料)


Docker注意事项

检查主包。锁和你的somelocallib/package。锁定到源代码管理器中。

然后在Dockerfile中使用:

FROM node:10
WORKDIR /app
# ...
COPY ./package.json ./package-lock.json ./
COPY somelocallib somelocallib
RUN npm ci
RUN (cd node_modules/zkp-utils/ && npm ci)
# ...

我在我的(cd A && B)结构中使用括号,以使操作幂等。