{"id":13912597,"url":"https://github.com/ericclemmons/grunt-angular-templates","last_synced_at":"2025-05-14T17:02:29.170Z","repository":{"id":6274323,"uuid":"7507968","full_name":"ericclemmons/grunt-angular-templates","owner":"ericclemmons","description":"Grunt build task to concatenate \u0026 pre-load your AngularJS templates","archived":false,"fork":false,"pushed_at":"2022-12-06T18:14:33.000Z","size":396,"stargazers_count":710,"open_issues_count":40,"forks_count":106,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-05-12T05:52:17.786Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericclemmons.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-08T19:44:51.000Z","updated_at":"2025-03-23T22:57:23.000Z","dependencies_parsed_at":"2022-09-06T05:20:21.975Z","dependency_job_id":null,"html_url":"https://github.com/ericclemmons/grunt-angular-templates","commit_stats":null,"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericclemmons%2Fgrunt-angular-templates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericclemmons%2Fgrunt-angular-templates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericclemmons%2Fgrunt-angular-templates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericclemmons%2Fgrunt-angular-templates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericclemmons","download_url":"https://codeload.github.com/ericclemmons/grunt-angular-templates/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254190366,"owners_count":22029629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-07T01:01:35.015Z","updated_at":"2025-05-14T17:02:29.094Z","avatar_url":"https://github.com/ericclemmons.png","language":"JavaScript","funding_links":[],"categories":["others","JavaScript","Task"],"sub_categories":[],"readme":"# grunt-angular-templates\n\n[![Build Status](https://travis-ci.org/ericclemmons/grunt-angular-templates.svg)](https://travis-ci.org/ericclemmons/grunt-angular-templates)\n[![Dependencies](https://david-dm.org/ericclemmons/grunt-angular-templates.svg)](https://david-dm.org/ericclemmons/grunt-angular-templates)\n[![devDependencies](https://david-dm.org/ericclemmons/grunt-angular-templates/dev-status.svg)](https://david-dm.org/ericclemmons/grunt-angular-templates#info=devDependencies\u0026view=table)\n\n\u003e Speed up your AngularJS app by automatically minifying, combining,\n\u003e and automatically caching your HTML templates with `$templateCache`.\n\nHere's an example of the output created by this task from multiple `.html` files:\n\n```js\nangular.module('app').run([\"$templateCache\", function($templateCache) {\n  $templateCache.put(\"home.html\",\n    // contents for home.html ...\n  );\n  ...\n  $templateCache.put(\"src/app/templates/button.html\",\n    // contents for button.html\n  );\n}]);\n```\n\nThen, when you use `ng-include` or `templateUrl` with `$routeProvider`,\nthe template is already loaded without an extra AJAX request!\n\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Options](#options)\n- [Usage](#usage)\n- [Examples](#examples)\n- [Changelog](#changelog)\n- [License](#license)\n\n\n## Installation\n\n*This plugin requires [Grunt][1] `~0.4.0`*\n\n*Usemin integration requires [grunt-usemin][5] `~2.0.0`*\n\nInstall the plugin:\n\n    $ npm install grunt-angular-templates --save-dev\n\nEnable the plugin within your `Gruntfile`:\n\n```js\ngrunt.loadNpmTasks('grunt-angular-templates');\n```\n\n\n## Options\n\n### angular\n\n\u003e Global namespace for Angular.\n\nIf you use `angular.noConflict()`, then set this value to whatever you\nre-assign angular to.  Otherwise, it defaults to `angular`.\n\n### bootstrap\n\n\u003e Callback to modify the bootstraper that registers the templates with `$templateCache`.\n\nBy default, the bootstrap script wraps `function($templateCache) { ... }` with:\n\n```js\nangular.module('app').run(['$templateCache', ... ]);\n```\n\nIf you want to create your own wrapper so you register the templates as an\nAMD or CommonJS module, set the `bootstrap` option to something like:\n\n```js\nbootstrap: function(module, script) {\n  return 'module.exports[module] = ' + script + ';';\n}\n```\n\n### concat\n\n\u003e Name of `concat` target to append the compiled template path to.\n\nThis is especially handy if you combine your scripts using\n[grunt-contrib-concat][4] or [grunt-usemin][5].\n\n### htmlmin\n\n\u003e Object containing [htmlmin options][2] that will *significantly* reduce\nthe filesize of the compiled templates.\n\nWithout this, the HTML (whitespace and all) will be faithfully compiled\ndown into the final `.js` file.  Minifying that file will only cut down\non the *Javascript* code, not the *HTML* within the strings.\n\nNote - this does incur a performance cost. Simply leave out this option to\nprevent minificaiton.\n\nI recommend using the following settings for production:\n\n```js\nhtmlmin: {\n  collapseBooleanAttributes:      true,\n  collapseWhitespace:             true,\n  keepClosingSlash:               true, // Only if you are using SVG in HTML\n  removeAttributeQuotes:          true,\n  removeComments:                 true, // Only if you don't use comment directives!\n  removeEmptyAttributes:          true,\n  removeRedundantAttributes:      true,\n  removeScriptTypeAttributes:     true,\n  removeStyleLinkTypeAttributes:  true\n}\n```\n\n### module\n\n\u003e `String` of the `angular.module` to register templates with.\n\nIf not specified, it will automatically be the name of the `ngtemplates`\nsubtask (e.g. `app`, based on the examples below).\n\n### prefix\n\n\u003e `String` to prefix template URLs with.\nDefaults to `''`\n\nIf you need to use absolute urls:\n\n```js\nngtemplates: {\n  app: {\n    options: {\n      prefix: '/'\n    }\n  }\n}\n```\n\nIf you serve static assets from another directory, you specify that as well.\n\n### source\n\n\u003e Callback to modify the template's source code.\n\nIf you would like to prepend a comment, strip whitespace, or do\npost-processing on the HTML that `ngtemplates` doesn't otherwise do,\nuse this function.\n\n### append\n\n\u003e Boolean to indicate the templates should be appended to dest instead of replacing it.\nNormally grunt-angular-templates creates a new file at `dest`.\nThis option makes it append the compiled templates to the `dest` file rather than replace its contents.\nThis is just a useful alternative to creating a temporary `dest` file and concatting it to your application.\n\n\n### standalone\n\n\u003e Boolean indicated if the templates are part of an existing module or a standalone.\nDefaults to `false`.\n\n- If the value is `false`, the module will look like `angular.module('app')`, meaning `app` module is retrieved.\n- If the value is `true`, the module will look like `angular.module('app', [])`, meaning `app` module is created.\n\n### url\n\n\u003e Callback to modify the template's `$templateCache` URL.\n\nNormally, this isn't needed as specifying your files with `cwd`\nensures that URLs load via both AJAX and `$templateCache`.\n\n### usemin\n\n\u003e Path to `\u003c!-- build:js [path/to/output.js] --\u003e` usemin target\n\nThis should be the output path of the compiled JS indicated in your HTML,\nsuch as `path/to/output.js` shown here.\n\n### quotes\n\n\u003e Use single or double quotes to wrap the template strings\n\nDefaults to 'double', other option is 'single'\n\n## Usage\n\n\n### Compiling HTML Templates\n\nAfter configuring your `ngtemplates` task, you can either run the\ntask directly:\n\n    $ grunt ngtemplates\n\nOr, bake it into an existing task:\n\n```js\ngrunt.registerTask('default', [ 'jshint', 'ngtemplates', 'concat' ]);\n```\n\n### Including Compiled Templates\n\nFinally, you have to load the compiled templates' `.js` file into your\napplication.\n\n\n#### Using HTML\n\n```html\n\u003cscript src=\"templates.js\"\u003e\u003c/script\u003e\n```\n\n\n#### Using Grunt's `concat` task:\n\nThis is my personal preference, since you don't have to worry about\nwhat the destination file is actually called.\n\n```js\nconcat:   {\n  app:    {\n    src:  [ '**.js', '\u003c%= ngtemplates.app.dest %\u003e' ],\n    dest: [ 'app.js' ]\n  }\n}\n```\n\n#### Using [grunt-usemin][5]\n\nUsing the following HTML as an example:\n\n```html\n\u003c!-- build:js dist/vendors.js --\u003e\n\u003cscript src=\"bower_components/angular/angular.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"bower_components/angular-resource/angular-resource.js\"\u003e\u003c/script\u003e\n\u003c!-- endbuild --\u003e\n```\n\n**Do not use the `concat` option**, even though grunt-usemin generates a `concat.generated`\nobject behind the scenes.  Instead, use the `usemin` option to indicate the anticipated\noutput filepath from grunt-usemin.\n\n```js\nngtemplates:  {\n  app:        {\n    src:      '**.html',\n    dest:     'template.js',\n    options:  {\n      usemin: 'dist/vendors.js' // \u003c~~ This came from the \u003c!-- build:js --\u003e block\n    }\n  }\n}\n```\n\n**Note**: Earlier versions of grunt-usemin (*correctly, in my opinion*) would have generated\na `concat['dist/vendors.js']` object for each build section in the HTML.  Now,\nbecause there's a single `concat.generated` object with **all** JS/CSS files within it,\nI'm back-tracking the proper `concat` target for you.\n\n## Examples\n\n\n### Register HTML Templates in `app` Module\n\n```js\nngtemplates:  {\n  app:        {\n    src:      '**.html',\n    dest:     'templates.js'\n  }\n}\n```\n\n\n### Register Relative Template URLs\n\nNormally, your app, templates, \u0026 server are in separate folders, which means\nthat the template URL is **different** from the file path.\n\n```js\nngtemplates:  {\n  app:        {\n    cwd:      'src/app',\n    src:      'templates/**.html',\n    dest:     'build/app.templates.js'\n  }\n}\n```\n\nThis will store the template URL as `templates/home.html` instead of\n`src/app/templates/home.html`, which would cause a 404.\n\n\n### Minify Template HTML\n\nSimply pass the [same options][2] as the `htmlmin` task:\n\n```js\nngtemplates:    {\n  app:          {\n    src:        '**.html',\n    dest:       'templates.js',\n    options:    {\n      htmlmin:  { collapseWhitespace: true, collapseBooleanAttributes: true }\n    }\n  }\n}\n```\n\nOr, if you already have an existing `htmlmin` task, you can reference it:\n\n```js\nngtemplates:    {\n  app:          {\n    src:        '**.html',\n    dest:       'templates.js',\n    options:    {\n      htmlmin:  '\u003c%= htmlmin.app %\u003e'\n    }\n  }\n}\n```\n\n\n### Customize Template URL\n\nSuppose you only use `ngtemplates` when on production, but locally you serve\ntemplates via Node, sans the `.html` extension.\n\nYou can specify a `url` callback to further customize the registered URL:\n\n```js\nngtemplates:  {\n  app:        {\n    src:      '**.html',\n    dest:     'templates.js',\n    options:  {\n      url:    function(url) { return url.replace('.html', ''); }\n    }\n  }\n}\n```\n\n\n### Customize Output\n\nSome people like [AMD \u0026 RequireJS][3] and would like wrap the output\nin AMD or something else (don't ask me why!):\n\n```js\nngtemplates:      {\n  app:            {\n    src:          '**.html',\n    dest:         'templates.js',\n    options:      {\n      bootstrap:  function(module, script) {\n        return 'define(' + module + ', [], function() { return { init: ' + script + ' }; });';\n      }\n    }\n  }\n}\n```\n\nYou will be able to custom everything surrounding `$templateCache.put(...)`.\n\n\n## Changelog\n\n- v1.1.0 - Added the `merge` option to allow templates to maintain directory structure if set to `false` ([#114](https://github.com/ericclemmons/grunt-angular-templates/pull/114))\n- v1.0.4 - Updated html-minifier to 2.1.2 ([#162](https://github.com/ericclemmons/grunt-angular-templates/pull/162))\n- v1.0.3 - Fixes issue with using usemin without uglify ([#153](https://github.com/ericclemmons/grunt-angular-templates/pull/153))\n- v1.0.2 - Fixes issue with escaping carriage returns ([#147](https://github.com/ericclemmons/grunt-angular-templates/pull/147)), Fixes issue with escaping backslashes ([#146](https://github.com/ericclemmons/grunt-angular-templates/pull/146))\n- v1.0.1 - Log error instead of warning when minify fails ([#139](https://github.com/ericclemmons/grunt-angular-templates/pull/139))\n- v1.0.0 - Updated unit tests for performance and bumps dependency versions ([#143](https://github.com/ericclemmons/grunt-angular-templates/pull/143))\n- v0.6.0 - Adds `quotes` options to allow wrapping in single instead of double quotes ([#142](https://github.com/ericclemmons/grunt-angular-templates/pull/142))\n- v0.5.9 - Fixes over-matching on `cwd` when `expand:true`\n- v0.5.8 - Fixes `cwd` being part of the $templateCache string when `expand:true` ([#134](https://github.com/ericclemmons/grunt-angular-templates/pull/134)), Added verbose logging for minify ([#136](https://github.com/ericclemmons/grunt-angular-templates/pull/136))\n- v0.5.7 – Improve error messages ([#100](https://github.com/ericclemmons/grunt-angular-templates/pull/100))\n- v0.5.6 – Updated `html-minifier` to correct whitespace issues. ([96](https://github.com/ericclemmons/grunt-angular-templates/pull/96))\n- v0.5.5 – Add `append` option to concat, not overwrite the `dest`. ([#89](https://github.com/ericclemmons/grunt-angular-templates/pull/89))\n- v0.5.4 – Specifying an invalid `usemin` option still creates file ([#84](https://github.com/ericclemmons/grunt-angular-templates/pull/84))\n- v0.5.3 – Fix bug with Underscore templates ([#79](https://github.com/ericclemmons/grunt-angular-templates/pull/79))\n- v0.5.2 – Fix `usemin` matching issue on Windows ([#80](https://github.com/ericclemmons/grunt-angular-templates/pull/80))\n- v0.5.1 – Add `usemin` option form v0.4.10\n- v0.5.0 – Works with `grunt-usemin` ([#44](https://github.com/ericclemmons/grunt-angular-templates/issues/44))\n- v0.4.10 – Add `usemin` option\n- v0.4.9 – Improve `prefix` and support for URLs ([#57](https://github.com/ericclemmons/grunt-angular-templates/pull/57))\n- v0.4.8 – Compiled assets are JSHint-able ([#58](https://github.com/ericclemmons/grunt-angular-templates/pull/58))\n- v0.4.7 – Fix bug for when htmlmin is not an Object ([#56](https://github.com/ericclemmons/grunt-angular-templates/issues/56))\n- v0.4.6 – Add `prefix` option for easier URL prefixes ([#53](https://github.com/ericclemmons/grunt-angular-templates/pull/53))\n- v0.4.5 – Attempt to better normalize templates based on current OS ([#52](https://github.com/ericclemmons/grunt-angular-templates/pull/52))\n- v0.4.4 – Fixed regression caused by `htmlmin` ([#54](https://github.com/ericclemmons/grunt-angular-templates/pull/54))\n- v0.4.3 - `options.concat` targets on Windows convert `/` to `\\\\`. [#48](https://github.com/ericclemmons/grunt-angular-templates/issues/48)\n- v0.4.2 - Fix for using `grunt-env` to change environments. Thanks to @FredrikAppelros ([#20](https://github.com/ericclemmons/grunt-express-server/pull/20))\n- v0.4.1 – Fix bug with empty files.\n- v0.4.0 – Complete rewrite.\n- v0.3.12 – Whoops, forgot to make `htmlmin` a regular dependency. Thanks  @rubenv ([#37](https://github.com/ericclemmons/grunt-angular-templates/pull/37))\n- v0.3.11 – Add `htmlmin` option that supports both an `{ ... }` and `\u003c%= htmlmin.options %\u003e` for existing tasks.\n- v0.3.10 – Fix *unknown concat target* bug on windows, thanks to @trask ([#31](https://github.com/ericclemmons/grunt-angular-templates/pull/31))\n- v0.3.9 – Allow the creation of a new module via `module.define`, thanks to @sidwood ([#28](https://github.com/ericclemmons/grunt-angular-templates/pull/28))\n- v0.3.8 – Fix error that occurs when adding 0-length files, thanks to @robertklep ([#27](https://github.com/ericclemmons/grunt-angular-templates/pull/27))\n- v0.3.7 – Add `noConflict` option to work with [angular.noConflict](https://github.com/angular/angular.js/pull/1535), thanks to @mbrevoort ([#26](https://github.com/ericclemmons/grunt-angular-templates/pull/26))\n- v0.3.6 – Fix issue with dading to `concat` task when it's an array, thanks to @codefather ([#23](https://github.com/ericclemmons/grunt-angular-templates/pull/23))\n- v0.3.5 – Preserver line endings in templates, thanks to @groner ([#21](https://github.com/ericclemmons/grunt-angular-templates/pull/21))\n- v0.3.4 – Attempt to fix a bug with `Path`, thanks to @cgross ([#19](https://github.com/ericclemmons/grunt-angular-templates/issues/19))\n- v0.3.3 – Add `concat` option for automatically adding compiled template file to existing `concat` (or `usemin`-created) task, thanks to @cgross ([#17](https://github.com/ericclemmons/grunt-angular-templates/pull/17))\n- v0.3.2 – Add `module` option for setting which module the templates will be added to, thanks to @sidwood ([#20](https://github.com/ericclemmons/grunt-angular-templates/pull/20))\n- v0.3.1 – Add `prepend` option for modifying final `$templateCache` IDs, thanks to @mbarchein. ([#16](https://github.com/ericclemmons/grunt-angular-templates/pull/16))\n- v0.3.0 – **BC break** - Templates are added to an existing module (e.g. `myapp`) rather than being their own `myapp.templates` module to be manually included, thanks to @geddesign. ([#10](https://github.com/ericclemmons/grunt-angular-templates/issues/10))\n- v0.2.2 – Escape backslashes, thanks to @dallonf. ([#9](https://github.com/ericclemmons/grunt-angular-templates/pull/9))\n- v0.2.1 – Remove `./bin/grunt-angular-templates`.  No need for it!\n- v0.2.0 – Update to Grunt 0.4, thanks to @jgrund. ([#5](https://github.com/ericclemmons/grunt-angular-templates/issues/5))\n- v0.1.3 – Convert `\\\\` to `/` in template IDs (for on win32 systems) ([#3](https://github.com/ericclemmons/grunt-angular-templates/issues/3))\n- v0.1.2 – Added NPM keywords\n- v0.1.1 – [Fails to combine multiple templates](https://github.com/ericclemmons/grunt-angular-templates/issues/1). Added directions to README on how to integrate with AngularJS app. Integrated with TravisCI\n- v0.1.0 – Released to [NPM](https://npmjs.org/package/grunt-angular-templates)\n\n\n## License\n\nCopyright (c) 2013 Eric Clemmons\nLicensed under the MIT license.\n\n\n[1]: http://gruntjs.com/\n[2]: https://github.com/gruntjs/grunt-contrib-htmlmin\n[3]: http://requirejs.org/docs/whyamd.html\n[4]: https://github.com/gruntjs/grunt-contrib-concat\n[5]: https://github.com/yeoman/grunt-usemin\n\n\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ericclemmons/grunt-angular-templates/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericclemmons%2Fgrunt-angular-templates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericclemmons%2Fgrunt-angular-templates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericclemmons%2Fgrunt-angular-templates/lists"}