npm install: Use global package if it exists, rather than installing twice

后端 未结 2 645
南笙
南笙 2021-02-20 06:38

When using npm install with a package.json file, how do I get it to use a globally installed package that meets the criteria instead of downloading and

相关标签:
2条回答
  • 2021-02-20 06:56

    One way of doing it for a specific set of modules is removing these modules from the dependencies section and creating a prestart script that contains all the modules that you prefer having installed globally.

    A simple example might look something like this:

      "scripts": {
        "test": "mocha",
        "prestart": "npm i -g mocha mysql bluebird"
      },
    

    Instead of prestart you can use one of the other hooks such as preinstall and prepare. Note that this won't work as-is with packages you want to publish and would require a bit more hacking.

    Help on running scriipts: https://docs.npmjs.com/misc/scripts

    0 讨论(0)
  • 2021-02-20 07:12

    Yarn seems to work much better with repeated dependencies. So try yarn install instead of npm install.

    0 讨论(0)
提交回复
热议问题