javascript - Yeoman:从缓存中安装依赖项

标签 javascript node.js yeoman yeoman-generator

我想添加一个选项,以便在调试我的生成器或离线工作时从缓存中下载 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

您可以为 #npmInstallbowerInstall 指定它们 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/

相关文章:

javascript - jQuery 突出显示文本无法使用 .css ("background-color")

javascript - Nodejs 不解析字符串化的 JSON,在线验证器将其视为有效的 JSON?

javascript - Grunt 展开文件,src 中可接受哪些模式?

gruntjs - 更新到优胜美地后,在grunt-contrib-compass中导致此错误的原因是什么?

javascript - 当我指定一定数量的列时,乘法表不起作用

javascript - 如何使用javascript在Azure SQL Server上执行操作?

javascript - jquery 在函数中的 Focusout 上执行双重触发代码

angularjs - Mean stack Web 应用程序基于角色的访问控制

node.js - Nodejs 中的 facebook、google 和 twitter 身份验证

node.js - 如何定义 GruntJS 服务的内容?