Skip to content

Instantly share code, notes, and snippets.

@vojtajina
Created August 14, 2012 08:17
Show Gist options
  • Save vojtajina/3347478 to your computer and use it in GitHub Desktop.
Save vojtajina/3347478 to your computer and use it in GitHub Desktop.
Grunt script for inlining AngularJS templates
module.exports = function(grunt) {
grunt.initConfig({
inline: {
'index.html': ['tpl/*.html']
}
});
grunt.registerMultiTask('inline', 'Inline AngularJS templates into single file.', function() {
var SCRIPT = '<script type="text/ng-template" id="<%= id %>"><%= content %></script>\n';
var html = '$1\n\n';
grunt.file.expandFiles(this.data).forEach(function(file) {
grunt.log.writeln('Inlining ' + file);
html += grunt.template.process(SCRIPT, {id: file, content: grunt.file.read(file)});
});
var result = this.target;
grunt.file.write(result, grunt.file.read(result).replace(/(<body[^>]*>)/, html));
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment