Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inlined imports should be rebased to current file #44

Merged
merged 1 commit into from
May 31, 2017

Conversation

jessebluemr
Copy link
Contributor

My problem is related to #42

Problem description

File import.css:

@import url(../otherdir/imported.css);
p.import
{
    background: url(import.png);
}

File otherdir/imported.css

p.imported
{
    background: url(import2.png);
}

Will fail by:

gulp.src(['dir/import.css'])
.pipe(cleanCSS({}))
.pipe(gulp.dest("out"))

with an Exception that ../otherdir/imported.css can not be resolved.

I had expected an outcome like this:

minified 'import.css':

p.imported{background:url(../otherdir/import2.png);}
p.import{background:url(import.png);}

I was not able to fix this problem by configuration, because the path of the current file is required to correct the rebaseTo option.

Solution

This fix always transports the file.path together with the contents to CleanCss.minify, which enables the imports of relative files.

A second problem occurred when inline: ['local'] is required. The image URLs defined in the imported css files were unexpected rebased to the current working directory. I had expected a rebase relative to the current file, so that the browser can import e.g. all images relative from the minified css file. Like in the sample above.

The patch ensures that the rebaseTo option is defined as the parent directory of the current processed file if not otherwise specified.

@scniro scniro merged commit f389d8f into scniro:master May 31, 2017
@scniro
Copy link
Owner

scniro commented May 31, 2017

@jessebluemr thank you very much for your work! I've been trying to solve this one for a bit now and I'm very pleased to see you took the time to contribute for this one. I'll publish up a new version on npm shortly. Rock on!

@scniro
Copy link
Owner

scniro commented May 31, 2017

@jessebluemr 3.4.1 now out in the wild

@jessebluemr
Copy link
Contributor Author

@scniro Thank you very much! It was a pleasure to contribute.

@jessebluemr jessebluemr deleted the rebase-fix branch June 1, 2017 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants