I'm having trouble understanding nesting that sometimes shows up in grunt.js
files. In the following example, what do nested objects like concat.dist
and min.dist
mean? Is the dist
key referencing another named task or is it simply a configuration object? What exactly gets called when executing the concat
and min
tasks?
module.exports = function (grunt) {
grunt.initConfig({
// …
concat: {
dist: {
src: ["<banner:meta.banner>", "<file_strip_banner:lib/main.js>"],
dest: "dist/main.js",
}
},
min: {
dist: {
src: ["<banner:meta.banner>", "<config:concat.dist.dest>"],
dest: "dist/main.min.js",
}
},
// …
});
// …
grunt.registerTask("default", "lint qunit concat min");
};
In grunt, tasks that support this kind of nesting are called multi tasks, and the nested objects are called targets. Suppose you have the following multi-task:
concat: {
dist: {
src: ["<banner:meta.banner>", "<file_strip_banner:lib/main.js>"],
dest: "dist/main.js",
},
dev: {
(...)
}
}
This means you have the multi task concat with the targets dist and dev inside it. You can run all targets of any multi task by typing the name of the task on console. For example:
grunt concat
will run both concat and dev. On the other hand, you can also specify which target to run explicitly:
grunt concat:dist
will only execute the dist target.
As far as I know, if you have two multitasks with targets of the same name (like your example min.dist and concat.dist), this doesn't mean that both dist are somehow referencing the same thing, they just happen to share the same name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With