Daniele Daniele - 1 year ago 106
Python Question

libsass-python compile a file

I recently find a fantastic python library compiling SASS really fast!
libsass-python seems to be very good and really fast

How I can use it to watch for any change in a sass folder or file and compile it in CSS ?
I do not understand how to pass a file and how to use --watch option


Answer Source

According to the help instructions (http://hongminhee.org/libsass-python/sassc.html), you can watch for modifications in file simply with :

$ sassc --watch source.scss target.css

Now, I get you want to watch all the files contained in a folder, and it doesn't seem that the command-line utility provides that.

For what I can tell, I'd see two possible workarounds.

1 : launching several sassc instances, one for each of your files. It pretty dirty, but doesn't require any effort, and I guess it is okay if you don't have too many files. Don't forget to terminate all the process (with killall for instance).

$ sassc --watch a.scss a.css & sassc --watch b.scss b.css # etc.

This is really not a great way to handle things, but it can be considered a temporary solution if you're in a hurry.

2 : use libsass inside a python program that would trigger compilation when a watched file is saved. To that end you can use another library like watchdog or pyinotify.

This seems to be a much better way to handle things.

Hope this was helpful, good luck !

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download