SASS:无效的\`import:预期的行尾为“;” -有时

ass CSS

神乐小哥Near

2020-04-03

我有一个仅包含导入语句的sass文件

@import "this";
@import "that";

如果我从命令行运行sass一切都很好

bundle exec sass foo.scss:foo.css

但是,如果我从脚本(也通过bundle exec)中运行它,则会对那些分号感到不满。这个...

template = File.read("foundation.scss")
sass_engine = Sass::Engine.new(template)
sass_output = sass_engine.render

...在sass_engine.render调用中产生以下内容:

(sass):1: Invalid @import: expected end of line, was ";". (Sass::SyntaxError)

如果我摆脱了分号,那么情况就相反了。它在命令行而不是在脚本中抱怨。

这是怎么回事,从脚本运行时如何使它接受分号?

第4023篇《SASS:无效的\`import:预期的行尾为“;” -有时》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

1个回答
蛋蛋猿 2020.04.03

区别在于Sass命令行程序会注意到“ scss”扩展名,并将文件解析为SCSS而不是传统的Sass。以编程方式进行操作时,您正在启动Sass引擎,而不是告诉它它是SCSS。

因此,错误是它将其读取为Sass而不是SCSS。

http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#options

这应该马上解决您的问题!

template = File.read("foundation.scss")
sass_engine = Sass::Engine.new(template, :syntax => :scss)
sass_output = sass_engine.render

中提琴!

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android