Mekajiki
Mekajiki

Reputation: 941

How to configure directory-recursive Sass compilation task by Grunt

I'm a newbie and learning how to configure coffee, jade, and sass compilation tasks. I could successfully configure compilation tasks for coffee and jade directory but I couldn't for sass. The structure of my project is bellow

.                                                                                                   
├── Gruntfile.coffee                                                                                
├── node_modules                                                                                    
├── package.json                                                                                    
├── sass                                                                                            
│   └── index.sass                                                                                  
└── www

and my package.json is

{
  "name": "grunt-sass-test",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-sass": "~0.5.0"
  }
}

when Gruntfile.coffee is bellow, $ grunt sass compile index.css successfully:

module.exports = (grunt) ->
  grunt.initConfig
    pkg: grunt.file.readJSON('package.json')
    sass:
      compile:
        files:[
          "www/index.css": "sass/index.sass"
        ]

but when as bellow, >> Source file "index.sass" not found. error is shown

    sass:
      compile:
        cwd: 'sass'
        src: ['**/*.sass']
        dest: 'www/'
        ext: '.css'

How can I configure recursive sass compilation task?

Upvotes: 7

Views: 9952

Answers (1)

Jesús Quintana
Jesús Quintana

Reputation: 1813

In grunt all recursive files work the same way:

files: [{
  expand: true,
  cwd: "sass/folder",
  src: ["**/*.sass"],
  dest: "dest/folder",
  ext: ".css"
}]

expand is for doing recursive, cwd is startup directory, src is regex to match ** (in folder), dest is the folder where it saves after being compiled, and finally ext is the extension added

This should work for all tasks which use files, in grunt.

Upvotes: 24

Related Questions