dynamic src in gulp tasks

Viewed 398

i tried to make the src path dynamic and it worked but it messed up the dest somehow

var gulp = require('gulp');
var sass = require ('gulp-sass');
var sassUrl = '**/style.scss';

// compile sass
gulp.task('compile-sass', function(){
gulp.src([sassUrl])
    .pipe(sass())
    .pipe(gulp.dest('dist/css'))
});

in this exemple

  • src returns dev/sass/style.scss (which's what i want).
  • dest returns dist/css/dev/sass i obviously want it to be dist/css but its adding dev/sass at the end
1 Answers

I'm late but I think you want to look into setting your base for your src (this will impact the end location). Please see https://gulpjs.org/api#gulpdestpath-options for more info but here's a quick code snippet from it that'll help you out:

gulp.src('client/js/**/*.js') // Matches 'client/js/somedir/somefile.js' and resolves `base` to `client/js/`
      .pipe(minify())
      .pipe(gulp.dest('build'));  // Writes 'build/somedir/somefile.js'

gulp.src('client/js/**/*.js', { base: 'client' })
      .pipe(minify())
      .pipe(gulp.dest('build'));  // Writes 'build/js/somedir/somefile.js'
Related