【问题标题】:Gulp pipe to separate destination foldersGulp 管道分隔目标文件夹
【发布时间】:2014-06-23 14:54:52
【问题描述】:

我正在编写一个 gulp 任务,它会遍历多个文件夹并监视更少的文件。我想将编译后的 css 通过管道传输回 less 文件来自的同一文件夹。不幸的是,我似乎找不到为每个文件提供单独的输出文件夹的好方法。

gulp.task('less:watch', function() {
    watch({
        glob: 'src/**/less/**/*.less',
        emit: 'one',
        emitOnGlob: false
    },function(files){
        return files
            .pipe(less({
                paths: [ path.join(__dirname, 'less', 'includes') ]
            }))
            // I need to pipe the files back to the folder they were generated from
            .pipe(gulp.dest(path.join(__dirname, 'less')))
            .on('error', gutil.log);
    });
});

【问题讨论】:

    标签: gulp gulp-less gulp-watch


    【解决方案1】:

    我相信您可以使用gulp.watch 一次处理一个文件:

    gulp.task('less:watch', function() {
        gulp.watch('src/**/less/**/*.less',function(evnt) {
          return gulp.src(evnt.path)
            .pipe(less({
              paths: [ path.join(__dirname, 'less', 'includes') ]
            }))
            .pipe(gulp.dest(path.dirname(evnt.path)))
            .on('error', gutil.log);
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-01
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      • 2020-07-21
      • 2015-08-21
      相关资源
      最近更新 更多