mariocasciaro / gulp-concat-css

Concatenates css files, bubbling up import statements (as per the standard), and optionally rebasing urls and inlining local import statements.
MIT License
78 stars 19 forks source link

Incorrect paths when output is deeply nested #9

Closed JonathanTech closed 9 years ago

JonathanTech commented 9 years ago

Tree Structure

./Content
|-/bootstrap
|  |-Bootstrap.less
|-/Fonts
|  |-glyphicons-halflings-regular.eot
|-/css
|  |-/release
|  |  |-/1.0.x.x
|  |  |  |-mse-r-core.min.css

Bootstrap contains a reference to glyphicons-halflings-regular.eot as:

../fonts/glyphicons-halflings-regular.eot

my gulp file looks like this:

gulp.task('mse-r-core-css-notIE8',['clean-css'], function() {

var version = "1.0.x.x"
return gulp.src(["content/bootstrap.less"])
    .pipe(less())
    .pipe(concatCss(path.join( 'content/css/release',version,"mse-r-core.min.css"), { newLine: "\r\n" }))
    .pipe(gulp.dest("."));

});

the resulting url is:

..\..\..\..\..\fonts\glyphicons-halflings-regular.eot

I was able to fix this issue by changing some code, but I'm new to node and it's tools, so I'm not certain how to create a test case for this or if I am breaking any other test cases.

On line 35 of index.js you have

 var resourceAbsUrl = path.relative(file.base, path.resolve(path.dirname(file.path), url));

I changed it too

 var resourceAbsUrl = path.resolve(path.dirname(file.path), url);

and now my urls are being correctly mapped to:

..\..\..\fonts\glyphicons-halflings-regular.eot
mariocasciaro commented 9 years ago

Looking at your code, it seems you need to set the appropriate base path for your source files. Try with this:

gulp.src(["content/bootstrap.less'], {base: 'content'})
JonathanTech commented 9 years ago

When I have time I will consider making a demo project for you to play around with. As it stands, the code I changed is working flawlessly for me regardless of the base set. Thanks for getting it 95% of the way there for me with the package as it was.

mariocasciaro commented 9 years ago

No problem, but be sure to set the base path of the sources as explained above, that may solve the issue without any patch. Regarding your patch, it was breaking the unit tests, a symptom that it was fixing your particular problem but breaking other use cases. Anyway, don't hesitate to contact me for any other issue/concern.

JonathanTech commented 9 years ago

I think i saw that you changed the same test in your other branch though. I don't know if I can trust the test because of that. On Oct 1, 2014 8:42 AM, "Mario Casciaro" notifications@github.com wrote:

No problem, but be sure to set the base path of the sources as explained above, that may solve the issue without any patch. Regarding your patch, it was breaking the unit tests, a symptom that it was fixing your particular problem but breaking other use cases. Anyway, don't hesitate to contact me for any other issue/concern.

— Reply to this email directly or view it on GitHub https://github.com/mariocasciaro/gulp-concat-css/issues/9#issuecomment-57464461 .

mariocasciaro commented 9 years ago

Yes, you are right, the test in the new branch is the good one, you can try to apply the change and see how your patch runs against that.

mariocasciaro commented 9 years ago

Hey @JonathanTech let me know if the problem was fixed and if I can close this ticket.