【问题标题】:Gulp only executes last task in gulpfile?Gulp 只执行 gulpfile 中的最后一个任务?
【发布时间】:2015-09-24 11:37:52
【问题描述】:

我有大约六个与此类似的 Gulp 任务:

gulp.task('scripts', function() {
    return gulp.src([
        'public_html/assets/plugins/zeroclipboard/ZeroClipboard.min.js',
        'public_html/assets/plugins/redactor/redactor.min.js',
        'public_html/assets/libraries/autobahn.min.js'
    ])
        .pipe(concat('localStatic.js'))
        .pipe(gulp.dest('public_html/assets/dist/js/'))
        .pipe(rename('localStatic.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('public_html/assets/dist/js'));
});

当我在终端运行gulp时,它只执行最后一个任务(或者至少,只生成最后一个任务的JS文件)。

Gulp 允许多个任务,对吧?为什么只执行文件中的最后一个任务?

【问题讨论】:

  • 你在 gulpfile.js 的底部有你的 gulp“默认”任务吗?在那里你列出了你想用“gulp”命令默认运行的所有任务?类似:gulp.task('default', ['styles', 'scripts', 'images']);

标签: gulp gulp-watch gulp-uglify


【解决方案1】:

是的,您可以同时运行多个任务,只要它们具有不同的名称。

gulp.task('name', function() {})
gulp.task('of', function() {})
// ... task definitions
gulp.task('default', ['name', 'of', 'the', 'tasks', 'you', 'want', 'to','run']);

这将在您运行gulp 命令时并行运行指定的所有任务。

您可以在docs中阅读有关任务依赖关系的更多信息

【讨论】:

  • 我刚刚意识到任务需要有唯一的名称。我有所有名为 scripts 的任务,所以显然只有最后一个被执行了。
  • 哦,是的,你不能这样做:)
猜你喜欢
  • 1970-01-01
  • 2019-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多