Here is an example of what I'm looking for:
module.exports = function(grunt) { grunt.initConfig({ config: grunt.file.readYAML('_config.yml'), // example variable: <%= config.scripts %> copy: { scripts: (function() { if (config.scripts === true) { // I want to target <%= config.scripts %> return { expand: true, cwd: '<%= input %>/_assets/js/', src: '**/*.js', dest: '<%= output %>/assets/js/' }; } else { return { // do nothing }; } })() } }); };
I know that Grunt can read data from a file using the file "grunt.file.readJSON" and then have this data with the following variable: "<% = pkg.value%>".
What I want to do is create a task with if / else options based on the variables from the JSON file. I don’t understand how to pass the Grunt variable '<% = pkg.value%>' into the JavaScript if statement in a way that it understands. I tried passing it in the same Grunt format with "<% =%>", as well as deleting this part and passing in "pkg.value", but it doesn't seem to work.
If someone can shed light on whether this can be done and how, I would really appreciate it. Thanks!
source share