Grunt cssmin重新绑定相对URI? [英] Grunt cssmin rebasing a relative URI?
问题描述
我目前正在为我们的项目设置 grunt-usemin ,但我正在运行 cssmin
任务的一个小问题。
我们的项目依赖于一些外部库,一些额外的资产(如图像或字体)。问题是这些库没有相同的文件夹结构。
这是不同文件夹结构的一个例子
lib
| --lib1
| | --style1.css
| + - image1.png
+ - lib2
| --styles
| + - style2.css
+ - images
+ - image2.png
在index.html中,所有样式表都被引用并放入构建块中。因此,当usemin任务执行时,库的样式表被连接成一个缩小文件并放入输出文件夹中。相应的资产(图像)也被复制到此输出文件夹中,并在 img
文件夹中变得流畅。输出文件夹结构如下所示:
out
| --allstyles.min.css
| - image1.png
+ - image2.png
正如你所猜测的,连接的样式表(在本例中)有两个不同的相对URI:
image1.png
.. \images\image2.png
这是导致无法找到某些图像的问题。我需要一个解决方案将将所有相对URI重定向到out文件夹。我尝试使用 cssmin
的目标
和根目录
任务但无济于事。有人能指点我一个正确的配置这项任务或另一个Grunt任务,可以实现我在找什么?
预先感谢!
在cssmin文档/选项中查找:
解决此问题。
I'm currently setting up grunt-usemin for our project but I'm running in a small issue with the cssmin
task.
Our project depends on a few external libraries, some which bring a long some extra assets (like images or fonts). The problem is these libraries do not have the same folder structure.
This is an example of the different folder structures
lib
|--lib1
| |--style1.css
| +--image1.png
+--lib2
|--styles
| +--style2.css
+--images
+--image2.png
In the index.html all the stylesheets are referenced and put inside a build block. As such, when the usemin task executes, the stylesheets of the libraries are concatenated in one minified file and put inside the output folder. The corresponding assets (images) are copied over to this output folder as well and flatened in the img
folder. The output folder structure looks like
out
|--allstyles.min.css
|--image1.png
+--image2.png
As you can guess, the concatenated stylesheets has (in this example) two different relative URIs:
image1.png
..\images\image2.png
This is causing an issue where some of the images cannot be found. I need a solution to rebase all relative URIs to the out folder. I tried using the target
and root
options of the cssmin
task but to no avail. Could someone point me to a correct configuration of this task or to another Grunt task that could achieve what I'm looking for?
Thanks in advance!
look in the cssmin documentation/options:
- rebase: set to false to skip URL rebasing
That solves the issue.
这篇关于Grunt cssmin重新绑定相对URI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!