Why Rails Asset Pipeline uses require instead of @import?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 21:00:24

问题


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)

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


回答1:


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.

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.



来源:https://stackoverflow.com/questions/23554270/why-rails-asset-pipeline-uses-require-instead-of-import

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!