Search code examples
gulpdotlessgulp-less

gulp-less relative images paths not flattened?


I have the following document structure

└── Content
    ├── Images
    │   ├──  document.png
    │   └──  document2.png
    └── Css
        ├──  Controls
        │    └──  Document.less
        └──  Main.less

Content/Css/Main.less:

@import "Controls/document.less";

Content/Css/Controls/Document.less:

.Document
{
    .Image
    {
        background-image: url(../../Images/document.png);
    }
    .Image2
    {
        background-image: url('../../Images/document2.png');
    }
}

if i run this with the following gulp script

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

gulp.task('css', function () {
    var source = 'Content/Css/Main.less';
    var destination = 'Content/Css';
    // place code for your default task here
    gulp.src(source)
        .pipe(less())
        .pipe(gulp.dest(destination));
});

i get the following

.Document .Image {
  background-image: url(../../Images/document.png);
}
.Document .Image2 {
  background-image: url('../../Images/document2.png');
}

Buf if i run this with dotless i get

.Document .Image {
  background-image:url(../Images/document.png)
}
.Document .Image2 {
  background-image:url('../Images/document2.png')
}

Is there any way to get the same output with Gulp without changing the structure of the less code (Note: this is just a example in reality i have multiple folders and less files..).


Solution

  • I found a solution add { relativeUrls: true } to less() and it works as intendent.