1

I am searching for a solution allowing to modify the base part of path. I have a path like 'app/assets/theme/file.css' that i get with 'app/**/*.css' pattern and I would like to transform it to 'dist/assets/theme/file.css'.

For now I am doing something like:

gulp.src(paths.styles)
    .pipe(rename(function(path) {
        path.dirname = paths.dist + path.dirname;
    })

wich give me 'app/dist/assets/theme/file.css' instead of 'dist/assets/theme/file.css'. I don't find the way to erase 'app/' part.

How could I obtain the good result (using rename or another plugin if necessary) ?

ChrisV
  • 233
  • 4
  • 15

2 Answers2

3

There is a base option in gulp.src which you can use

gulp.src(paths.styles, {base: 'app'})
    .pipe(gulp.dest('dist'));

Read the doc for more details.

Lim H.
  • 9,870
  • 9
  • 48
  • 74
  • Thanks for the answer, I already read the doc but what I want to do is not moving the file but retrieving the path. – ChrisV Jul 06 '15 at 20:02
  • @ChrisV then you may be interested in this answer I wrote some time ago: http://stackoverflow.com/questions/29614917/getting-relative-source-destination-in-gulp-task/29615354#29615354 – Lim H. Jul 07 '15 at 08:55
0

You could try a String replace(), something like this:

gulp.src(paths.styles) .pipe(rename(function(path) { var newPath = paths.dist + path.dirname; path.dirname = newPath.replace('app/'); })

Matt
  • 17
  • 4
  • Thank you for your answer Matt but I was actually searching for something more general that could handle a "glob string" because my example is just a simplification of what I want to do. – ChrisV Jul 06 '15 at 20:04