how to watch changes in whole directory/folder containing many sass files
Asked Answered
P

9

91

How could I trace changes in whole directory containing many sass files ? I'm using the following command to watch changes in sass

file:

sass --watch style.scss:style.css

But how to watch changes in whole directory/folder containing many sass files.

Pasteurism answered 25/8, 2013 at 10:3 Comment(1)
Did any of the answers here help you?Crupper
E
114

Simply use the command sass --watch <input folder>:<output folder>, like this:

$ ls -l
css/ sass/
$ sass --watch sass:css

Where <input folder> contains the Sass files and <output folder> that hosts the generated CSS files.

Escaut answered 26/8, 2013 at 12:25 Comment(3)
If I have a sass folder with 20 sub-directories and with a total of 200 scss files inside them, what impact would sass --watch have in this case on CPU/Memory resources?Uptake
@piouPioum, I have tried the command you have mentioned it detects the change but doesn't write.Freefloating
It says Could not find an option named "watch".. I don't know what to do, I can't believe I can't run a watcher without install external programs or use a task runnerDecency
M
30

Expanding the answer by piouPiouM a little:

  • Output files will be created with the same names as input files except ending with .css.
  • <input folder> and <output folder> can be the same.
  • Both folders can be the present working directory, so the following is valid:

    $ sass --watch .:.

Mcmullan answered 16/4, 2014 at 16:1 Comment(0)
W
16

Go to you terminal and get to you folder then wrote:

 sass --watch .

this will watch all sass files and convert to css files with the same name. also you can do it in this way:

sass --watch ~/user/youUser/workspace/project/styles/

I hope this can help you.

Wilburn answered 18/12, 2015 at 11:16 Comment(0)
C
9

I ended up doing this without using Grunt or Sass-watch:

npm install -g watch
watch "sass assets/app.scss assets/dist/app.css" assets/css
Crossways answered 31/10, 2014 at 13:35 Comment(2)
Do you install sass in your working web directory? If its installed at the system level do I have to type the whole path? So... sass --watch /Users/estout/Documents/GIT/project/:/Users/estout/Documents/GIT/project/Colner
@buschschwick: Yes, you install it at system level. You either type the full address each time, like you have, or a little easier would be to change directory cd /Users/estout/Documents/GIT/project/ and then write $ sass --watch .:.Crupper
L
6

if you are in your current folder then do the following to watch it.

F:\sass tutorial>sass --watch ./:./
Laroche answered 20/5, 2018 at 7:47 Comment(0)
D
4

Just in case someone faces with this issue in 2018:
sass Website refers to Ruby Sass that is been deprecated. and as now (May 2018) if you install dart sass via npm , it does not support --watch command

What to do:
you need to install node-sass globaly , like:

npm install node-sass -g

and then restart the command line , then use this code:

node-sass --watch scss/styles.scss css/styles.css

to compile your scass files to css.
basically node-sass supports --watch command and we use that to compile our scss codes to regular css files.

and just in case you get an error like this at the first time that you save your .scss file:

{
  "status": 3,
  "message": "File to read not found or unreadable: yourdirectory/scss/styles.scss",
  "formatted": "Internal Error: File to read not found or unreadable: yourdirectory/scss/styles.scss\n"
}

what you need to do is save it again, it will work correctly!

Dizen answered 17/5, 2018 at 10:53 Comment(1)
Though of course now node sass is deprecated. I don't see anything equivalent to watch on the npm page. It is on the stand-alone version, but not 100% sure how to use in node code yet, as, eg, there's no watch on its DefinitelyTyped definition.Hunchbacked
A
3

According to the information, you can use the next command line:

sass --watch .

Source: http://sassbreak.com/watch-your-sass/#what-does---watch-do

Atoll answered 9/11, 2016 at 18:8 Comment(1)
they work for me, thxPatty
E
3

You can set sass to watch all the .scss files(for my case i got several .scss files in src/static folder) to compile, but before install it globally:

npm i -g sass

then go to the project folder and type command below:

sass --watch $(pwd)/src/static 

also you can wrap it in npm script in package.json, like

 "scripts": {
    "sass:watch": "sass --watch $(pwd)/src/static"
    }
    

and run it by this command:

npm run sass:watch
Economically answered 8/10, 2020 at 11:31 Comment(0)
A
2

You can create one sass file which includes the rest of the files, and then just watch this file.

Alternately, look into Grunt and the very good grunt-contrib-compass plugin

Anselma answered 25/8, 2013 at 10:17 Comment(4)
@Crossways yes, that is indeed what the grunt watch doesAnselma
I ended up doing this: #18428349Crossways
You would not want one SASS file for my current project. This is a poor suggestion/answer. Much simpler is to ask SASS to watch a directory, which others have stated in their answers.Crupper
You may want one master SASS file for the project, which includes all the child component SASS files (look at how bootstrap does it). There is also a major pitfall with the current accepted answer that it compiles all sass files and outputs one css file for each sass file (partials excluded). That may not be what you want.Anselma

© 2022 - 2024 — McMap. All rights reserved.