support-for
The support-for module allows Sass authors to conditionally add support for specific browser versions to their Sass module or Sass partials.
Autoprefixer is great for conditionally adding vendor prefixes, but sometimes you need more extensive CSS for specific versions of browsers. For example, adding px fallbacks to rem units when you need IE 8 support.
Authors of Sass code with support-for can specify which browser versions they want to support by setting a simple Sass variable, $support-for
.
Here are some example usages:
- The Sass author only wants to support Safari 8 and later (and no other browsers) because he is an asshole.
; // Normalize-scss uses support-for to conditionally // output CSS for old and new browsers. ;
- The Sass author wants to support the 4 most recent versions of all browsers which she can do by setting the wildcard browser,
'*'
. She also has to support IE 6 and later because the client hates her.
; ;
- The Sass author is working for a government client and every browser version has a specific version specified in the contract.
; ;
By the way, here's the default value of $support-for
:
// Support the last 4 versions of all browsers except IE. ;
support-for()
Update your Sass partials to use If a Sass module tells you that it uses support-for, you just need to override the default value of the $support-for
variable before you import that module. See the examples above to see some of your options.
If, however, you want to conditionally include Sass in the stylesheets you author, you can update your Sass code to wrap those lines of Sass with an @if
block that uses the support-for()
function.
If you later drop support for IE 10 (someday!), you just need to update the
$support-for
variable and your code will stop outputting the IE-10-specific
CSS.
Updating your module to use support-for
If you are a Sass module author wanting to use support-for in your module, it's quite easy to add it as a dependency.
Ruby Sass
Alter your my-module.gemspec
file:
- Find the line for your module's Sass dependency. It should look similar to this:
spec.add_runtime_dependency('sass', '~> 3.3')
- Just after that line, add this:
spec.add_runtime_dependency('support-for', '~> 1.0')
NPM (and node-sass)
Add your dependency with the following command:
npm install --save support-for
Bower
Add your dependency with the following command:
bower install --save support-for