Make gulp.dest output to same directory

315 views Asked by At

I have a structure like

  • wwwroot/lib/site/scripts
  • wwwroot/lib/site/scripts/modules
  • wwwroot/lib/site/scripts/stuff

They all contain different js-files, I'd like to uglify them and output them to the same directory

The script below will only output them to

  • wwwroot/scripts
  • wwwroot/scripts/modules
  • wwwroot/scripts/stuff

I'd like to have them all in wwwroot/scripts, I do not wish to concat any files.

gulp.task('site-js', function () {
    var files = [
        'wwwroot/lib/site/scripts/**/*.js'
    ];

    return gulp.src(files)
        .pipe(uglify())
        .pipe(gulp.dest('wwwroot/scripts/'));
});
1

There are 1 answers

0
Derek Nguyen On BEST ANSWER

Sounds like gulp-rename is what you're looking for:

gulp.src('wwwroot/lib/site/scripts/**/*.js')
  .pipe(rename(path => { path.dirname = "" })) // remove relative path
  .pipe(gulp.dest('wwwroot/scripts/'));