Grunt import external data

Grunt has two methods for importing external data:

  • grunt.file.readJSON
  • grunt.file.readYAML

For example, you can load data from a file into configuration of GruntFile:

1
2
3
4
5
6
7
8
9
10
11
12
module.exports = function (grunt) {
grunt.config.init({
colors: grunt.file.readJSON('colors.json'),
white: '<%= colors.white %>',
green; '<%= colors.green %>'
});
grunt.registerTask('default', function () {
grunt.log.writeln(grunt.config.get('green'));
});
});

Using Tempalte to store external data into specific config properties, such as white and green in the above example. Then, you can get the data by method grunt.config.get().

0%