grunt-contrib-cssmin icon indicating copy to clipboard operation
grunt-contrib-cssmin copied to clipboard

What happened to relativeTo?

Open sebastian-zarzycki opened this issue 9 years ago • 5 comments

0.12.x versions broke cssmin for me completely. The result is just empty file, because relativeTo is not passed to clear-css (this results in an empty file). Additionally, something's wrong with url rewriting. In 0.11.0, I had just to to pass root to options (and relativeTo was set per file in task itself). Now, relativeTo is gone, there's no way to pass it for every file from grunt config, but even if I fake it and set from config, url rewriting doesn't work.

Simple case:

  • css file sitting in ./client/style/application/image.css
  • in it, as part of class def : background-image: url('../../resource/asset/logos/white/logo.png');
  • target dir, dist, has ./dist/resource/(...) in it
  • grunt:
cssmin: {
    options: {
        keepSpecialComments: 0,
        root: 'client'
    }
    custom: {
        files: [
            {
                src: ['client/style/application/image.css'],
                dest: 'dist/image.css'
            }
        ]
    }
}

dist/image.css

expected result background-image: url('resource/asset/logos/white/logo.png');

actual result background-image: url('../../resource/asset/logos/white/logo.png');

same config in 0.11.0 background-image: url(/resource/asset/logos/white/logo.png); (almost correct, but adding the leading / at the beginning - why?)

sebastian-zarzycki avatar Mar 21 '15 01:03 sebastian-zarzycki

I'm also experiencing a similar issue. Using the following code...

cssmin: {
   options: {
      rebase: true,
      relativeTo: '<%= compile_dir %>',
      target: '<%= compile_dir %>',
      keepSpecialComments: 0, 
      advanced: true
   },
   bin: {
      files: [{
         src: [
            '<%= vendor_files.css %>',
            '<%= compile_dir %>/assets/<%= pkg.name %>-<%= pkg.version %>.css'
         ],
         dest: '<%= compile_dir %>/assets/<%= pkg.name %>-<%= pkg.version %>.css'
      }]
   }
},

...produces different results in different versions of cssmin:

Result in v0.11.0 (rebasing produces correctly-formatted path)

.k-map .k-marker{background-image:url(../vendor/kendo-ui/styles/Default/markers.png)}

Result in v0.12.2 (rebasing produces malformed path, resulting in 404 error)

.k-map .k-marker{background-image:url(../../vendor/kendo-ui/styles/Default/markers.png)}

nklein1 avatar Apr 14 '15 18:04 nklein1

We're seeing this in production too. Having to stick on v0.11 as later versions produce incorrect url paths.

THemming avatar Oct 10 '15 08:10 THemming

We are having the same issue

Bnaya avatar Oct 14 '15 15:10 Bnaya

#241

Bnaya avatar Oct 14 '15 15:10 Bnaya

I spent some time trying to get rebase working with cssmin for the latest version 1.0.1 and couldn't, until I saw this thread and tried it with version 0.11.0. I finally managed to get it working as I needed with the following options:

 cssmin: {
            options: {
                keepBreaks: true,
                rebase: true,
                target: "../Web/common",
                showLog: true,
                keepSpecialComments: true,
                aggressiveMerging: false,
                mediaMerging: false,
                restructuring: false
            }
        }

So it seems to me there is a problem not only an issue with relativeTobut also with target? Since I didn't need to use relativeToto do what I needed, but I needed to use an older version.

pauloya avatar Jul 06 '16 08:07 pauloya