Search code examples
gruntjsgrunt-usemin

Grunt + usemin, how to include one HTML file in another?


I have a head.html file that includes all of my bundles:

<!-- build.js(.) scripts/scripts.js -->
<script src="scripts/script1.js"></script>
<script src="scripts/script2.js"></script>
<!-- endbuild -->

I need this file to be separate because I want to use the generated tags to the bundles on legacy parts of my site that aren't part of the app I'm building.

I would then like my index.html to do something like this:

<head>
  <!-- include:head.html -->
</head>

grunt-usemin doesn't seem to support this directive. Any ideas on how I can make this happen?


Solution

  • Figured it out. Use grunt-includes and add this to the Gruntfile:

    includes: {
        files: {
            src: ['<%= yeoman.dist %>/{,*/}*.html'],
            dest: '.'
        }
    },
    

    Then add an 'includes' step after the copy step in the build task.