I am working on grunt for making building tool, till now I was putting src and dest addresses directly in my grunt.js file but in this case if I want to change my dest I have to change in every task of file which is not a good practice.for example if my grunt.js file have following task:
concat: {
js: {
src: 'src/js/*.js',
dest: 'dest/js/concat.js'
},
css: {
src: 'src/css/*.css',
dest: 'dest/css/concat.css'
}
},
min: {
js: {
src: 'dest/js/concat.js',
dest: 'dest/js/concat.min.js'
}
},
here if I change my address than i have to change in every place!!!
I want a JSON file in which I can declare src and dest and call in my grunt.js file. How can we do that???
You could add a property to
package.jsonto declare metadata, for exampleThen in your
Gruntfile.js, you could read those properties like thisThe important bits are
pkg:<json:package.json>which loads the json file into memory and the underscore template interpolations<%= pkg.meta.src %>which evaluate to the contents of themetaproperty added to the json file.Keep in mind that the Gruntfile is just a JavaScript file so you could also have an object with references to paths and then interpolate them into your tasks.