-
-
Save syul/2dec564929d91b63d1f4 to your computer and use it in GitHub Desktop.
Dynamicly loading included modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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