sassgruntjsgrunt-contrib-cssmin

grunt cssmin @import parameters in url


I am looking for a way to put a version parameter in the url tail of some @import statements in sass file:

@import url('custom-style.css?v='+random(99999));
@import url('custom-style-mobile.css?v='+random(99999));

Grunt sass doesn't seems to reject this statement, but cssmin task does:

Running "cssmin:minify" (cssmin) task Warning: Broken @import declaration of "custom-style.css?v=1" Use --force to continue.

cssmin: {
            options: {
                keepSpecialComments: 1
            },
            minify: {
                expand: true,
                cwd: '<%= paths.dest.css %>',
                src: ['*.css', '!*.min.css'],
                dest: '<%= paths.dest.css %>',
                ext: '.min.css'
            }
        },

There is a way to avoid this warning?


Solution

  • The issue is because the question mark '?' is added to a file rather than an url. try giving an http reference to the same resource or the cdn link then it will work.

    $rand: random(99999);
    @import url("http://yourcdn.com/custom-style.css?v=#{$rand}");