我在让libsass编译SASS文件时遇到了问题。我可以很好地编译SCSS文件。
我有一个烧瓶应用程序,我已经安装了利巴斯,我正在使用libsass绑定沙斯。它工作良好,但缺少一些功能-它不能编译SASS,但它可以编译SCSS。我所做的是:
在我的applicaiton.py文件中
from flask import Flask
import sass
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
sass.compile(dirname=('client/sass', 'client/css'), source_comments=True)
app.run()我的两个测试文件是test_scss.scss,它可以工作:
$font-stack: Helvetica, sans-serif;
$primary-color: #333;
body {
font: 100% $font-stack;
color: $primary-color;
}和test_sass.sass
$font-stack: Helvetica, sans-serif
$primary-color: #333
body
font: 100% $font-stack
color: $primary-color文档中说,sass.complie可以接受SASS代码,但我只能让它接受SCSS代码。也就是说,当我运行我的应用程序时,只有.scss文件被编译成CSS。运行sass.compile后,我的应用程序的目录结构是:
- lib
- sass
- test\_sass.sass
- test\_scss.scss
有人建议我将SASS文件重命名为具有.scss扩展名的文件。就像test_sass.scss:‘
$font-stack: Helvetica, sans-serif
$primary-color: #333
body
font: 100% $font-stack
color: $primary-color但是,当我这样做时,我只会得到以下错误:
src/web-internal/server/applicaiton.py", line 8, in <module>
sass.compile(dirname=('client/sass', 'client/css'), source_comments=True)
File "/usr/local/lib/python3.4/site-packages/sass.py", line 516, in compile
raise CompileError(v)
sass.CompileError: b"Error: top-level variable binding must be terminated by ';'\n on line 2 of src/web-internal/server/../client/sass/test_sass.scss\n>> $primary-color: #333\n ^\n"我想使用SASS,并希望不满足于SCSS。有人有什么建议吗?我觉得sass文件里有些东西是我的记忆。
发布于 2015-08-03 20:37:31
我从来没有和sass.compile一起工作过,但我在周围找到了一份工作。
...
if __name__ == '__main__':
# Start sassc with --watch
sass_cmd = subprocess.Popen(['sass', '--watch', 'client/sass' + ':' + 'client/css'])
... 发布于 2021-08-18 21:30:41
Python包的compile()方法支持indented kwarg来告诉编译器给定的输入是缩进的.sass还是普通括号内的.scss。
如果您使用缩进.sass作为输入,只需按如下方式使用:
indented_sass_string = """
$font-stack: Helvetica, sans-serif
$primary-color: #333
body
font: 100% $font-stack
color: $primary-color
"""
css = sass.compile(string=indented_sass_string, indented=True)我假设如果您要传递整个目录,这将是可行的。如果您试图编译包含.sass和.scss文件的整个目录,我不知道会发生什么。
见docs:https://sass.github.io/libsass-python/sass.html#sass.compile
发布于 2022-02-19 18:27:07
https://stackoverflow.com/questions/31679647
复制相似问题