Skip to content

Instantly share code, notes, and snippets.

@aNd1coder
Last active September 9, 2018 17:49
Show Gist options
  • Save aNd1coder/6913270 to your computer and use it in GitHub Desktop.
Save aNd1coder/6913270 to your computer and use it in GitHub Desktop.
config.rb for compass
# 默认编码
Encoding.default_external = "utf-8"
# compass插件
require 'autoprefixer-rails'
require 'csso'
# import远程scss文件
require 'remote-sass'
RemoteSass.location = "http://path/to/the/static/root"
on_sprite_saved do |filename|
if File.exists?(filename)
# 去除生成的sprite图文件名中hash部分
FileUtils.cp filename, filename.gsub(%r{-s[a-z0-9]{10}\.png$}, '.png')
FileUtils.rm_rf(filename)
end
end
on_stylesheet_saved do |filename|
css = File.read(filename)
File.open(filename, 'w+') do |io|
# 处理雪碧图URL参数 https://github.com/RaphaelDDL/compass-generic-config/blob/master/config.rb
io << css.gsub(%r{(?<start>-s)(?<hash>[a-z0-9]{10})(?<file>\.png)}, '.png?v=\k<hash>')
end
end
on_stylesheet_saved do |filename|
css = File.read(filename)
File.open(filename, 'w') do |io|
# 处理浏览器前缀 http://samgui.com/blog/Autoprefixer一个以最好的方式处理浏览器前缀的后处理程序/
io << AutoprefixerRails.process(css)
end
end
# Set this to the root of your project when deployed:
http_path = "http://path/to/the/static/root"
css_dir = "css"
fonts_dir = "css/font"
sass_dir = "css"
images_dir = "img"
javascripts_dir = "js"
# enable sourcemaps
enable_sourcemaps = true
sass_options = {:sourcemap => true}
# You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed
output_style = :compact
# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true
# To disable debugging comments that display the original location of your selectors. Uncomment:
line_comments = false
# sass_options = { :debug_info => true }
# If you prefer the indented syntax, you might want to regenerate this
# project again passing --syntax sass, or you can uncomment this:
# preferred_syntax = :sass
# and then run:
# sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass
@aNd1coder
Copy link
Author

添加远程@importsass文件功能,详情请参考《SASS实战之RemoteSass插件介绍》

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment