使用 package.json 更改安装目录 npm

Change the install directory, npm with package.json

我有一个 package.json 看起来像这样:

{
  "name": "test",
  "version": "0.0.1",
  "description": "test test",
  "main": "index.js",
  "scripts": {
    "test": "echo \"No test specified\""
  }  ,
  "devDependencies": {
    "gulp": "^3.9.1"
  },
  "dependencies": {
    "bootstrap": "^4.0.0-alpha.5"
  }
}

是否可以将 bootstrap 安装在 "node_modues" 以外的目录中。如果是这样,我如何在 "package.json" 文件

中写入它

您可以在 package.json 中使用此代码:

{
 "scripts": {
  "preinstall": "npm install bootstrap --prefix ./another/"
 }
}

您的模块将安装在 ./another/node_module

注意:因此您可以在此脚本中使用其他选项来根据需要安装模块。