我想添加一个选项,以便在调试我的生成器或离线工作时从缓存中下载 npm 和 bower 内容(通过使用 --cache-min 999999
和 --offline
分别)。
目前,这是我的代码(安装依赖项并调用 grunt bower
):
CallumGenerator.prototype.installDeps = function () {
var cb = this.async();
this.installDependencies({
skipInstall: this.options['skip-install'],
callback: function () {
this.spawnCommand('grunt', ['bower'])
.on('close', function () {
cb();
});
}.bind(this)
});
};
看起来我很可能必须手动调用 .npmInstall()
和 .bowerInstall()
来指定选项(我想?),但是我不知道如何指定任何选项。澄清一下,这就是我在控制台中的操作方式:
npm install --cache-min 999999 --save-dev grunt-contrib-less
bower install --offline --save jquery#1.10.2
最佳答案
您不能直接从 #installDependencies
指定选项,请参阅:https://github.com/yeoman/generator/blob/master/lib/actions/install.js#L44-L69
您可以为 #npmInstall
和 bowerInstall
指定它们 https://github.com/yeoman/generator/blob/master/lib/actions/install.js#L121-L143
你传递的options
是对象哈希的形式,将被dargs
Node 模块解析,所以你should follow the module conventions for declaring options
关于javascript - Yeoman:从缓存中安装依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20723488/