javascript - 如何确保使用 Grunt 正确处理远程 @imports

标签 javascript node.js gruntjs grunt-contrib-cssmin

我使用 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/

相关文章:

node.js - "FFMPEG not found"即使 ffmpeg 二进制文件已添加到 package.json

javascript - 在 GruntJS 任务中使用 ‘this.files’ 时出现问题

javascript - 使用 javascript 导出时 Excel 工作表中的上标

javascript - 如何使用JS制作一个自玩贪吃蛇游戏?

javascript - 放置div1和div2 onclick事件的内容

node.js - sass 不编译我的媒体指令

node.js - 如何使用 Gulp 在流中替换?

javascript - 有没有办法在选框完成滚动一次后运行一行代码?

node.js - 文件上传完成后,如何使用nodejs撤销Azure的共享访问签名(SAS)?

gruntjs - grunt babel 100 kb 样式问题