Use custom SASS functions . The following is a complete working example.
styles.sass:
$primary_color: getenv("SASS_VAR_PRIMARY_COLOR", white) body background: $primary_color
sass_functions.rb:
module Sass::Script::Functions def getenv(name, default) assert_type name, :String value = ENV.fetch(name.value, nil) if not value return default end begin Sass::Script::Parser.parse(value, 0, 0) rescue Sass::Script::String.new(value) end end end
Command line:
SASS_VAR_PRIMARY_COLOR='#123456' sass -r ./sass_functions.rb styles.sass styles.css
If you use Compass, you can put module Sass::Script::Functions directly in config.rb and compile the styles with:
SASS_VAR_PRIMARY_COLOR='#123456' sass --compass styles.sass styles.css
source share