How do I prevent npm install from removing packages?

后端 未结 5 1231
无人及你
无人及你 2021-01-11 15:39

I\'m trying to set up a development environment with several packages, and as a result I need to manually install some dependencies. More specifically, I have some local ch

5条回答
  •  一生所求
    2021-01-11 16:26

    Have a look at npm link if you need to test against modified packages.

    From npm link: This is handy for installing your own stuff, so that you can work on it and test it iteratively without having to continually rebuild.

    Say b is a dependency of a. You made changes to b and want to check if a still works with those changes. Instead of using b in node_modules installed from npm, use your local, modified version:

    cd ~/projects/b    # go into the package directory
    npm link           # creates global link
    cd ~/projects/a    # go into some other package directory.
    npm link b         # link-install the package
    

    Now, any changes to ~/projects/b will be reflected in ~/projects/a/node_modules/b/.

提交回复
热议问题