我使用 Grunt 来构建我的项目和 cssmin里面的任务。我的 CSS 文件包含一个远程 @import 语句并且 grunt build
返回一个警告:
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
我在 clean-css 中找到了以下信息图书馆文档:
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.
如何在我的 Gruntfile.js 中描述 cssmin 任务以正确处理远程 @import 语句?
最佳答案
将 @import
语句移动到 CSS 文件的顶部为我修复了它,我遇到了同样的问题。当 @import
语句位于文件中间时,似乎 cssmin
不喜欢它。您可以使用 Grunt 中的 options
对象自动执行此操作,有关详细信息,请参阅此答案:https://stackoverflow.com/a/28454233/2142259
关于javascript - 如何确保使用 Grunt 正确处理远程 @imports,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30888163/