我如何gulp.src整个文件夹及其子文件夹,然后根据文件的位置gulp.dest?

时间:2016-02-12 13:45:22

标签: gulp

编辑:有没有办法清理这段代码?

task.coffee

# Watch pages
gulp.task 'jade', ->
  # Watch index
  gulp.src('src/jade/index.jade')
  .pipe(jade(pretty: true))
  .pipe gulp.dest('dist')
  # Watch views
  gulp.src('src/jade/views/*.jade')
  .pipe(jade(pretty: true))
  .pipe gulp.dest('dist/views')
  # Watch views/products
  gulp.src('src/jade/views/products/*.jade')
  .pipe(jade(pretty: true))
  .pipe gulp.dest('dist/views/products')

gulp.watch 'src/jade/*.jade', ['html']
gulp.task 'html', (callback) ->
  runSequence 'jade', callback
  return

假设我正在运行我的gulp任务来处理我的.jade文件而我正在开发一个角度应用程序(views / ** / * .html),如何保持清理我的任务以便更改我的这样做的任务?

// gulp.src('src/jade/**/*.jade')
// gulp.dest('dist/path/*.html') so for example 'src/jade/index.jade'
// will be output into 'dist/index.html' and
// 'src/jade/views/products/product.jade' will be
// output into 'dist/views/products/product.html'

task.coffee

# Watch pages
gulp.task 'jade', ->
  gulp.src('src/jade/*.jade')
  .pipe(jade(pretty: true))
  .pipe gulp.dest('dist')
gulp.watch 'src/jade/*.jade', ['html']
gulp.task 'html', (callback) ->
  runSequence 'jade', callback
  return

task.js

gulp.task('jade', function() {
  return gulp.src('src/jade/*.jade').pipe(jade({
    pretty: true
  })).pipe(gulp.dest('dist'));
});

gulp.watch('src/jade/*.jade', ['html']);

gulp.task('html', function(callback) {
  runSequence('jade', callback);
});

1 个答案:

答案 0 :(得分:11)

您的问题的答案已在您自己的帖子中:

// gulp.src('src/jade/**/*.jade')

jade任务和watch中使用此功能应该完全符合您的要求:

gulp.task('jade', function() {
  return gulp.src('src/jade/**/*.jade')
    .pipe(jade({pretty: true}))
    .pipe(gulp.dest('dist'));
});

gulp.watch('src/jade/**/*.jade', ['html']);

这将在dist文件夹中生成文件,如下所示:

src/jade/index.jade -> dist/index.html
src/jade/views/example.jade -> dist/views/example.html
src/jade/views/products/product.jade -> dist/views/products/product.html
...