0

I have lots of projects that use grunt-sass, which depends on node-sass, which depends on libsass. Everytime I checkout one of those projects from the their git repository and npm install them, libsass is compiled again and in my computer, this process takes a lot of time.

node-sass has ways of providing an existing libsass binary, so I don't have to go through the process of compiling it everytime. (https://github.com/sass/node-sass#binary-configuration-parameters)

I tried then installing globally a node-sass npm package. It compiles libsass and install it in my /usr/local/lib/node_modules/node-sass folder:

npm install -g node-sass

after I set a sass_binary_path parameter in my ~/.npmrc file:

sass_binary_path=/usr/local/lib/node_modules/node-sass/vendor/darwin-x64-47/binding.node

When I npm install my projects after checkout them, libsass isn't compiled anymore and the installation is successful. But when I execute a grunt task which uses grunt-sass, here's what I get:

Loading "sass.js" tasks...ERROR
>> Error: ENOENT: no such file or directory, scandir '~/dev/my-project/node_modules/node-sass/vendor'
Warning: Task "sass:dist" not found. Use --force to continue.

Aborted due to warnings.

What am I doing wrong in this process of caching libsass?

--

EDIT:

When I install npm install using the normal process, node_modules/node-sass/vendor/darwin-x64-47/binding.node is created. When I try to use the node-sass cache flags, it doesn't even create the node_modules/node-sass/vendor folder.

armoucar
  • 408
  • 1
  • 4
  • 15
  • I'm not sure libsass is your issue. What does your .scss file look like ? Any references to vendor ? – Nix Sep 14 '16 at 14:29
  • No, there is no reference to this vendor directory inside `node_modules/node-sass`. When I install using the normal process, `node_modules/node-sass/vendor/darwin-x64-47/binding.node` is created. When I try to use the node-sass cache flags, it isn't. – armoucar Sep 14 '16 at 14:34

2 Answers2

1

I was able to use a cached node-sass library finally.

First a binary package should be downloaded from: https://github.com/sass/node-sass/releases

Then I used a environment variable to point to this binary.

export SASS_BINARY_PATH="$HOME/dev/bin/darwin-x64-47_binding.node"

When installing node-sass with npm, it uses the provided binary.

armoucar
  • 408
  • 1
  • 4
  • 15
1

Transparent caching is coming in https://github.com/sass/node-sass/pull/1714 (probably version 3.11), I just need to fix up the PR.

nschonni
  • 4,069
  • 1
  • 28
  • 37