简体   繁体   English

使用CSS最小化导入远程字体

[英]Remote font imports with css minification

I'm trying to concatenate & minify all bower package assets including css. 我正在尝试串联和缩小包括CSS在内的所有Bower软件包资产。 One of them is bootswatch design and it imports google fonts. 其中之一是bootswatch设计,它会导入Google字体。 Problem is, running css tasks on it results in timeout exception. 问题是,在其上运行css任务会导致超时异常。 I'm guessing it is trying to download those fonts and it takes too long as exception does not occur every single time. 我猜它正在尝试下载那些字体,并且花费的时间太长,因为不会每次都出现异常。

How would I go about resolving it? 我将如何解决呢?

Gulp imports: Gulp进口:

var gulpMinifyCss = require('gulp-minify-css');
var gulpConcatCss = require('gulp-concat-css');
var mainBowerFiles = require('main-bower-files');
var gulpFilter = require('gulp-filter');

Gulp task: Gulp任务:

gulp.task('compileBowerCss', function(){
    return gulp
        .src(mainBowerFiles())
        .pipe(gulpFilter('*.css'))
        .pipe(gulpConcatCss('bower.css'))
        .pipe(gulpMinifyCss())
        .pipe(gulp.dest(assetsFolder + cssFolder));
});

Exception: 例外:

events.js:85
  throw er; // Unhandled 'error' event
        ^
Error: Broken @import declaration of "https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" - timeout

Running this task alone and nothing else works fine always (as far as I can tell with limit testing), but running it in conjuction with other tasks results in mentioned error. 仅运行此任务,就没有其他方法可以正常工作(就极限测试而言),但与其他任务结合运行会导致上述错误。

I'd same bug. 我会遇到同样的错误。 Solution: pass processImport: false option to minifyCss pipe. 解决方案:将processImport传递给false: minifyCss管道。

.pipe(gulpMinifyCss({processImport: false}))

尝试使用npm本地化字体: https ://libraries.io/npm/roboto-font

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM