NPM link done at install time inside package.json

本秂侑毒 提交于 2019-12-25 09:08:54

问题


I'm in the process of creating 2 projects. Project 1 will be like a library. Project 2 will be an application which uses Project 1's library code.

So I wish to do a npm link from Project 1 to Project 2. I can do this at the command line using the follow:

  • cd ../project1 npm link
  • cd ../project2 npm link project1_name

and it works fine. But I don't wish to do that, I want when I install the package.json to not only set up the various dependencies to also set up the link.

So how would I do that in a npm script? I thought possibly - "preinstall": "cd ../project1 npm link && cd ../project2 npm link project1_name",

but that fails and I think it may have to do with what's the correct way to split up the various commands.


回答1:


Right before I posted the question I tried a few more combinations and I got the answer -

You just need to place a && between each command that you'd enter if you were doing it manually.

So the answer is -

"preinstall": "cd ../project1 && npm link && cd ../project2 && npm link project1_name",

I placed that into the scripts object in the package.json and now whenever the package is installed it will link to the library project



来源:https://stackoverflow.com/questions/38855927/npm-link-done-at-install-time-inside-package-json

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