[英]How do I compile my .scss file into multiple .css files depending on the variables
I have a simple gulp build to compile my .scss files: 我有一个简单的gulp构建来编译.scss文件:
gulpfile.js: gulpfile.js:
gulp.task('sass', function() {
return gulp.src('app/assets/scss/**/*.scss')
.pipe(gulp.dest('app/assets/css'))
});
...
index.scss: index.scss:
$brand-primary: #b0b0b0;
// $brand-primary: #b1b1b1;
// $brand-primary: #b2b2b2;
...
In index.scss I have multiple versions of the $brand-primary
variable I want the file to compile with, eg I want gulpfile.js to automatically create multiple versions of index.scss depending on the $brand-primary
variable: index-1.css, index-2.css, index-3.css, etc. with the $brand-primary
value equal to #b0b0b0
first, then #b1b1b1
, then #b2b2b2
accordingly. 在index.scss中,我想编译文件的
$brand-primary
变量有多个版本,例如,我希望gulpfile.js根据$brand-primary
变量自动创建index.scss的多个版本:index-1 .css,index-2.css,index-3.css等,其$brand-primary
值首先等于#b0b0b0
,然后依次等于#b1b1b1
和#b2b2b2
。
The idea is to create multiple color options for my template without manually recompiling it for each color. 想法是为模板创建多个颜色选项,而无需为每种颜色手动重新编译。
PS: I am aware of CSS variables, however those won't work with color function like darken($brand-primary, 10%);
PS:我知道CSS变量,但是这些变量不能与
darken($brand-primary, 10%);
等颜色函数一起使用darken($brand-primary, 10%);
It would be very hard to do what you ask purely programatically. 纯粹通过编程来完成您的要求将非常困难。 I'm not even sure it's possible.
我什至不确定是否有可能。
Why don't you just create 3 index.scss files each with different $brand-color and and then import everything else in them. 您为什么不只创建3个index.scss文件,每个文件具有不同的$ brand-color,然后导入其中的所有其他内容。 Or even better make another file which will import all of your other *.scss files and then just import that file and color in each index file.
甚至更好地制作另一个文件,该文件将导入所有其他* .scss文件,然后仅在每个索引文件中导入该文件和颜色。 So your index files would look like this:
因此,您的索引文件如下所示:
$brand-primary: #b0b0b0;
@import 'style';
and _style.scss would have all of your other scss dependencies. 和_style.scss将具有所有其他scss依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.