How to locate the path of parent directory in gulp.dest()?

I'm new comer in Gulp, and i got stock when i try to output my files to their parent's path.

My directories like this:


My goal is:


Here's what i'm doing:

I use ** because i want to match all of my page_* module.

gulp.task('test', function () {
    var files = ['./app/**/*.less'];
    return gulp.src(files, {
            base: '.' // Now the base url becomes where the *.less is.

My result:( which is obviously wrong :( )


So how can i output *.css into the corresponding app/page_*/css path?


The path you specify in the base option to gulp.src() isn't relative to each respective .less file, but rather the current working directory. This is usually the directory your Gulpfile.js resides in.

What you actually want to do is alter the path for each resulting .css file after your less() plugin has run, so when the .css files are written to the directory specified by gulp.dest() the /less/ part of the path has been replaced with /css/.

This is exactly what the gulp-rename plugin is for:

var gulp = require('gulp');
var less = require('gulp-less');
var rename = require('gulp-rename');

gulp.task('default', function () {
  return gulp.src( './app/**/*.less') 
    .pipe(rename(function(file) {
       file.dirname = file.dirname.replace(/less$/, "css");

With gulp.dest('.') you say 'here' Try with:


This should be work

Need Your Help

how to declare and initialize global arrays in javascript

javascript arrays global

In my html code, I need a global array which I use throughout my application. How to create and initialize global array variable in javascript..

iphone dev get user profile name, email using fbconnect api

iphone objective-c

i am using this for wall posting on facebook from my iphone app