Compass & Autoprefixer Gem install

1.3k views Asked by At

Using this guide, I was still unable to install auto-prefixer using gem with compass:

https://github.com/postcss/autoprefixer#compass

gem install autoprefixer-rails
and add post-compile hook to config.rb:

require 'autoprefixer-rails'

on_stylesheet_saved do |file|
  css = File.read(file)
  File.open(file, 'w') do |io|
    io << AutoprefixerRails.process(css)
  end
end

Does it matter what directory I am in when I type 'gem install autoprefixer-rails? Should I be in the directory I call 'compass watch'?

I added the function to config.rb but compass is still not compiling with autoprefixer.

1

There are 1 answers

0
Asa SaPanther On

Try this in your config.rb project file:

require 'autoprefixer-rails'

on_stylesheet_saved do |file|
  css = File.read(file)
  map = file + '.map'

  if File.exists? map
    result = AutoprefixerRails.process(css,
      from: file,
      to:   file,
      map:  { prev: File.read(map), inline: false })
    File.open(file, 'w') { |io| io << result.css }
    File.open(map,  'w') { |io| io << result.map }
  else
    File.open(file, 'w') { |io| io << AutoprefixerRails.process(css) }
  end
end

Worked for me when Koala started acting up for me.