2016-01-22 50 views
0

我有我的gruntfile这个任务:分裂了gruntfile

jade: { 
    compile: { 
     options: { 
      client: false, 
      pretty: true, 
      data: { 
        section: grunt.file.readJSON('json/section.json') 
      } 
     }, 
     files: [ { 
      cwd: "app/views", 
      src: "**/*.jade", 
      dest: "build/templates", 
      expand: true, 
      ext: ".html" 
     } ] 
    } 
} 

然而,当我这个片段添加到一个js文件jade.js像这样:

module.exports = {

compile: { 
    options: { 
     client: false, 
     pretty: true, 
     data: { 
       section: grunt.file.readJSON('json/section.json') 
     } 
    }, 
    files: [ { 
     cwd: "app/views", 
     src: "**/*.jade", 
     dest: "build/templates", 
     expand: true, 
     ext: ".html" 
    } ] 
} 

}

我得到的错误的ReferenceError:咕噜没有定义

虽然我具有以下设置:

aliases.yaml

default: 
     - 'jade' 
     - 'sass' 
     - 'watch 

文件夹结构

/grunt 
    aliases.yaml 
    jade.js 
    sass.js 
    watch.js 

Gruntfile.js

module.exports = function(grunt) { 
    // load grunt config 
    require('load-grunt-config')(grunt); 
}; 

我已经安装了load-grunt-config和load-grunt-tasks。

回答

1

如果你想在你的配置使用grunt,你必须使用的函数形式为jade.js文件:

module.exports = function (grunt, options) { 
    return { 
    compile: { 
     options: { 
     client: false, 
     pretty: true, 
     data: { 
       section: grunt.file.readJSON('json/section.json') 
     } 
     }, 
     files: [ { 
     cwd: "app/views", 
     src: "**/*.jade", 
     dest: "build/templates", 
     expand: true, 
     ext: ".html" 
     } ] 
    } 
    } 
} 
+0

你的先生是一个真正的英雄!我向你们致敬。 – user1937021