简体   繁体   English

Medialize / sass.js是否可以修改sass变量?

[英]Medialize/sass.js is it possible modify sass variables?

I want to know if there is a method that permits to change sass vars in The browser and see live changing. 我想知道是否有一种方法可以允许在浏览器中更改sass vars并进行实时更改。 In less.js there is this method called "modifyVars". 在less.js中,有一个称为“ modifyVars”的方法。 Is there a similar functionality in sass.js? sass.js中有类似的功能吗?

Less uses lazy loading and last declaration wins for variables so you can put the definition of the variables to override afterwards with "modifyVars"; Less使用延迟加载,变量最后声明胜出,因此您可以使用“ modifyVars”将变量的定义覆盖。

With Sass you can override only variables defined with !default . 使用Sass,您只能覆盖!default定义的变量。 You can override these variables by putting their definition at the start of your code. 您可以通过将它们的定义放在代码的开头来覆盖这些变量。

Sass.writeFile('code.scss', '$var: red !default; p { color: $var; }');
Sass.compile('$var: green; @import "code.scss";', function(result) {
  console.log(result);
});

Should compile into: 应该编译成:

p { 
color: green; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM