Grunt 到基本 src 的相对路径以提高效率

Grunt relative paths to base src for efficiency

所以,我一直在努力优化我的网站。现在,我有一个非常好的模板。它看起来像这样:

<!doctype html>
<html class="no-js" lang="">
<head>
    <!-- shiny optimizations -->
    ...
    <!-- Ooh look! An important example that will help you understand my question! -->
    <link rel = "stylesheet" href = "release/base/css/normalize.css">
    include "page/head.html"
</head>
<body>
    include = "page/body.html"
</body>
</html>

所以在每一页中,它的构成如下

现在,我有一个名为 /base 的目录(在根目录中),它包含优化和其他有趣的东西,比如规范化、浏览器兼容性等。

Base 在所有项目中都将保持不变,模板文件也是如此,但项目的位置会发生变化。以下面的文件结构为例。

base
    favicon.ico
    /css
        ...
    /js
        ...
source
    ...
release
    ...
foo
    /release
        ...
    /source
        ...
    index.html
    /foobar
        /release
            ...
        /source
            ...
        index.html
bar
    /release
        ...
    /source
        ...
    index.html
baz
    /release
        ...
    /source
        ...
    index.html

所以baz、bar、foo需要通过

引用优化
../base

foobar需要通过

引用
../../base

而 root 只需要通过

base

因此,根据某些文件的深度,我想将其更改为

<link rel = "stylesheet" href = "{changeMeBasedOnFileDeepness}/base/css/normalize.css">

<link rel = "stylesheet" href = "../../../base/css/normalize.css">

tl;dr:我想允许文件从任何地方引用基本目录。

这是在 github 页完成的,您可以查看存储库 here

干杯,

真理精灵

原来这是一个 XY 问题。我需要做的就是得到一些看起来像这样的闪亮符号:

/base/css/...

这将变得非常复杂

简而言之:

使用网络服务器时,/foo/bar 表示法会让您进入根目录