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

用户名

编辑:有没有办法清除此代码?

任务咖啡

# 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'

任务咖啡

# 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);
});
斯文·舍嫩

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

// 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
...

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用src和dest相同文件夹更改或更新的gulp?

gulp.dest未创建目标文件夹

如何使Gulp等到dest文件完成?

如何使gulp.dest动态

如何通过递归复制文件夹而不在dest文件夹中包含源文件夹标签?

Gulp-定位文件夹及其子文件夹中的所有文件

gulp.dest()不会导致文件更新

gulp.dest不打印到文件

Gulp-处理dest文件的只读权限?

如何忽略gulp.dest()中的** / *?

如何在gulp.dest中使用来自gulp.src的源文件路径?

修改gulp.dest的路径

Gulp监视整个文件夹并编译保存的文件

Gulp:如何读取文件夹名称?

Gulp:如何删除文件夹?

如何从Webpack JavaScript中的文件夹,子文件夹及其子文件夹动态获取文件

Gulp:在目标位置保留单个文件的文件夹结构

Grunt-Contrib-Copy,如何在不覆盖 dest 文件夹中的现有文件/文件夹的情况下复制保持相同文件夹结构的目录内容?

用gulp / imagemin替换子文件夹中的文件

包含文件夹的子文件夹但不包含实际子文件夹(Gulp)的Glob

Gulp:将输出文件写入与src路径相关的子文件夹

Glob / minimatch:如何使用gulp.src()进行所有操作,然后排除文件夹但在其中保留一个文件

如何将可读流传输到gulp.dest()?

如何在gulp.dest()中找到父目录的路径?

如何授予文件夹及其子文件夹和文件的读写权限?

如何最好地删除文件夹及其子文件夹中的所有文件

Gulp.src 匹配带方括号的文件夹

TypeError:dest.on不是gulp中的函数

Gulp TypeError:dest.on不是函数