Created
August 14, 2012 08:17
-
-
Save vojtajina/3347478 to your computer and use it in GitHub Desktop.
Grunt script for inlining AngularJS templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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