Last active
April 19, 2019 06:55
-
-
Save alexdunae/c6ec418fb166fdebc42b to your computer and use it in GitHub Desktop.
Guard + sass + autoprefixer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org/' | |
gem 'guard' | |
gem 'guard-sass', git: 'git@github.com:alexdunae/guard-sass.git' | |
gem 'autoprefixer-rails' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'autoprefixer-rails' | |
guard :sass, { | |
input: 'www/wp-content/themes/example/css', | |
output: 'www/wp-content/themes/example', | |
style: :compressed, | |
smart_partials: true, | |
all_on_start: true | |
} do | |
callback(:run_on_changes_end) do |_, _, files| | |
Array(files).each do |file| | |
time = Benchmark.realtime { autoprefix_file(file) } | |
benchmark = "[\e[33m%2.2fs\e[0m] " % time | |
::Guard::UI.info("\t\e[1;37mAutoprefixer\e[0m %s%s" % [benchmark, file]) | |
end | |
end | |
end | |
def autoprefix_file(file) | |
original_css = File.read(file) | |
File.open(file, 'w') do |io| | |
io << ::AutoprefixerRails.process(original_css, browsers: ['> 1%', 'ie >= 7']) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment