Skip to content

Instantly share code, notes, and snippets.

@syul
Last active August 29, 2015 14:04
Show Gist options
  • Save syul/2dec564929d91b63d1f4 to your computer and use it in GitHub Desktop.
Save syul/2dec564929d91b63d1f4 to your computer and use it in GitHub Desktop.
Dynamicly loading included modules
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt, {pattern: 'grunt-contrib-*'});
var options = {
config : {
src: 'grunt/*.json'
}
};
// loading all config of my tasks from specified folder
var configs = require('load-grunt-configs')(grunt, options);
// Here some magic. If in configs exists grunt-contrib-requirejs task config
// getting all files from specified folder and pushing they into include array
if (configs.requirejs) {
var fs = require('fs'),
files = fs.readdirSync('application/views/alg'),
fileArrayLength = files.length;
grunt.log.writeln('There are %d modules will be added to require js config.', fileArrayLength);
if (configs.requirejs.options && configs.requirejs.options.include) {
for (var i = 0; i < fileArrayLength; i ++) {
configs.requirejs.options.include.push('application/views/alg/' + files[i]);
grunt.log.ok('Module application/views/alg/%s was added to require js config', files[i]);
}
}
}
//Grunt config initialization
grunt.initConfig(configs);
//Registering my tasks
grunt.registerTask('default', ['clean', 'copy', 'requirejs', 'uglify', 'less', 'connect']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment