Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 663
David Chan Avatar asked Oct 08 '15 21:10

David Chan


1 Answers

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' {
   ...
}
like image 107
David Chan Avatar answered Oct 06 '22 06:10

David Chan