为什么 Rails Asset Pipeline 使用 require 而不是 @import? [英] Why Rails Asset Pipeline uses require instead of @import?

查看:54
本文介绍了为什么 Rails Asset Pipeline 使用 require 而不是 @import?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果 Rails (3, 4) 使用 SASS 预编译 CSS,为什么默认使用require",而不是 Sass 指令@import"(http://sass-lang.com/documentation/file.SASS_REFERENCE.html#import)

If Rails (3, 4) uses SASS for precompile the CSS, Why uses "require" for default, instead of Sass directive "@import" (http://sass-lang.com/documentation/file.SASS_REFERENCE.html#import)

相同的 Rails 文档建议使用@import"(http://edgeguides.rubyonrails.org/asset_pipeline.html)

The same Rails documentation suggest to use "@import" (http://edgeguides.rubyonrails.org/asset_pipeline.html)

推荐答案

As 在您链接到的文档中注明@import 更可取,因为 Sass 变量可以在文件之间共享.但是拥有链轮提供的 require 指令允许您包含来自 gems 的样式表或完全绕过使用 Sass.

As noted in the document you linked to, @import is preferable because Sass variables can be shared between files. But having the Sprockets-provided require directive allows you to include stylesheets from gems or bypass using Sass altogether.

完成一项任务的方法通常不止一种,有选择是件好事.例如,Javascript 有许多依赖管理的解决方案,但简单的链轮require 通常足以满足简单的应用程序.

There is usually more than one way to accomplish a task, it’s good to have options. For instance, Javascript has many solutions to dependency management, but the simple Sprockets require is often adequate for simple applications.

这篇关于为什么 Rails Asset Pipeline 使用 require 而不是 @import?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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