Passing in variable values when calling `sass` fro

2020-07-29 16:22发布

问题:

This question was asked a few months ago but ended not having an answer so I'm wondering if in that time one has come up.

I want to use mixins to turn my relative url's into absolute ones without hard-coding the host in the file. I'm not using rails or ruby ... rendering it standalone, called by a web server written in a different language. it'd be nice to be able to specify the base/host during the command line call -- with the server supplying the proper protocol, host, port, etc. for sass to just tack on relative url's at the end of.

The 'solution' that the last question had was that the asker didn't really need this functionality. Maybe I can do this another way?

(I'd also rather not interpolate the entire sass file with a pre-processing script)

回答1:

The functionality you seek is already part of Compass. Use the URL helper functions for your assets (images, stylesheets, fonts)

.foo {
    background-image: image_url('my-image.png');
}

The config.rb options relevant to your question are:

  • http_path
  • images_dir
  • relative_assets

(see all configuration variables)

If you want to have settings that are different for development vs production mode, you can do this:

if environment == :production
    relative_assets = true
elsif environment == :development
    relative_assets = false
end

To change modes, your command requires the addition of the environment flag:

compass compile -e production


标签: sass