简体   繁体   中英

Automatically compiling persistent css without compass watch

I have a compass sinatra project based off of this example .

As noted in this commit in a pull request and this pull request comment , sinatra is able to auto generate compiled css files on demand, as per request.

However, this seems like a waste since the server has to recompile even if there was no changes to the css file. Wouldn't it be better if the server watched for changes, recompiled on file changes, but would serve the same static css file on demand? This would work as if we ran "compass watch" and just served the compiled file.

My question then is: is there a good way to have sinatra automatically compile my sass files into a static CSS on change, without having to run watch compass separately?

Note: I also have a express/node/stylus project and it behaves like this, which leads me to believe this is possible and the logical way, and that I am just mis-configuring my sinatra app.

To change the CSS you have to either:

  • push new files to the application server (with a possible restart)
  • recompile in the background (eg compass watch on the server)
  • get the server to compile on changes (using something like the example you gave)

Personally, I favour the first. I'm not sure why I'd want the server to compile static assets? It takes up valuable resources, and the CSS changes on my dev machine, so why not compile them on my dev machine? I've not heard good answers to these questions, so I use a Guard file (or you could use sass watch or compass watch as a background task eg sass --watch app/views/stylesheets:app/public/css & ) to compile them, and then I check in the .css files and push them to the server.

YMMV.

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