[英]Install npm packages programmatically
How to install npm packages programmatically? 如何以编程方式安装npm软件包? i have multiple local repos and each has its own package.json. 我有多个本地存储库,每个存储库都有自己的package.json。 Now i want to install packages from all those repos into a single node_modules folder which is outside of all repos. 现在,我想将所有这些存储库中的软件包安装到所有存储库之外的单个node_modules文件夹中。 Can someone provide a sample script/guide for this? 有人可以为此提供示例脚本/指南吗?
var repos = ['repo1', 'repo2', 'repo3'];
repos.forEach(function(repoName, index) {
//todo: install packages from this repo.
// dest: '/Users/lokesh/Documents/node_modules'
});
One option is to use gradle node plugin and use config nodeModulesDir specific a global nodeModulesDir. 一种选择是使用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}")
}
I don't know if this is helpful, if you don't want use gradle. 我不知道这是否有帮助,如果您不想使用gradle。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.