Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
782 views
in Technique[技术] by (71.8m points)

sass - How does SCSS locate partials?

I'm looking through the bower foundation project and I'm getting stumped on how the project is able to locate the partials. In particular, I'm looking at the _settings.scss that has a relative reference in it I just don't quite understand.

On line 58 there is a reference to foundation/functions but this partial (_functions.scss) is a sibling of the settings partial. I'm confused as why there is a reference to the parent directory foundation on that line. I'm also confused as to how this works. Why would the settings file not look for a directory named foundation at the same level?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The answer becomes clear if you attempt to import a file that does not exist. Here's an excerpt of the error generated on http://sassmeister.com/ when you try to import "foo"; (which doesn't exist):

File to import not found or unreadable: foo.
Load paths:
  /app
  /app/lib/sass_modules
  /app/vendor/bundle/ruby/2.0.0/gems/compass-0.12.6/frameworks/blueprint/stylesheets
  /app/vendor/bundle/ruby/2.0.0/gems/compass-0.12.6/frameworks/compass/stylesheets
  /app/vendor/bundle/ruby/2.0.0/gems/susy-1.0.9/sass

If Sass begins searching for the requested file relative to each of those directories until it finds it.

For vanilla Sass, one would add extra paths via the --import-path option:

sass --watch test.scss:test.css --load-path ../path/to/lib/ --load-path ../path/to/otherlib/

Compass users would use additional_import_paths or add_import_path in their config.rb (see: http://compass-style.org/help/documentation/configuration-reference/)

add_import_path "../path/to/lib/"

Only the authors of Foundation can answer your specific question as to why they would write the import that way. But this is why it works.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...