Open ciro207 opened 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.
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!
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.)
So, this exists: https://code.google.com/p/simplefilewatcher/
@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).
Whats the status of this issue ? Will it be implemented or should this be closed ?
We made something that builds on sassc to provide directory compilation and watching: http://github.com/dailymuse/gosass
Hope that helps :smile:
There no plans to implement this in the near future. Pull requests are welcome.
+1 Using Node-Sass + Chokidar for now, but would prefer --watch
in SassC.
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.
+1 for me too :smile:
+1
+1
Here's another way I documented that you can use using fswatch 😄
Thanks @fgimian that's neat.
I just added -i ".*\.scss$" -e ".*"
to the fswatch
options to only watch for scss file changes.
Ah nice @ziodave, glad you found it handy 😄
Would love to have this now that sass-ruby is nearing end of life.
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.
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).
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!!!