title: Registering Grunt tasks whose code is located in external JavaScript files
body: <p>I've written a function which I'd like to use as a Grunt task. I can do this by adding this to the Gruntfile:</p>
  
  <pre><code>grunt.registerTask('foo', function () {
      // code here
  });
  </code></pre>
  
  <p>However, it makes more sense to keep the function code in a separate file. I plan to define a bunch of these custom tasks and I don't want to bloat the Gruntfile.</p>
  
  <p>I'm not sure what the preferred way of registering such tasks is. I have found this to work:</p>
  
  <pre><code>grunt.registerTask('foo', function () {
      require('./path/to/foo.js')(grunt);
  });
  </code></pre>
  
  <p>So, I'm having the inline function like in the fist example, but this time, I'm loading an external file and invoking it immediately. In that external file, I of course have to write:</p>
  
  <pre><code>module.exports = function (grunt) {
      // code here
  }
  </code></pre>
  
  <p>This works, but it feels hackish. Is there a more proper way of doing this?</p>