【问题标题】:automate npm update,bower prune, bower update inside gulpfile as gulp tasks将 gulpfile 中的 npm 更新、bower prune、bower 更新作为 gulp 任务自动化
【发布时间】:2016-09-27 23:05:06
【问题描述】:

我想通过以下任务(gulp.task)自动化我的 gulpfile。

  1. npm 更新
  2. 鲍尔修剪
  3. 凉亭更新

每当有人更改 package.json 和 bower.json 时,我只需运行 gulp 即可安装/更新/删除这些包,而无需通过终端运行这些命令。

【问题讨论】:

  • 那么你的问题是什么?

标签: npm gulp


【解决方案1】:

还有另一种更简单的方法可以做到这一点(认为这不在 gulp 文件中)

在您的 package.json 中,在脚本部分添加 update 命令

"scripts": {
    "update": "npm install && npm prune && bower install && bower prune",
    "first-run": "npm install -g gulp bower && npm run update"
},

然后从命令行执行:

 npm run update

你也可以像上图那样创建first-run这样的命令并运行它

npm run first-run

【讨论】:

    【解决方案2】:

    您可以使用gulp-install 之类的插件来执行此操作...或者您可以像下面这样自己编写任务

    var gulp = require('gulp');
    var bower = require('bower');
    
    gulp.task('bower', function(cb){
      bower.commands.install([], {save: true}, {})
        .on('end', function(installed){
          cb(); // notify gulp that this task is finished
        });
    });
    

    【讨论】:

    • 非常感谢,这有效。一个问题,我如何通过 gulp-task 进行 npm prune。 gulp-install 似乎只有安装命令,但没有修剪/卸载命令。
    • gulp-install 将同时执行安装/卸载...修剪我不确定
    【解决方案3】:

    我想做这三件事:更新/安装/修剪 npm 和 bower,所以我最终为此创建了一个工具:updatejs

    如果你喜欢请告诉我:)

    【讨论】:

      猜你喜欢
      • 2013-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-06
      • 1970-01-01
      • 2012-12-19
      相关资源
      最近更新 更多