Registry / devops / grunt-html2js-terser

grunt-html2js-terser

JSON →
library0.10.0jsnpmunverified

Grunt plugin that converts AngularJS HTML templates into JavaScript to cache them in an Angular module, eliminating lazy server loads. Version 0.10.0 uses html-minifier-terser instead of html-minifier for minification. Requires Grunt >=1.0.0 (peer dependency) and Node >=10. It is a fork of grunt-html2js with up-to-date dependencies. Designed for AngularJS 1.x projects, it is not suitable for Angular 2+.

npm install grunt-html2js-terser
INSTALL
IMPORT
SIG · GRUNT-HTML2JS-TERS
G
grunt-html2js-terser
devopsjavascriptv0.10.0
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.

grunt
grunt.loadNpmTasks('grunt-html2js-terser');
require('grunt-html2js-terser');
The plugin is loaded via Grunt's loadNpmTasks, not directly required. It must be configured in grunt.initConfig.
grunt.initConfig
grunt.initConfig({ html2js: { options: {}, target: { src: [], dest: '' } } });
grunt.initConfig({ 'grunt-html2js-terser': {} });
The task name is 'html2js', not the package name.
module
angular.module('main', ['templates-main'])
angular.module('main', ['grunt-html2js-terser'])
The generated module name is specified in the Gruntfile configuration, not the package name.

Shows Gruntfile setup: install, load plugin, configure html2js task to convert .tpl.html files into an AngularJS module for template caching.

// Install: npm install grunt-html2js-terser --save-dev // In Gruntfile.js module.exports = function(grunt) { grunt.loadNpmTasks('grunt-html2js-terser'); grunt.initConfig({ html2js: { options: { base: 'src', module: 'templates-myapp' }, main: { src: ['src/**/*.tpl.html'], dest: '.tmp/templates.js' } } }); grunt.registerTask('default', ['html2js']); };
Debug
Known issues
gotchaThe `dest` property must be a string. If it is an array, Grunt will fail when attempting to write the bundle file.
fix
Ensure dest is a single file path string, not an array.
affects: >=0.10.0
gotchaTask name is 'html2js' not 'grunt-html2js-terser'.
fix
Use grunt.loadNpmTasks('grunt-html2js-terser') and configure under html2js key.
affects: >=0.10.0
deprecatedThis plugin is for AngularJS (1.x) only. Not compatible with Angular 2+.
fix
Use Angular CLI or other build tools for Angular 2+.
affects: >=0.10.0
gotchaIf you use the `module` option, the generated module name must match the dependency in your AngularJS app. Mismatch causes template not found errors.
fix
Ensure angular.module('myApp', ['yourModuleName']) matches the module option.
affects: >=0.10.0
Errors
Common errors & fixes
Warning: Path must be a string. Received undefined
The `src` or `dest` property is missing or undefined in the Grunt configuration.
fix
Ensure both `src` (array of globs) and `dest` (string) are specified in the target.
Task "html2js" not found.
grunt.loadNpmTasks('grunt-html2js-terser') is missing or the package isn't installed.
fix
Install the package: npm install grunt-html2js-terser --save-dev, then add grunt.loadNpmTasks('grunt-html2js-terser'); to Gruntfile.
Fatal error: Unable to write "..." file (Error: ENOENT: no such file or directory...).
The directory for the dest file does not exist.
fix
Create the directory or use grunt.file.mkdir before the task: grunt.file.mkdir('.tmp');
Upgrade
Version history
0.10.0latest on npm
Audit
Dependencies
gruntrequiredGrunt >=1.0.0 is required as a peer dependency to load and run this plugin.
Agent activity
4 hits · last 30 days
node
4
Resources
grunt-html2js-terser — npm install grunt-html2js-terser · libregistry