Filippo oretti
Filippo oretti

Reputation: 49873

Gulp dest() dynamic destination folders based on file names

I want to iterate over all the src files and move every file in a folder named with the file name itself, for example.

from:

hello.js
omg.js

to:

hello/
  hello.js
omg/
  omg.js

I have this task:

gulp.src('/*.js')
  .pipe(gulp.dest('/' + filename here.......));

How do i achieve this?

Upvotes: 1

Views: 2277

Answers (1)

Foysal Osmany
Foysal Osmany

Reputation: 1581

gulp.task('pack', function () {
  return gulp.src('temp/**/*.js')
    .pipe(uglify())
    .pipe(rename(function (path) {
        path.dirname += "/"+path.basename;
        path.extname = ".min.js";
    }))
    .pipe(gulp.dest('./build'));
});

Upvotes: 3

Related Questions