【发布时间】:2016-09-09 19:22:34
【问题描述】:
在 HTML 模板中使用 gulp-file-include 链接到 CSS 和 JavaScript 文件的推荐方法是什么?
例子:
index.html
@@include('templates/doc-begin.html')
<h1>Welcome</h1>
<p>Hello!</p>
@@include('templates/doc-end.html')
support/index.html
@@include('templates/doc-begin.html')
<h1>Support</h1>
<p>RTFM</p>
@@include('templates/doc-end.html')
templates/doc-begin.html
<!doctype html>
<html lang=en>
<head>
<title>Website</title>
<link rel=stylesheet href=?????/style.css>
</head>
<body>
这两个index.html 文件位于不同的文件夹级别,因此link 标记中样式表的相对路径不能硬编码(绝对路径有其自身的问题,在这种情况下是不可取的)。
基本上第一个link 标签需要是这样的:
<link rel=stylesheet href=style.css>
第二个类似:
<link rel=stylesheet href=../style.css>
gulp-file-include 中是否有方便的方法来执行此操作?
注意:
我目前有一个解决方法,我将一个变量作为"."、".." 或"../.." 传递给每个@@include 调用,但这既麻烦又脆弱。
【问题讨论】:
标签: javascript html css templates gulp