0

I'm kinda new to gulp, and I've been trying to beautify my js source files. I have this task (which runs 100%) which uses 'gulp-beautify' to beautify the js files:

gulp.task('js', function() {
    return gulp.src('src/js/**/*.js')
        .pipe(beautify({indent_size: 4}));
});

And it doesn't work. The file stays the same. But, if I do this:

gulp.task('js', function() {
    return gulp.src('src/js/**/*.js')
        .pipe(beautify({indent_size: 4}))
        .pipe(gulp.dest('./foo/'));
});

The files outputted are beautified. Any idea why this is happening?

Thanks in advance!

NonameSL
  • 1,405
  • 14
  • 27

1 Answers1

1

The first task is beautifying the streams in memory, but they're not saved on the disk automatically. You must explicitly output the files somewhere to save the beautified files, like in your second task.

If you want to overwrite the files with their beautified version, you can use gulp.dest to output the files at the same place they are read.

gulp.task('beautify', function() {
  return gulp.src('src/js/**/*.js', { 
      base: "./" // specify the base option
    })
    .pipe(beautify({ indent_size: 4 }))
    .pipe(gulp.dest('./'));
}); 

Modify file in place (same dest) using Gulp.js and a globbing pattern

Community
  • 1
  • 1
Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129