TheMcMurder
TheMcMurder

Reputation: 758

Grunt: sending array of sourceFiles to grunt task uglify

I can't seem to find the answer in the documentation. I want to send an array of sourceFiles from my package.json to the grunt task.

Here is my config.json

{
  "sourceFiles": ["src/js/d3js/d3.js", "src/js/testingGrunt.js"]
}

and here is my gruntfile.js

module.exports = function(grunt) {
  // Project configuration.

  grunt.initConfig({
     pkg: grunt.file.readJSON('package.json'),
     config: grunt.file.readJSON('config.json')
  });

  // Load the plugin that provides the concat tasks.
  grunt.loadNpmTasks('grunt-contrib-concat');

  // defining my concat task
  grunt.config('concat', {
        dist: {
          //src: ['src/js/testingGrunt.js', 'src/js/d3js/d3.js'],
          src: '<%config.sourceFiles%>',
          dest: 'build/<%= pkg.name %>-build.js'
        }
  });

  // Load the plugin that provides the uglify tasks.
  grunt.loadNpmTasks('grunt-contrib-uglify');

  // defining my uglify task
  grunt.config('uglify', {
      options: {
        banner: '/*\n*    ©<%= pkg.author%>\n*    <%= pkg.name %>\n*    <%= grunt.template.today("yyyy-mm-dd HH:mm:ss") %> \n*/\n'
      },
      build: {
        src: 'build/<%= pkg.name %>-build.js',
        dest: 'build/<%= pkg.name %>-build.min.js'
      }
  });



  // Default task(s).
  var defaultTasks;
  defaultTasks = ['concat', 'uglify']


  grunt.registerTask('default', defaultTasks);

};

The commented out line inside the grunt.config('concat',... works just fine. However I want to set up my gruntfile to read the files from the config file.

Eventually I'm going to be doing other things in this grunt task and I want to set it up so that I never need to edit the grunt file.

Upvotes: 0

Views: 1033

Answers (1)

Kyle Robinson Young
Kyle Robinson Young

Reputation: 13762

Looks like the template syntax is off try replacing:

src: '<%config.sourceFiles%>',

with the following:

src: '<%= config.sourceFiles %>',

Upvotes: 1

Related Questions