简体   繁体   English

如何根据变量将.scss文件编译成多个.css文件

[英]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.

相关问题 我正在尝试将SCSS代码编译为CSS,但未找到变量 - I'm trying to compile my SCSS code into CSS but the variables are not found 我如何将数百个CSS文件转换为SCSS文件? - how do i convert hundreds of CSS file to SCSS files? 将多个SCSS文件导入一个SCSS文件,编译成一个CSS文件 - Import multiple SCSS files into one SCSS file and compile to one CSS file 如何将多个CSS文件和JavaScript文件编译为一个文件? - How do I compile multiple css files and javascript files into one file? 如何在文件夹树中递归编译SCSS文件? - How do I compile SCSS files recursively in folder tree? Laravel 5 Elixir:如何编译和移动.scss文件? - Laravel 5 elixir: How do I Compile and move .scss files? 如何在模板中将.SCSS 编译为.CSS 项目文件 - how to compile .SCSS to .CSS project files in template 我的SCSS文件不再编译为CSS。 我该如何解决? - My SCSS files are no longer compiling to CSS. How do I fix this? gulp:如何在 scss 文件之间通过管道传输 css 文件? gulp.src(['sassfile1.scss', 'cssfile.css','sassfile2.scss']) - gulp: How do i pipe a css file in between scss files? gulp.src(['sassfile1.scss', 'cssfile.css' ,'sassfile2.scss']) Webpack - 如何将scss编译成单独的css文件? - Webpack - how to compile scss into a separate css file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM