0

I have a Grunt concat task that I am trying to understand how to apply banners to. If I supply a banner in the "options" object, it gets applied to each of my subtasks. This is by design, but it's not optimal-- each of the concat tasks would ideally have their own banner!

One of my subtasks is to concat the results of my concat. In this case, 3 banners are applied. One to each preliminary concat and one to the final concat.

I would be happiest with a solution to this:

How can I apply a custom banner only to each subtask? In my imagination, the syntax would look like this:

concat: {
  options: { /* ... */ },
  myStuff: {
    banner: 'Some banner',
    src: ['a.js','b.js'],
    dest: 'somepath/complete.js'
  },
  otherStuff: {
    banner: 'A totes different banner',
    src: ['c.js','d.js'],
    dest: 'somepath/complete2.js'
  }
}

Is there an equivalent for the above that I may have overlooked while digging through the grunt-contrib-concat documentation?

The alternative for me would be to put all of my comments in just one comment at the top, including the license information for all included libraries. If the individual task could strip banners and then add just the one?

Here's my current concat object if it's useful to anyone (you can assume that the template pieces all work):

concat: {
    options: {
        stripBanners: false,
        banner: '/*!\n' +
            ' * Concatenated JavaScript includes Bootstrap v<%= bootstrapInfo.version %> (<%= bootstrapInfo.homepage %>)\n' +
            ' * Copyright 2011-<%= grunt.template.today("yyyy") %> <%= bootstrapInfo.author %>\n' +
            ' * Licensed under the <%= bootstrapInfo.license %> license\n' +
            ' *\n' +
            ' * Also includes jQuery DataTables <%=dataTablesInfo.version %> (<%= dataTablesInfo.homepage %>)\n' +
            ' * Copyright 2008-<%= grunt.template.today("yyyy") %> <%= dataTablesInfo.author %>\n' +
            ' * Licensed under the <%= dataTablesInfo.license %> license (http://datatables.net/license)\n' +
            ' */\n',
    },
    bootstrapJS: {
        src: [
            'lib/bootstrap/js/transition.js',
            'lib/bootstrap/js/alert.js',
            'lib/bootstrap/js/button.js',
            'lib/bootstrap/js/carousel.js',
            'lib/bootstrap/js/collapse.js',
            'lib/bootstrap/js/dropdown.js',
            'lib/bootstrap/js/modal.js',
            'lib/bootstrap/js/tooltip.js',
            'lib/bootstrap/js/popover.js',
            'lib/bootstrap/js/scrollspy.js',
            'lib/bootstrap/js/tab.js',
            'lib/bootstrap/js/affix.js'],
        dest: 'purgatory/js/bootstrap.js'
    },
    dataTablesJS: {
        src: [
            'lib/datatables/js/jquery.dataTables.js',
            'lib/datatables/js/dataTables.bootstrap.js'],
        dest: 'purgatory/js/dataTables.js'
    },
    noCompMonolith: {
        src: ['<%= concat.bootstrapJS.dest %>', '<%= concat.dataTablesJS.dest %>'],
        dest: 'dev/js/application_monolith.js'
    }
}

In this example, the 3 instances of the heading are spit out.

Greg Pettit
  • 10,749
  • 5
  • 53
  • 72
  • I have a partial solution: I modified my banner to use `/*` instead of `/*!` and I set `stripBanners` to true, which happens BEFORE adding a configured banner. But yeah... it deletes some of the banners I wanted to keep intact. – Greg Pettit Jun 30 '15 at 20:24
  • ...aaaaaand nope. I've continued working and it's time to concatenate my non-vendor files to a different JS. The banner is, of course, the "Bootstrap and Datatables" one specified above. – Greg Pettit Jun 30 '15 at 20:39

0 Answers0