zcesl53
zcesl53

Reputation: 53

Using grunt to compile jade templates to javascript functions in sails.js

I am building an application in Sails.js and i want to compile some jade templates to javascript functions for use from the client. I have found a few articles explaining how to do this, but when i try to implement their steps they don't seem to work for me

I am trying to compile files located in App/Views/Client and put the compiled javascript files into App/.tmp/public/templates

My grunt task is in App/tasks/config and is based on the coffeescript grunt task that comes with sails.js. My grunt task looks like this

module.exports = function(grunt) {
    grunt.config.set('jade', {
        dev: {
            templates:{
                options: {
                    pretty: true,
                    client: true,
                    namespace: 'Templates'  
                },
                files: [{
                    expand: true,
                    cwd: 'views/client/',
                    src: ['**/*.jade'],
                    dest: '.tmp/public/templates/',
                    ext: '.js'
                }]
            }
        }
    });
    grunt.loadNpmTasks('grunt-contrib-jade');
};

I have added it to the compileAssets.js grunt task that comes with sails.js, and i can see it being run when i run the sails lift command.

When it runs it reports 0 files created, which suggests to me that there is a problem with my paths. However i have defined them based on the same working folder as the other grunt tasks in sails.js. I have tried a number of variations on the paths, including putting ./ at the start of them, but none seem to work.

Can anyone help explain what is wrong with my grunt file? Or how to make it output the folder it is looking at to the console so i can figure out whether my path is correct or not?

Upvotes: 1

Views: 202

Answers (1)

Lucas S.
Lucas S.

Reputation: 2401

Your configuration object is one level too deep. dev is already the task's target and Grunt will start looking for the files property in there. templates is quietly ignored.

So the configuration object should look like this:

dev: {
  options: {
      pretty: true,
      client: true,
      namespace: 'Templates'  
  },
  files: [{
      expand: true,
      cwd: 'views/client/',
      src: ['**/*.jade'],
      dest: '.tmp/public/templates/',
      ext: '.js'
  }]
}

Upvotes: 1

Related Questions