node.js npm - 在不同的文件夹中安装包的依赖项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13498403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
npm - install dependencies for a package in a different folder?
提问by Florin
I have the following directory structure:
我有以下目录结构:
/some_project
source.js
package.json
I would like to install the dependencies for some_project. I know I could cd into some_project and then run npm install
我想为 some_project 安装依赖项。我知道我可以 cd 进入 some_project 然后运行 npm install
But I was wondering if it's possible without changing the directory ? Something like
但我想知道是否可以不更改目录?就像是
npm install some_project/package.json
回答by coudy
You can use the npm install <folder>variant with the --prefixoption. In your scenario the folder and prefix will be the same:
您可以使用npm install <folder>带有--prefix选项的变体。在您的场景中,文件夹和前缀将相同:
npm --prefix ./some_project install ./some_project
回答by Linus Gustav Larsson Thiel
Update:Since the --prefixoption exists, I now vote for @coudy's answer to this question. Original answer below:
更新:由于该--prefix选项存在,我现在投票支持@coudy 对这个问题的回答。原答案如下:
No, npmwill always install in the current directory or, with -g, in the system wide node_modules. You can kind of accomplish this with a subshell though, which won't affect your current directory:
不,npm将始终安装在当前目录中,或者安装在-g系统范围的 node_modules 中。不过,您可以使用子外壳完成此操作,这不会影响您的当前目录:
(cd some_project && npm install)
The parentheses makes it run in a subshell.
括号使它在子shell 中运行。
回答by Yoannes Geissler
On Windows 10 I couldn't get --prefixto work, so I had to cdand execute it.
在 Windows 10 上我无法开始--prefix工作,所以我不得不cd执行它。
cd PATH_TO_FOLDER && npm install

