什么是使用 gulp-file-include 在 HTML 模板中链接 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
调用中传递变量 "."
、".."
或 "../.."
,但这很麻烦且脆弱。