【发布时间】:2013-05-31 01:03:01
【问题描述】:
我有以下目录结构(仅显示相关位用于说明目的):
proj \
\ Gruntfile.js
\ package.json
\ test \ (all my tests are in this folder structure)
\ app \
\ index.html
\ scripts \ (all my scripts are in here)
\ views \ (all views are in here)
\ styles \
\ style.css
\ oldie.css
\ print.css
\ images \
\ hires \ (all high resolution images are here)
\ lowres \ (all low resolution images are here)
我的 Gruntfile.js 文件的指南针部分如下所示:
compass: {
options: {
require: "susy",
sassDir: '<%= my.app %>/styles',
cssDir: '.tmp/styles',
imagesDir: '<%= my.app %>/images',
javascriptsDir: '<%= my.app %>/scripts',
fontsDir: '<%= my.app %>/styles/fonts',
importPath: 'app/components',
relativeAssets: true
},
dist: {},
server: {
options: {
debugInfo: true
}
}
}
<%= my.app %> 解析为 app。我的问题是我无法指定生成的 CSS 文件中的图像应该有以images/ 开头的路径,而不是像现在这样以app/images 开头的路径。
如果我将 imagesDir: '<%= my.app %>/images' 更改为 imagesDir: 'images'(或将后者添加为 imagesPath 选项的值),当 compass 尝试编译时,我会收到以下错误:
在加载路径中找不到与“lowres/sprites/*.png”匹配的文件。 您当前的加载路径是: /Users/joachimdyndale/Development/myProject/myapp_joachim/proj/images
我尝试添加 config: 'compass.rb' 属性并在 compass.rb 文件中包含以下内容:
http_images_path = '../images'
http_generated_images_path = '../images'
但是,上面的完全没有效果。
那么我的问题是:有没有什么我还没有发现的方法来配置这一切,以便它既能找到图像又能将正确的路径写入 CSS 文件,还是我必须更改我的目录结构,以便将app 文件夹中的所有内容上移一级?我真的很喜欢目前的结构,但我承认这可能是目前 Compass 根本不支持的极端情况。
我正在使用grunt-contrib-compass grunt 插件。
【问题讨论】:
-
将 relativeAssets 切换到
false是否对您有任何改变? -
不太清楚你的意思。是的,我前段时间在一个几乎相同的项目上尝试过(我只是最终没有使用指南针任务),但我明天会在工作中再试一次,以防万一。但是,我不确定它有什么好处,因为我必须有相对路径,因为我的机器与我们的测试、QA 和 Prod 环境之间的 URL 是不同的。
-
所以...实际上,将 relativeAssets 设置为 false 实际上解决了问题。但是:WTF?!将 relativeAssets 设置为 false 会导致 Compass 在生成 CSS 时使用相对路径。这与名称所暗示的内容以及文档所述将发生的内容完全相反。我称之为一个重大错误......
-
谢谢。请随意添加它作为对这个问题的回答,但随后解释为什么它也会有帮助;)
标签: build-automation compass-sass gruntjs web-frontend