用Grunt将变量传递给SASS [英] Passing variable to SASS with Grunt

查看:107
本文介绍了用Grunt将变量传递给SASS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够根据Grunt参数使用SASS导入文件。



使用grunt我想要:

  grunt someTask --skinName = yellow 

Inside app.scss我想以某种方式使用这个参数:

  @import$ skinName; 

有些上下文...



skinName.scss包含许多带颜色代码的SASS变量,以便我可以轻松地在应用程序中更改颜色。我应该在所有SASS @imports之前加入。

解决方案

你可以用grunt写的另一个scss文件解决这个问题构建过程:

$ p $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $ g $% 'skin.scss','@import''+ grunt.option('skinName')+';');
});

然后只需将 skin.scss 你的 app.scss


I want to be able to "@import" a file with SASS depending on a Grunt parameter.

With grunt I want to:

grunt someTask --skinName=yellow

Inside app.scss I want to somehow use this parameter:

@import "$skinName";

Some context...

This skinName.scss contains a lot of SASS variables with color codes so that I can easily change colors all over the app. I Should be included before all my SASS @imports.

解决方案

You could solve this with another scss file that is written by grunt during the build process:

grunt.registerTask('skin', function () {
    grunt.file.write('skin.scss', '@import "' + grunt.option('skinName') + '";');
});

Then simply import the skin.scss in your app.scss.

这篇关于用Grunt将变量传递给SASS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆