Search code examples
npmsassnode-sass

How to avoid subdirectory output in node-sass?


I have following setup under my project:

  • /assets/scss has many SCSS files organized under different subdirectories; including a root global.scss file. As you can imagine, global.scss will only have @imports.
  • /assets/css is set as output directory. I am trying to output only one file under this folder - global.css.

package.json has this command

"scripts": {
    "scss": "node-sass --watch assets/scss/styleguide.scss -o assets/css --recursive"
  }

When I run npm run scss it outputs subdirectory CSS files as well. Does anyone know how to avoid output of subdirectory sass files?

Thanks in advance!


Solution

  • You are passing the --recursive argument to node-sass. That will mean that node-sass will search recursively on every directory under assets/scss and will compile all the scss files found. To avoid that behavior just remove the --recursive option:

    "scripts": {
        "scss": "node-sass --watch assets/scss/styleguide.scss -o assets/css"
    }
    

    More about node-sass usages and options can be found here.