Install npm local package dependencies

无人久伴 提交于 2019-12-11 03:46:27

问题


I have a npm dependency installed from a local path, which in turn has a few dependencies of its own. As I understand it, in this case npm just copies the contents of the local folder under node_modules. Is there any way to make it run npm install on the package folder before copying it?


回答1:


npm install /path/to/foo simply copies from the specified path into your local package's node_modules folder. If this is what you meant by "installed from a local path", then that was the wrong thing to do if you want to make sure that npm update and npm install on your package would (a) automatically get the latest code from that path and (b) update/install the dependencies of the package at that path.

To accomplish (a) and (b), you can add that local dependency to your package.json's dependencies or devDependencies (supported by npm since 2.0). For example:

"dependencies": {
  "foo": "file:/path/to/foo"
}

After doing the above, npm update or npm install will treat that local dependency in the same way as any other dependency.



来源:https://stackoverflow.com/questions/40774328/install-npm-local-package-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!