sass / sassc

libsass command line driver
Other
785 stars 131 forks source link

-w, --watch option #63

Open ciro207 opened 10 years ago

ciro207 commented 10 years ago

Hi guys,

sassc is incredible and really fast! Several times faster than ruby version! I miss the -w, --watch option

This is my fault? If not, is there any chance to add this feature?

Thanks!!!

HamptonMakes commented 10 years ago

No, we haven't built this yet. You could make it work with something like guard. But, this is definitely something we should build in.

mgreter commented 9 years ago

I think this will be pretty hard to implement portable! sassc currently is pretty C standard compliant. We only need some additional code on windows to parse the input arguments (getopt). File watching is unfortunately not part of posix and pretty much implemented differentely on every system. This should be somewhat obvious, since it basically involves an event which is triggered by the filesystem. With a fallback solution to checking every monitored file/directory in an interval (bad). I've done it with perl, but it was still a big pain, due to different implementations. Just read the decription for Filesys::Notify::Simple:

"A simple but unified interface to get notifications of changes to a given filesystem path. It utilizes inotify2 on Linux, fsevents on OS X, kqueue on FreeBSD and FindFirstChangeNotification on Windows if they're installed, with a fallback to the full directory scan if they're not available."

Unitil someone knows a C library that abstracts all these portability problems for *nix/mac/win, I don't think this is feasible, so I'm in favor of closing this issue. Seems to be a perfect candidate for other implementations to step in!

pukku commented 9 years ago

I think even if you can just watch one file, using some kind of polling technique, it would be useful. (The lack of this is the primary reason I'm going back to using the Ruby gem.)

chriseppstein commented 9 years ago

So, this exists: https://code.google.com/p/simplefilewatcher/

xzyfer commented 9 years ago

@chriseppstein simplefilewatcher looks promising from a glance.

As an alternative for the moment I've just supercharged the watcher in node-sass. It's now aware of the @import dependency graph and will only compile the ancestors (much like the current Ruby sass watcher).

IbnSaeed commented 9 years ago

Whats the status of this issue ? Will it be implemented or should this be closed ?

xzyfer commented 9 years ago

Noone is currently working on this. Our priority right now is getting Ruby Sass parity.

If you're using node/io.js node-sass currently has a great watcher. There are also binding for perl, ruby, python, and go.

ysimonson commented 9 years ago

We made something that builds on sassc to provide directory compilation and watching: http://github.com/dailymuse/gosass

Hope that helps :smile:

xzyfer commented 9 years ago

There no plans to implement this in the near future. Pull requests are welcome.

TheJaredWilcurt commented 8 years ago

+1 Using Node-Sass + Chokidar for now, but would prefer --watch in SassC.

saper commented 8 years ago

What could possibly be done portably is an interface to external file watcher that just feeds the file names via the standard input to libsass.

fgimian commented 8 years ago

+1 for me too :smile:

fabio-coolshop commented 8 years ago

+1

ziodave commented 8 years ago

+1

fgimian commented 8 years ago

Here's another way I documented that you can use using fswatch 😄

ziodave commented 8 years ago

Thanks @fgimian that's neat.

I just added -i ".*\.scss$" -e ".*" to the fswatch options to only watch for scss file changes.

fgimian commented 8 years ago

Ah nice @ziodave, glad you found it handy 😄

staghouse commented 5 years ago

Would love to have this now that sass-ruby is nearing end of life.

WnP commented 5 years ago

Why not just using entr to watch and reload?

olaf-w commented 5 years ago

I know I'm a little late to the party, but I found a workaround that works just fine for me as long as I just work on one scss / css files pair: Have the sassc input.scss output.css --style=... bash command repeat itself as described in this accepted stackoverflow answer.

In short: Bash (and probably other terminal flavors as well) provides a built-in "watch" function with a pretty straight forward syntax watch -n 30 sassc input.scss output.css --style=... for a 30 seconds repition.

I thought I'd add this here since 1) I haven't been aware of @fgimian 's exquisite solution :1st_place_medal: to date and 2) there's no need to even installing any additional tools.

Edit: Of course there's still the need for a browser tab reload, I solved this with one of dozens of addons available out there.

GitarMan commented 5 years ago

So, I tried some of the above solutions, but this seems to be the simplest one that works for me so I thought I'd share.

I made a simple shell script using a inotifywait with a while do loop.

#!/bin/bash
while inotifywait -r -e close_write sass; do
  sassc --style compact ./sass/style.scss ./style.css
done

You have to install inotify-tools if you haven't yet.

The -r flag means recursive because I'm using a ./sass/ directory with partials in sub-directories. The -e is the event-type flag. You may need to experiment with what exact event types your editor triggers when saving, there are often multiple opens / reads, but the 'close_write' event only triggered once per save for my editor (Atom) so that's the one that I used to trigger the sassc command. You can review the man page here: https://linux.die.net/man/1/inotifywait

My file structure is almost always something like the following (simplified). You can edit the script according to yours.

├── style.css
└── sass
    ├── style.scss
    └── elements
        ├── _elements.scss
        ├── _lists.scss
        └── _tables.scss

I put the script in my local path of /.local/bin/sasswatch so all I have to do is navigate to the appropriate directory and then type sasswatch

Don't forget to set execute permissions for the script with chmod 755 sasswatch

I'm running Linux Pop!_OS (Ubuntu).