Naor
Naor

Reputation: 24103

gulp rename doesn't work as expected

I am trying to use gulp rename to files in a stream. This is my code:

var jsFiles = gulp.src(['app/scripts/modules.js', 'app/scripts/**/*.js'])
    .pipe(map(function(path, callback) {
        path.dirname = Path.join('./dist', 'scripts', path.basename + path.extname);
    }));

I was hopping to get the following conversion:

  app/scripts/*     -> dist/scripts/*
  app/scripts/abc/* -> dist/scripts/abc/*

Instead, I got:

app/scripts/*     -> app/scripts/dist/scripts/*
app/scripts/abc/* -> app/scripts/dist/scripts/abc/*

What is wrong with this code? Anyway, an alternative is something like the map function. I found this: https://github.com/dominictarr/map-stream but I can't figure out how to use it for this need.

Upvotes: 0

Views: 877

Answers (1)

Preview
Preview

Reputation: 35846

You can specify a base in gulp.src to determine the starting directory of the paths of matched files. By default it's the process.cwd(), but you can change it to whatever you want.

So the relative paths will crop all the base part you have specified.

var jsFiles = gulp.src(['app/scripts/modules.js', 'app/scripts/**/*.js'], { base: 'app/scripts' })

Upvotes: 0

Related Questions