user1937021
user1937021

Reputation: 10791

splitting up a gruntfile

I have this task in my 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"
        } ]
    }
}

However when I add this snippet to a js file jade.js like so:

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"
    } ]
}

}

I get the error ReferenceError: grunt is not defined

although I have the following setup:

aliases.yaml

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

FOLDER STRUCTURE

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

Gruntfile.js

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

I have load-grunt-config and load-grunt-tasks both installed.

Upvotes: 0

Views: 153

Answers (1)

Xavier Priour
Xavier Priour

Reputation: 2121

If you want to use grunt in your config, you have to use the function form for the jade.js file:

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"
      } ]
    }
  }
}

Upvotes: 1

Related Questions