9

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

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

1 回答 1

16

最后通过在 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
    });
  }
});

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

于 2014-03-13T14:07:43.930 回答