Standalone script to load all your Angular html/jade templates into the $templateCache using npm. Based off of https://github.com/arnauddri/npm-html2js
npm install exos-npm-html2jsUse npm as a build tool to load all your jade/html templates into your $templateCache.
``javascript`
$ npm-html2js -i 'src/*/.jade' -o 'dist/template.js'
angular.module('template.js', []);
.run(['$templateCache', function($templateCache) {
.$templateCache.put('files/file1.tpl.jade',
'\n' +')
' Hello World from file1!
\n' +
'
.$templateCache.put('files/file2.tpl.jade',
'\n' +')
' Hello World from file2!
\n' +
'
.$templateCache.put('files/subfolder/subfile1.tpl.jade',
'\n' +')
' Hello World from subfile1!
\n' +
'
.$templateCache.put('files/subfolder/subfile2.tpl.jade',
'\n' +')
' Hello World from subfile2!
\n' +
'
}]);
Via npm:
`shell`
npm install --save-dev npm-html2js
And load it in your build process in your `package.json`:`json`
"scripts": {
"build": "npm-html2js -i 'files/*/.html' -o 'dist/template.js'"
},
#### Note for Windows users
If running on Windows, make sure to replace the single quotes with escaped double quotes:
`json`
"scripts": {
"build": "npm-html2js -i \"files/*/.html\" -o \"dist/template.js\""
},
##### Input
Path to your templates. The module supports globbing so you can use path like `src/*/.tpl.html`
example:
`shell`
npm-html2js -i 'files/*/.tpl.html'
##### output
Path to the expected output file.
example:
`shell`
npm-html2js ... -o 'dist/template.js'
##### module
The name of the parent Angular module for each set of templates. Defaults to the task target prefixed by templates.js
example:
`shell`
npm-html2js ... -m 'myModule'
##### jade
if the filename ends with `.jade`, the task will automatically render file's content using Jade then comile into JS
##### base
The prefix relative to the project directory that should be stripped from each template path to produce a module identifier for the template. For example, a template located at `src/projects/projects.tpl.html` would be identified as just `projects/projects.tpl.html`.
example:
`shell`
npm-html2js ... -b 'src'
##### minify
Minify the html before compiling to JS
example:
`shell``
npm-html2js ... --minify
##### help
Display the command line options