繁体   English   中英

以编程方式安装npm软件包

[英]Install npm packages programmatically

如何以编程方式安装npm软件包? 我有多个本地存储库,每个存储库都有自己的package.json。 现在,我想将所有这些存储库中的软件包安装到所有存储库之外的单个node_modules文件夹中。 有人可以为此提供示例脚本/指南吗?

var repos = ['repo1', 'repo2', 'repo3'];

repos.forEach(function(repoName, index) {
   //todo: install packages from this repo. 
   // dest: '/Users/lokesh/Documents/node_modules'
});

一种选择是使用gradle节点插件,并使用特定于全局nodeModulesDir的配置nodeModulesDir。

node {
  // Version of node to use.
  version = '0.11.10'

  // Version of npm to use.
  npmVersion = '2.1.5'

  // Version of Yarn to use.
  yarnVersion = '0.16.1'

  // Base URL for fetching node distributions (change if you have a mirror).
  distBaseUrl = 'https://nodejs.org/dist'

  // If true, it will download node using above parameters.
  // If false, it will try to use globally installed node.
  download = true

  // Set the work directory for unpacking node
  workDir = file("${project.buildDir}/nodejs")

  // Set the work directory for NPM
  npmWorkDir = file("${project.buildDir}/npm")

  // Set the work directory for Yarn
  yarnWorkDir = file("${project.buildDir}/yarn")

  // Set the work directory where node_modules should be located
  nodeModulesDir = file("${project.projectDir}")
}

我不知道这是否有帮助,如果您不想使用gradle。

Gradle节点插件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM