0

I'm trying to create a very simple build system with Grunt in windows using Cygwin to handle compiling,concatenation and minification of my scss/css and coffee/js files.

I'm having problem with Grunt not recognizing Sass as a command.

I should note that the same Gruntfile, same tasks, same packages is working perfectly on linux (why of course!) and this problem is solely related to implementing the same system on Windows.

I have correctly installed Ruby and Sass (both "ruby -v" and "sass -v" work as expected) and i have no problem compiling scss into css from command line

$ sass --update sass:css

and it effectively converts all the .scss files into .css

Grunt itself works without problems, compiling coffee into js, concatenating js or css files, minifying them and watching for changes.

here is the complete Gruntfile.js, for reference

module.exports = function(grunt) {

    grunt.initConfig({
            concat: {
                    js: {
                            src: 'js/*.js',
                            dest: 'build/js/scripts.js',
                    },
                    css: {
                            src: 'css/*.css',
                            dest: 'build/css/theme.css',
                    },
            },
            uglify: {
                    jsMin : {
                            files: {
                                    'build/js/scripts.min.js' : ['build/js/scripts.js']
                            },
                    },
            },
            cssmin: {
                    styleMin : {
                            files : {
                                    'build/css/theme.min.css' : ['build/css/theme.css']
                            },
                    },
            },
            watch: {
                    jsW: {
                            files: ['js/**/*.js'],
                            tasks: ['concat:js','uglify:jsMin'],
                    },
                    cssW: {
                            files: ['css/**/*.css'],
                            tasks: ['concat:css','cssmin'],
                    },
                    sassW: {
                            files: ['sass/**/*.scss'],
                            tasks: ['exec']
                    }
            },
            exec: {
                    Sass    : 'sass --update sass:css',
                    Coffee  : 'coffee -o js/ -c coffee/'
            }
    });



    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-exec');

    grunt.registerTask('default',['exec','concat','uglify','cssmin','watch']);

};

if then I start grunt it displays the following alert

Running "exec:Sass" (exec) task

'sass' is not recognized as an internal or external command, operable program or batch file.

Exited with code: 1.

Warning: Task "exec:Sass" failed. Use --force to continue.

Aborted due to warnings.

as I stated before the system works perfectly on linux, so I would guess there is something wrong with my Paths, but why then would sass work fine from command line and not being recognized through grunt?


last thing I would like to point out is that, during some digging and testing to try and guess what the problem was before posting here on SO, I found out that calling out any bash function that has not an .exe file in cygwin/bin shows the same error

https://i.stack.imgur.com/DGLe5.png (testing on files 'sass' 'sdoc' and 'ruby.exe')

modified grunt-exec for testing:

exec: {
                    Sass    : 'sass -v',
                    Ruby    : 'ruby -v',
                    Sdoc    : 'sdoc -v',

}

and they showed the following after grunt --force https://i.stack.imgur.com/3boy7.png

while from normal command-line

$ sass -v && ruby -v && sdoc -v
Sass 3.4.16 (Selective Steve)
ruby 2.0.0p598 (2014-11-13) [x86_64-cygwin]
4.2.0

I seriously have no idea where to go from here, any help would be appreciated.

Luken00
  • 21
  • 5
  • You should check out an npm package called `grunt-contrib-sass` it compiles your sass to css. Taking that route might prevent the issue your having now. – Josh Aug 13 '15 at 18:34
  • using `grunt-contrib-sass` fires the following error : _Warning: You need to have Ruby and Sass installed and in your PATH for this task to work. More info: https://github.com/gruntjs/grunt-contrib-sass Use --force to continue._ which is still more weird since both are installed and in my PATH. I will add a workaround I have found as an answer – Luken00 Aug 20 '15 at 09:57
  • Install sass and ruby GLOBALLY on your machine. – Josh Aug 24 '15 at 00:09

1 Answers1

1

I still haven't found a solution to my problem. However I did find a workaround that works just fine, just in case someone is interested or is having the same issue I had.

the solution involves running sass directly through Ruby (which my grunt-exec task recognize), so I edited my Gruntfile.js as follows :

exec: {
                Sass    : 'ruby sass.rb'
        }

which calls a sass.rb file in the main directory, which is a ruby script file.

require "sass"
options = {
    :syntax => :scss,
    :style => :compressed,
    :load_paths => ['./src/sass/']
    # load_paths is required in case your 'master.scss' files use @import to attach other scss files 
}

render = Sass::Engine.new(File.read("src/sass/master.scss"), options).render
File.write("src/css/master.css", render)

You can find further options in the SASS documentation


I know this is not an actual answer to my question, but this is the only thing the worked right away without any problem. I'll still try to figure out why the more common solutions (grunt-contrib-sass and grunt-exec) won't work, but with this workaround I have my build system up and running.

Luken00
  • 21
  • 5