7

我是新手,正在学习如何配置coffee、jade和sass编译任务。我可以成功地为咖啡和玉目录配置编译任务,但我不能为 sass。我的项目结构如下

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

我的 package.json 是

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

当 Gruntfile.coffee 如下时,$ grunt sass编译 index.css 成功:

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

但是当如下所示时,>>找不到源文件“index.sass”。显示错误

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

如何配置递归 sass 编译任务?

4

1 回答 1

24

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.

于 2013-11-07T00:27:22.183 回答