Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sass filewatcher for webstorm

I am trying to use sass in a NodeJS project and this is the library I installed with nodejs

https://www.npmjs.org/package/node-sass

I am using webstorm for this project and I can't get the Sass file watcher to work.

enter image description here

Even after I save the filewatcher and click "Ok", the filewatcher does not work. When I open the settings to check what's wrong the filewatcher has been unchecked. Here are the filewatcher settings:

enter image description here

The node-sass module is installed as a global module so the node-sass command works.

like image 269
EternallyCurious Avatar asked May 19 '14 07:05

EternallyCurious


People also ask

How do I use file watchers in WebStorm?

A configured File Watcher can be saved in your project settings or in the IDE settings and used in different projects. When you open a file where a predefined File Watcher is applicable, WebStorm displays a pane where suggests activating it.

How does WebStorm watch for changes to my typescript files?

When WebStorm detects that you’re using a type of File which it can “watch” for you, it will prompt you to set up a File Watcher (or you can customize your own). From this panel, you can see this File Watcher will do the following: Watch for changes on all TypeScript files (within the defined scope)

Does PhpStorm file Watcher work with node-Sass?

Phpstorm file watcher does not work very well with node-sass (tested in Phpstorm 8.0.1 windows) Show activity on this post. Phpstorm 8.0.3 Windows 7 (x64) node-sass installed globally working example

What is the source file name of the sass or less file?

The file has the name of the source Sass, Less, or SCSS file and the extension .css. The location of the generated files is defined in the Output paths to refresh field of the New Watcher dialog. However, in the Project Tree, they are shown under the source file which is now displayed as a node.


2 Answers

  1. You need to specify a full path to node-sass.cmd in a Program field (as @LazyOne mentioned)
  2. Specified arguments won't work with node-sass - they are only suitable for standard SASS compiler. Here is a list of node-sass options:
Usage: node C:\Users\USER\AppData\Roaming\npm\node_modules\node-sass\bin\node-sass

[options] <input.scss> [<output.css>]

Options:
  --output-style     CSS output style (nested|expanded|compact|compressed)  [default: "nested"]
  --source-comments  Include debug info in output (none|normal|map)         [default: "none"]
  --include-path     Path to look for @import-ed files                      [default: "C:\\Users\\USER\\AppData\\Roaming\\npm"]
  --watch, -w        Watch a directory or file
  --output, -o       Output css file
  --stdout           Print the resulting CSS to stdout
  --help, --help     Print usage info

the simplest setup looks as follows:

Program: C:\Users\USER\AppData\Roaming\npm\node-sass.cmd
Arguments: $FileName$ $FileNameWithoutExtension$.css
Working directory: $FileDir$
Output paths to refresh: $FileNameWithoutExtension$.css

'Create output from stdout' should be off

With such settings the generated .css file will be placed near the original .scss. If you like to put resultant files into a different folder, try playing with -o option. Like:

Arguments: $FileName$ -o $ProjectFileDir$/css/$FileNameWithoutExtension$.css
Output paths to refresh: $ProjectFileDir$/css/$FileNameWithoutExtension$.css
like image 151
lena Avatar answered Sep 28 '22 00:09

lena


Most definitely path to .cmd is wrong as lena and lazy one suggested. Whenever watcher unchecks in Web/Phpstorm its probably because of invalid path. If you still have trouble with node-sass you could always go Ruby way.

  1. Download and install Ruby for Win,
  2. Install Sass via command prompt with gem install sass,
  3. In Web/Phpstorm put "Program" path to sass.bat (remember node-sass.cmd?), e.g. C:\Ruby200\bin\sass.bat
like image 28
Drops Avatar answered Sep 28 '22 00:09

Drops