Locally installed versus globally installed NPM modules

前端 未结 4 1821
醉梦人生
醉梦人生 2020-12-15 03:03

In my package.json file, I have bower listed as a dependency. After I run npm install, bower gets installed locally. When I try to run bower after

4条回答
  •  执笔经年
    2020-12-15 03:42

    We use both PHP and JavaScript, so we have composer and npm.

    Each of the projects we work on have different packages both for runtime of the package as well as build/dev tools.

    As there are version constraints in each project, installing version x of a package globally (that would be run from the command line), would cause us issues, we install all the tooling in each package. Much easier to define in the appropriate composer.json / package.json files.

    But running the CLI tools is a pain if you have to constantly add an additional path to the command.

    To that end, we have recommend to the team that the following paths are added to your $PATH in the appropriate .bashrc (or equivalent):

    ./vendor/bin:./node_modules/.bin

    (EDIT: For Windows, the paths would be .\vendor\bin;.\node_modules\.bin;)

    So, whilst in project X, we have access to the CLI tools for that project. Switch to project Y, and we get that projects tools.

    Sure, you are going to get duplications, but each project is maintained by different teams (and some people are in multiple teams), so again, having 1 version in the global setup is an issue there.

提交回复
热议问题