Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created June 25, 2012 17:46
Show Gist options
  • Save cowboy/2990126 to your computer and use it in GitHub Desktop.
Save cowboy/2990126 to your computer and use it in GitHub Desktop.
grunt: an example of building task targets dynamically
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
min: {
ariaAccessibility: {
src: ['src/javascripts/jquery.selectBoxIt.ariaAccessibility.js'],
dest: 'src/javascripts/jquery.selectBoxIt.ariaAccessibility.min.js'
},
disable: {
src: ['src/javascripts/jquery.selectBoxIt.disable.js'],
dest: 'src/javascripts/jquery.selectBoxIt.disable.min.js'
},
enable: {
src: ['src/javascripts/jquery.selectBoxIt.enable.js'],
dest: 'src/javascripts/jquery.selectBoxIt.enable.min.js'
},
destroy: {
src: ['src/javascripts/jquery.selectBoxIt.destroy.js'],
dest: 'src/javascripts/jquery.selectBoxIt.destroy.min.js'
},
setOption: {
src: ['src/javascripts/jquery.selectBoxIt.setOption.js'],
dest: 'src/javascripts/jquery.selectBoxIt.setOption.min.js'
},
setOptions: {
src: ['src/javascripts/jquery.selectBoxIt.setOptions.js'],
dest: 'src/javascripts/jquery.selectBoxIt.setOptions.min.js'
},
wait: {
src: ['src/javascripts/jquery.selectBoxIt.wait.js'],
dest: 'src/javascripts/jquery.selectBoxIt.wait.min.js'
}
}
});
// etc.
};
/*global module:false*/
module.exports = function(grunt) {
var min = {};
[
'ariaAccessibility',
'disable',
'enable',
'destroy',
'setOption',
'setOptions',
'wait'
].forEach(function(name) {
min[name] = {
src: 'src/javascripts/jquery.selectBoxIt.' + name + '.js',
dest: 'src/javascripts/jquery.selectBoxIt.' + name + '.min.js'
};
});
// Project configuration.
grunt.initConfig({
min: min
});
// etc.
};
@vasu512
Copy link

vasu512 commented May 6, 2019

very useful for my case. What if there is another min configuration and I want to run this specific configuration. My case is, I have created a dynamic compress task from your example and when I run 'grunt compress' all the compress tasks are being executed but I just want the compress configuration generated by the above example. For example...
//created grunt compress task
var compress = {};
references.forEach(function(name)
{
compress[name] = {
options: {
archive: '<%= pkg.distOutputDir %>/uploads/'+ name + '.zip'
},
files: [
{
expand: true,
cwd: './js/temp/files/'+name+'/',
src: ['']
}
]
};
});
grunt.initConfig({
compress:compress, //dynamically geneerated statements from above
compress: { //manual configuration
temp: {
options: {
archive: ./uploads/xyz.zip
},
files: [
{expand: true,
cwd: <%= pkg.distOutputDir %>/xyz/,
src: [
]
}
]
}
}
});

when I do a 'grunt compress' all compress tasks are run including temp also. I do not want compress: temp to run. Any help on this is appreciable. Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment