Local dependency in package.json

后端 未结 12 1298
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 16:42

I want to do something like this, so npm install also installs the package.json of ../somelocallib or more importantly its dependencie

12条回答
  •  暖寄归人
    2020-11-22 17:26

    Here in 2020, working on a Windows 10, I tried with

    "dependencies": {
        "some-local-lib": "file:../../folderY/some-local-lib" 
        ...
    }
    

    Then doing a npm install. The result is that a shortcut to the folder is created in node-modules. This doesn't work. You need a hard link - which windows support, but you have to do something extra in windows to create a hard symlink.

    Since I don't really want a hard link, I tried using an url instead:

    "dependencies": {
        "some-local-lib": "file:///D:\\folderX\\folderY\\some-local-lib.tar" 
         ....
    }
    

    And this works nicely.
    The tar (you have to tar the stuff in the library's build / dist folder) gets extracted to a real folder in node-modules, and you can import like everything else.
    Obviously the tar part is a bit annoying, but since 'some-local-lib' is a library (which has to be build anyway), I prefer this solution to creating a hard link or installing a local npm.

提交回复
热议问题