簡體   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