我使用 Famo.us 的 Yeoman 生成器创建了一个项目。它创建一个index.html 文件、一个styles 文件夹、一个src 文件夹和一个content 文件夹。gruntfile 指定index.html 包含styles 文件夹下的所有css 文件。但是,我想通过在我的 index.html 中引用它来包含 google fonts css 文件。我无法手动插入此文件,因为每当我在项目中保存文件时,grunt 都会覆盖我的更改,我该如何让 grunt 加载我的外部 css 文件/在我的 index.html 文件中引用它们?

有帮助吗?

解决方案

确保包含样式表 外部<!-- build:css 评论。

这有效:

<link href='http://fonts.googleapis.com/css?family=Gochi+Hand' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="lib/famous/core/famous.css" />

<!-- build:css(app/) css/app.css -->
<link rel="stylesheet" type="text/css" href="styles/app.css" />
<!-- bower:css -->

故障排除:

  • 如果这不适用于实时重新加载,请尝试重新启动服务器!
  • 请务必刷新页面(即清除缓存或打开开发者控制台)

示例文件:

本要点中的示例文件!

解释:

在index.html中重写CSS样式表的特定Grunt任务称为 cssmin, ,与 useminPrepareusemin.

基本上, useminPrepare 写了一个 cssmin 为您配置基于 <!-- build:css html 文件中的注释。看 使用分钟 文档。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top