Gulp.js - Use path from gulp.src() in gulp.dest()

后端 未结 2 1666
后悔当初
后悔当初 2020-12-12 16:26

Trying to create a gulp task that will pipe a bunch of files from different folders through LESS and then output them to a folder based on the original source. Consider this

相关标签:
2条回答
  • 2020-12-12 16:49

    You should have a look at gulp-rename

    Pretty much:

    gulp.src('./*/less/*.less')
      .pipe(less())
      .pipe(rename(function(path){
        // Do something / modify the path here         
      }))
      .pipe(gulp.dest('./finalRootDestination'))
    

    You leave gulp.dest pointing at your final output dir, but modify on the fly the individual file paths based on whatever logic you want inside the callback to gulp-rename.

    0 讨论(0)
  • 2020-12-12 16:55

    in your src set the base option and it will maintain the original path of your less file.

    gulp.task('compileLess', function () {
      gulp.src('./*/less/*.less', {base: './'})
        .pipe(less())
        .pipe(gulp.dest( './dist' ));
    });
    

    The ./dist destination can be anything. Wherever you want your file structure to be placed.

    Additional info here: https://github.com/wearefractal/glob-stream#options

    0 讨论(0)
提交回复
热议问题