咕噜生成时更改本地链接到生产链接?
问题描述:
我们可以在grunt构建过程中更改咕噜声中的链接,这些链接主要是生产链接的本地链接?咕噜生成时更改本地链接到生产链接?
例如,
.a-container {
background: url(../images/hello.jpg) no-repeat top center;
background-size: 100%;
}
建立之后,它看起来应该像
.a-container {
background: url(http://hello.com/blah/blah/hello.jpg) no-repeat top center;
background-size: 100%;
}
我们有URL前期可在繁重的文件进行配置。
答
要完成我开始的问题,请在这里介绍如何实现它。
compass: {
dist: {
options: {
config: 'app/config.rb',
sassDir: 'app/styles',
cssDir: 'dist/styles',
imagesDir: 'app/images/',
javascriptsDir: 'app/scripts',
fontsDir: 'app/styles/fonts',
importPath: 'app/components',
outputStyle: 'compressed',
},
},
}
而你应该有一个config.rb文件,因为Compass不公开某些选项作为命令行参数。
config.rb
http_images_path = "http://cdn.example.com/images/"
在你的SASS/SCSS文件
也不要忘记使用的,而不是image_url('hello.jpg')
只url('hello.jpg')
,网址()是由北斗忽略。
下次运行grunt compass:dist
时,您将会将url插入生成的css文件中。
答
如果你没有使用原始CSS卡住,我建议在项目顶部投掷grunt-contrib-compass。您可以设置开发/生产环境并在需要时运行它们。你会特别想看看option for images。以下列方式我矿结构:
compass: {
dev: {
sassDir: 'build/sass',
cssDir: 'stylesheets',
imagesDir: 'build/assets/images/'
},
production: {
sassDir: 'build/sass',
cssDir: 'stylesheets',
imagesDir: 'http://example.com/images'
},
}
你不必一定利用SASS/comapss的其他部分(尽管会有一些前期工作,围绕切换目录和文件结构)。
如果这种方法不适用于您,您可能需要查看Yeomans usemin task。不幸的是,我不是,因为熟悉那个,也不能提供很多帮助。
+0
非常感谢这个整洁的把戏:) – 2013-05-05 18:42:29
你需要在指南针中有哪些选项在grunt-contrib-compass中不可用?你指定的是这里:https://github.com/gruntjs/grunt-contrib-compass#httpimagespath – imjared 2013-05-07 15:38:35
是的,这是真的,但它不工作如预期,你会得到一个错误说:“错误:无效的选项: - -http-images-path“..这里是问题和解决方法,https://github.com/gruntjs/grunt-contrib-compass/issues/13 – 2013-05-07 18:48:08
很酷,很高兴知道。很高兴这个解决方案为你工作。我 imjared 2013-05-07 18:59:48