Search code examples
node.jsgulp

Using gulp.src(xyz).pipe(gulp.dest(xyz)); Facing Issues, Why not working for me?


Following code, tried with both ./ as src and dest. Gave security administration full rights to folders, just in case if there was any issue.

So whenever I change styles.css from the styles folder, the code runs good on gulp watch and detects change too. It does run styles command on file change too. But then no folders are created in my dest folder.

var gulp = require('gulp');

gulp.task('styles' , function() {
  return gulp.src('/app/assets/styles/styles.css')
        .pipe(gulp.dest('/app/styles.css'));
});



gulp.task('watch',function(){

    gulp.watch('./app/assets/styles/styles.css', 
    function() {
        gulp.start('styles');
    });
});

Solution

  • gulp.dest() takes a folder only, not a file. It probably is creating a folder, it is just called styles.css! Look under that for your file styles.css.

    You probably want gulp.dest('./app'). the file name will be retained automatically.

    I would also simplify to the below. gulp.start is not really documented.

    gulp.task('watch',function(){
        gulp.watch('./app/assets/styles/styles.css', ['styles']);
    });
    
    gulp.task('styles' , function() {
       //  added the . before /app here and in dest
      return gulp.src('./app/assets/styles/styles.css')
            .pipe(gulp.dest('./app'));
    });