Registry / devops / angular-template-cache

angular-template-cache

JSON →
library1.3.3jsnpmunverified

CLI tool to pre-cache HTML templates into AngularJS $templateCache, reducing HTTP requests. Version 1.3.3 is the latest stable release (last updated 2016-03-09). It supports glob patterns, HTML minification (via html-minifier), custom output, base path stripping, and configurable module naming. Differentiators include TypeScript support, multiple module styles (browser, browserify, ES2015), and the ability to ignore missing files. This project is in maintenance mode and not compatible with Angular (2+).

npm install angular-template-cache
INSTALL
IMPORT
SIG · ANGULAR-TEMPLATE-C
A
angular-template-cache
devopsjavascriptv1.3.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

angularTemplateCache (CLI)
npx nghtml2js -m 'myModule' -f 'src/**/*.html' -o templates.js
npx angular-template-cache ...
The package exposes an executable called 'nghtml2js' (not 'angular-template-cache'). Use npx or local path.
module (programmatic API)
const ngHtml2Js = require('angular-template-cache');
import ngHtml2Js from 'angular-template-cache';
The programmatic API uses CommonJS require. Default export is the main function. No ES module wrapper exists.
TypeScript types
No separate type import required. Generated file will have // @ts-check at top.
import { nghtml2js } from 'angular-template-cache';
The package does not export any TypeScript type; it only generates template files with optional type comment via --service-type.

Generates an AngularJS module that pre-caches all HTML templates using $templateCache. Run CLI with glob pattern and output file, then include the generated file in your app.

// Install the package npm install angular-template-cache --save-dev // Run the CLI to cache all HTML files under src/ into a module named 'templates' // The output file will be src/templates.js npx nghtml2js -m 'templates' -f 'src/**/*.html' -o src/templates.js // Then include the generated file in your AngularJS app (e.g., via script tag or bundler) // Example usage in AngularJS module: angular.module('myApp', ['templates']);
Debug
Known issues
gotchaThe glob pattern with -f must be quoted in Unix shells to prevent bash expansion.
fix
Always quote the pattern: -f 'src/**/*.html'
affects: >=1.0
gotchaThe default module name is 'templates'; if you already have a module named 'templates' but without dependencies, the generated code will assume it exists (--no-new-module).
fix
Use -m to specify a custom module name, or use --no-new-module if the module is already defined elsewhere.
affects: >=1.0
gotchaHTML minification is enabled by default and can break custom Angular directives that embed raw HTML (e.g., ng-include with dynamic content).
fix
Disable minification with --no-html-min or fine-tune html-minifier options with --htmlmin-* flags.
affects: >=1.0
breakingGenerated output style changed between v1.2.x and v1.3.x: default style is now browser (not browserify). Use --style to specify.
fix
Provide --style browserify if you need CommonJS require syntax.
affects: >=1.3.0 <1.3.3
gotchaThe programmatic API does not return a promise; it uses a callback or synchronous fs operations.
fix
Use callback pattern: const ngHtml2Js = require('angular-template-cache'); ngHtml2Js(options, callback);
affects: >=1.0
Errors
Common errors & fixes
Error: Cannot find module 'angular-template-cache'
The package is not installed or is installed globally but required locally.
fix
Install as devDependency: npm install angular-template-cache --save-dev
bash: nghtml2js: command not found
CLI not in PATH; try using npx or direct path.
fix
Use npx nghtml2js or node_modules/.bin/nghtml2js
ReferenceError: angular is not defined
NgHtml2Js generates code that references the Angular global variable, which must be loaded before the generated file.
fix
Ensure angular.js is included before the generated template file.
Upgrade
Version history
1.3.3latest on npm
Audit
Dependencies
angularrequiredRuntime dependency: the generated code references AngularJS $templateCache service.
Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
angular-template-cache — npm install angular-template-cache · libregistry