如何在预编译期间包含自定义 SASS 函数?
我已经使用 Ruby 代码成功扩展了一些 SASS 函数(http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#adding_custom_functions),并且我的扩展在开发中正确加载,但是当我预编译时我的资产,扩展未加载。代码位于 /app/models 中,但这可能不是它的最佳位置。
我尝试在几个不同的配置文件中明确要求该文件,但在预编译期间它仍然无法加载。这似乎也是一个糟糕的方法。
我知道代码无法加载,因为预编译的 CSS 以明文形式保留了 CSS 中的函数名称。不会抛出任何错误。
那么:像这样的文件最适合存放在哪里,如何让 SASS 在预编译期间加载该文件?
I've successfully extended some SASS functions with Ruby code (http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#adding_custom_functions), and my extensions are loading correctly in development, but when I precompile my assets, the extensions are not loaded. The code lives in /app/models, but this is probably not the best place for it.
I've tried explicitly requiring the file in a few different config files, but it continues to fail to load during precompile. This also seems like a poor approach.
I know that the code is failing to load because the precompiled CSS leaves the function names in the CSS in plaintext. No errors are thrown.
So: Where's the best place for a file like this to live, and how do I get SASS to load the file during precompile?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题最终是我错误地需要了文件,使用的是配置根目录而不是应用程序根目录。假设尝试包含不存在的文件时会抛出错误,但显然不会。有一次,我在 config/application.rb 中正确要求了该文件,预编译能够访问我的 SASS 扩展
The problem ended up being that I was requiring the file incorrectly, was using the config root rather than the app root. Assumed an error would be thrown when trying to include a nonexistent file, but evidently not. Once, I required the file correctly in config/application.rb, the precompile was able to access my SASS extensions