简体   繁体   中英

Can I configure SASS such that the scss files aren't in the web root?

It looks like SASS by default exposes scss files which I find rather obnoxious. Is there a way to configure SASS to look for scss files in a folder that's not in the web root but compile them into the public/stylesheets folder?

Yes!

If you use Compass, then you'll have a file /config/compass.rb that'll look like the following. Here I have my sass files in app/stylesheets and saving compiled in tmp/stylesheets (to help with heroku deployments)

/config/compass.rb

# This configuration file works with both the Compass command line tool and within Rails.
# Require any additional compass plugins here.
project_type = :rails
project_path = Compass::AppIntegration::Rails.root
#project_path = RAILS_ROOT if defined?(RAILS_ROOT)
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "tmp/stylesheets"
sass_dir = "app/stylesheets"
environment = Compass::AppIntegration::Rails.env
# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true

Old question but it's actually simple to do, you just pass the directories through to sass instead of specific .scss like so;

sass --watch /location/to/you/scss/:/location/to/your/css

Then any changes to scss will be saved into your css directory and it will also follow the same structure of your scss directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM