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.com/css?family=Lato:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic" as no callback given.,Ignoring remote @import of "http://fonts.googleapis.com/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?
@import
s but this also doesn´t import remote css to avoid use of@import
. The callback function mentioned byclean-css
library would inline the css files remotely referenced by@import
. – Smashing