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

7 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
Run Code Online (Sandbox Code Playgroud)

比方说,我跑我的一口任务来处理我的.jade文件和我工作的角度应用程序(浏览量/**/*.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'
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

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);
});
Run Code Online (Sandbox Code Playgroud)

Sve*_*ung 12

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

// gulp.src('src/jade/**/*.jade')
Run Code Online (Sandbox Code Playgroud)

在你的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']);
Run Code Online (Sandbox Code Playgroud)

这将在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
...
Run Code Online (Sandbox Code Playgroud)