Gulp管道分离目标文件夹

3

我正在编写一个gulp任务,它会遍历多个文件夹并监视less文件。我希望将编译后的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);
    });
});
1个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
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);
    });
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,