Skip to content

Instantly share code, notes, and snippets.

@sheedy
Created December 30, 2013 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sheedy/8184942 to your computer and use it in GitHub Desktop.
Save sheedy/8184942 to your computer and use it in GitHub Desktop.
Loading tasks and task options from individual files (http://www.thomasboyt.com/2013/09/01/maintainable-grunt.html) and loading modules as needed
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
var path = require('path');
// Display task times
require('time-grunt')(grunt);
// Load tasks as needed for performance
require('jit-grunt')(grunt);
/*========================================
= Config variables =
========================================*/
var config = {
pkg: grunt.file.readJSON('package.json'),
src: 'src',
build: 'build',
temp: '.tmp',
port: 9001,
hostname: '0.0.0.0' // enter host ip address + :port into browser address bar for remote livereload
};
// Split grunt file into 'tasks' and 'task options' for easier maintenance
// Source: http://www.thomasboyt.com/2013/09/01/maintainable-grunt.html
function loadConfig(path) {
var glob = require('glob'), object = {}, key;
glob.sync('*', {cwd: path}).forEach(function(option) {
key = option.replace(/\.js$/,'');
object[key] = require(path + option);
});
return object;
}
grunt.util._.extend(config, loadConfig('./tasks/options/'));
grunt.initConfig(config);
/*====================================
= Task loading =
====================================*/
// Use matchdep to load tasks
// require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// Load all grunt-* tasks
// Load all tasks with "pattern: '*'" is producing load module errors
// require('load-grunt-tasks')(grunt);
// Manually load tasks that don't conform to the grunt-* pattern in 'load-grunt-tasks'
// grunt.loadNpmTasks('assemble');
/*=============================
= Tasks =
=============================*/
// Auto-load all tasks from files in /tasks directory
grunt.loadTasks('tasks');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment