javascript - How to make sure remote @imports are processed correctly with Grunt - Stack Overflow

I use Grunt to build my project and cssmin task inside. My CSS file contains a remote @import statement

I use Grunt to build my project and cssmin task inside. My CSS file contains a remote @import statements and grunt build return a warning:

Running "cssmin:generated" (cssmin) task
>> Ignoring remote @import of ":400,300,300italic,400italic,600,600italic,700,700italic,800,800italic" as no callback given.,Ignoring remote @import of "+Pro:500" as no callback given.
>> 2 files created. 322.48 kB → 249.05 kB

I've found the following information in the clean-css library documentation:

In order to inline remote @import statements you need to provide a callback to minify method, e.g.:

var CleanCSS = require('clean-css');
var source = '@import url(http://path/to/remote/styles);';
new CleanCSS().minify(source, function (errors, minified) {
  // minified.styles
});

This is due to a fact, that, while local files can be read synchronously, remote resources can only be processed asynchronously. If you don't provide a callback, then remote @imports will be left intact.

How can I describe a cssmin task in my Gruntfile.js to correct handling remote @import statements?

I use Grunt to build my project and cssmin task inside. My CSS file contains a remote @import statements and grunt build return a warning:

Running "cssmin:generated" (cssmin) task
>> Ignoring remote @import of "http://fonts.googleapis./css?family=Lato:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic" as no callback given.,Ignoring remote @import of "http://fonts.googleapis./css?family=Maven+Pro:500" as no callback given.
>> 2 files created. 322.48 kB → 249.05 kB

I've found the following information in the clean-css library documentation:

In order to inline remote @import statements you need to provide a callback to minify method, e.g.:

var CleanCSS = require('clean-css');
var source = '@import url(http://path/to/remote/styles);';
new CleanCSS().minify(source, function (errors, minified) {
  // minified.styles
});

This is due to a fact, that, while local files can be read synchronously, remote resources can only be processed asynchronously. If you don't provide a callback, then remote @imports will be left intact.

How can I describe a cssmin task in my Gruntfile.js to correct handling remote @import statements?

Share Improve this question edited Jun 22, 2015 at 6:28 tolyasik asked Jun 17, 2015 at 9:53 tolyasiktolyasik 3553 silver badges13 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

Moving the @import statements to the top of the CSS file fixes it for me, I had the same problem. It seems like cssmin doesn't like it when @import statements are in the middle of the file. You can do this automatically with an options object in Grunt, see this answer for more details: https://stackoverflow./a/28454233/2142259

It is not the best solution, but it worked for me when I moved all the @import statements to another file and inserted it in my html file just before my main css file.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743587347a4475159.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信