Yeoman Generator:在自定义文件夹中安装项目依赖项

时间:2014-03-12 19:06:41

标签: yeoman yeoman-generator

生成我的项目脚手架后,我希望Yeoman在子文件夹中安装我的npm依赖项,而不是在主项目文件夹中。我的package.json文件位于项目的/ gulp子文件夹中。我怎么能让Yeoman在那里安装依赖项?这是我在发生器末尾运行的当前函数:

this.on('end', function () {
  if (!this.options['skip-install']) {
    this.installDependencies({
      bower: false,
      npm: true
    });
  }
});

1 个答案:

答案 0 :(得分:15)

最后通过在index.js中运行this.installDependencies()之前更改目录来实现此目的,如:

this.on('end', function () {
  if (!this.options['skip-install']) {

    // Change working directory to 'gulp' for dependency install
    var npmdir = process.cwd() + '/gulp';
    process.chdir(npmdir);

    this.installDependencies({
      bower: false,
      npm: true
    });
  }
});

如果您有不同的项目脚手架设置,希望这会有所帮助。

相关问题