sassc icon indicating copy to clipboard operation
sassc copied to clipboard

-w, --watch option

Open ciro207 opened this issue 9 years ago • 21 comments

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!!!

ciro207 avatar Jul 24 '14 09:07 ciro207

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.

HamptonMakes avatar Oct 05 '14 15:10 HamptonMakes

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!

mgreter avatar Dec 29 '14 22:12 mgreter

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.)

pukku avatar Jan 12 '15 21:01 pukku

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

chriseppstein avatar Jan 12 '15 22:01 chriseppstein

@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).

xzyfer avatar Jan 16 '15 10:01 xzyfer

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

IbnSaeed avatar Feb 24 '15 07:02 IbnSaeed

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.

xzyfer avatar Feb 24 '15 12:02 xzyfer

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

Hope that helps :smile:

ysimonson avatar Apr 21 '15 18:04 ysimonson

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

xzyfer avatar Jun 11 '15 03:06 xzyfer

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

TheJaredWilcurt avatar Nov 17 '15 19:11 TheJaredWilcurt

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.

saper avatar Nov 17 '15 22:11 saper

+1 for me too :smile:

fgimian avatar Apr 02 '16 15:04 fgimian

+1

fabio-coolshop avatar May 06 '16 14:05 fabio-coolshop

+1

ziodave avatar Sep 07 '16 06:09 ziodave

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

fgimian avatar Sep 07 '16 07:09 fgimian

Thanks @fgimian that's neat.

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

ziodave avatar Sep 07 '16 11:09 ziodave

Ah nice @ziodave, glad you found it handy 😄

fgimian avatar Sep 10 '16 01:09 fgimian

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

staghouse avatar Jan 31 '19 20:01 staghouse

Why not just using entr to watch and reload?

WnP avatar Feb 28 '19 16:02 WnP

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.

olaf-w avatar Jun 21 '19 02:06 olaf-w

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).

GitarMan avatar Jul 26 '19 22:07 GitarMan