如何将变量传递给 scss 处理器?

How do I pass variables to scss processor?

我目前的设置是 前端: VueJS

后端 Python、龙卷风

Vue 是通过 cdn 用于单独的静态模板。 Tornado 提供模板。 我正在使用 python scss 库来编译 scss,这部分非常简单。

sass.compile(dirname=(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static/scss'), os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static/css')), output_style='compressed')

我有两个 config.py 文件,其中包含两种不同配色方案的配置,我想使用将这些文件中的颜色变量传递给 scss 文件,但不知道是否有way/possible。

我可以使用 tornado 将全局变量传递给模板,但这不是我需要的,因为 scss 文件必须在此之前使用这些颜色进行编译。 在此之前我已经做了很多研究,但找不到我真正需要的东西,所以也许有人以前做过。

啊哈!您可以将 custom functions 传递给编译器以与文件通信。

https://sass.github.io/libsass-python/sass.html#custom-functions