How to make gulp.src the entire folder and its subfolders, and then gulp.dest based on the location of the files?

EDIT: Is there a way to clear this code?

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

Let's say I run my gulp task to process my .jade files and I am working on an angular application (views / ** / *. Html), how can I clear my task in change my task to do this?

// 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);
});
+4
source share
1 answer

The answer to your question is already in your own message:

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

Using this in your task jadeand watch, you must accomplish exactly what you want:

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

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

This will create files in the folder distas follows:

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
...
+7
source

Source: https://habr.com/ru/post/1628512/


All Articles