grunt-sass and custom functions

421 views Asked by At

I would like to create custom functions inside my grunt file (or everywhere) to use with grunt-sass.

I tried with this:

options: {
    functions: {
        'fakeList()': function() { 
            var list = new require('node-sass').types.List(3);
            list.setValue(0, 'a');
            list.setValue(1, 'b');
            list.setValue(2, 'c');
            return list;
        }
    }
},  

But i correcty get error in C function readFolder: Cannot find module 'node-sass' (because node-sass in a nested dependency, not a direct).

So I tried forcing with a npm install node-sass. But then I get this error in C function readFolder: A SassValue object was expected.

Did someone had the same problem?

1

There are 1 answers

0
alberto-bottarini On

The problem is the value of the setValue method that must be a SassValue object!

I changed in this way and now it works:

options: {
    functions: {
        'fakeList()': function() { 
            var sass = require('node-sass');
            var list = new sass.types.List(3);
            list.setValue(0, sass.types.String('a'));
            list.setValue(1, sass.types.String('b'));
            list.setValue(2, sass.types.String('c'));
            return list;
        }
    }
},