gulpgulp-clean-css

How to keep my relative paths with clean-css minifying?


Why does gulp code below remove my relative paths?

I am using clean-css:

gulp.task('build-css', function() {
    return gulp.src([
        'style.css',
        ])
        .pipe(sourcemaps.init())
        .pipe(cleanCSS({debug: true}))
        .pipe(concat('bundle.min.css'))
        .pipe(sourcemaps.write('./maps'))
        .pipe(gulp.dest('dist'))
        .pipe(livereload());
});

Original css:

@font-face {
  font-family: 'icomoon';
  src:  url('../fonts/social-media/icomoon.eot?mh2h47');
  src:  url('../fonts/social-media/icomoon.eot?mh2h47#iefix') format('embedded-opentype'),
    url('../fonts/social-media/icomoon.ttf?mh2h47') format('truetype'),
    url('../fonts/social-media/icomoon.woff?mh2h47') format('woff'),
    url('../fonts/social-media/icomoon.svg?mh2h47#icomoon') format('svg');
  font-weight: normal;
  font-style: normal;
}

After minifying with gulp:

@font-face{font-family:icomoon;src:url(fonts/social-media/icomoon.eot?mh2h47);src:url(fonts/social-media/icomoon.eot?mh2h47#iefix)

How can I keep these relative paths?


Solution

  • Try setting the rebase option to false (true is the default) so that your paths are not modified by cleanCSS.

    .pipe(cleanCSS( {debug: true, rebase: false} )