Node-sass: No way to output to a single file when watching

Created on 9 Jan 2017  路  9Comments  路  Source: sass/node-sass

After my experiments (#1852) I found that node-sass -w input.scss > output.css is a wrong way to go (due to POSIX file descriptors redirection logic).

So currently there is no way to output changes into a single file when using --watch option.

Environment

  • NPM version (npm -v): 3.10.3
  • Node version (node -v): v6.3.0
  • Node Process (node -p process.versions):
{ http_parser: '2.7.0',
  node: '6.3.0',
  v8: '5.0.71.52',
  uv: '1.9.1',
  zlib: '1.2.8',
  ares: '1.10.1-DEV',
  icu: '57.1',
  modules: '48',
  openssl: '1.0.2h' }
  • Node Platform (node -p process.platform): darwin
  • Node architecture (node -p process.arch): x64
  • node-sass version (node -p "require('node-sass').info"):
node-sass   4.1.1   (Wrapper)   [JavaScript]
libsass     3.4.0   (Sass Compiler) [C/C++]
Module - Watcher

Most helpful comment

Note: you can get around this somewhat by prefixing all imported sass files with a _ which lets sass know it is a partial and should not be generated into a css file.

All 9 comments

What are you suggesting?

Maybe to allow -o file.css? (or some new argument for that).

I see. We do have an -o flag but I believe it only works when watching a directory. It makes sense that it should work individual files as well

I came across this today. Even when pointing the input to one file, it watches the whole directory (seemed to be recursive even though I didn't have the -r flag) and creates a .css file in my output directory FOR EACH FILE.

So node-sass --watch sass/styles.scss --output css didn't just create css/styles.css it created a css file for everything in sass/.

Even without the option for -o filename.css why would it create an output file for anything but my entry? Everything is imported in that one styles.scss, so now I have a ton of extra files dirtying the project. The other option being to not use watch.

Note: you can get around this somewhat by prefixing all imported sass files with a _ which lets sass know it is a partial and should not be generated into a css file.

Even when using folder watch, node-sass don't create the output file until I make a change:

node-sass --watch template/ --output template/style.css

I only have style.scss in template/ folder, and the css file is never created, until I make a change on my scss file. Using node-sass --watch template/ --output template/ don't work either.

(osx platform, latest node-sass version)

What about this:

 node-sass -w in/main.scss out/main.css

This works for me as of 4.12. There are some issues like https://github.com/sass/node-sass/issues/2491 or https://github.com/sass/node-sass/issues/2560 but in the most general case it works.

The problem was that I had multiple files to watch for changes but only one file to recompile.

So this is the same as this https://github.com/sass/node-sass/pull/2492#issuecomment-543409242 I think

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pulkitnandan picture pulkitnandan  路  4Comments

harukaeru picture harukaeru  路  3Comments

mkbctrl picture mkbctrl  路  4Comments

liuyuqiang picture liuyuqiang  路  3Comments

samayo picture samayo  路  3Comments