1

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?

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.