ember.jssassember-clibroccolijs

Is it possible to pass environment variables to Ember cli sass during build?


I am using ember-cli-sass

I want to define some sass variables depending on env variable.

my theme1.scss file

@if 'theme1' == process.env.THEME {
  $color-secondary: #eee;
  $color-primary: #ff0;
}

How can i send my env to the broccoli build process

and how can I access the env variables in sass script?


Solution

  • after tracing the code back thru the ember-cli-sass module to the base broccoli-sass code i found that we can pass functions to sass in sassOptions.

    var sass = require('node-sass');
    var app = new EmberApp({
    
      sassOptions: {
        functions: {
          variable: function () {
            return new sass.types.String(process.env.VARIABLE);
          }
        }
      }
    });
    

    and then we can use it as a method in sassScript

    @if variable() == 'foo' {
       ...
    }