Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
grunt-angular-templates
Advanced tools
Grunt build task to concatenate & register your AngularJS templates in the $templateCache
Grunt build task to concatenate & register your AngularJS templates in the $templateCache
NOTE:
0.1.x
for Grunt 0.3.x
.0.2.x
or 0.3.x
for Grunt 0.4.x
.Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-angular-templates
Then add this line to your project's grunt.js
gruntfile:
grunt.loadNpmTasks('grunt-angular-templates');
This plugin provides the grunt task ngtemplates
, which will allow you to compile your HTML templates into a single JS file,
which preloads $templateCache
to prevent round-trips to the server.
// grunt.js
grunt.initConfig({
ngtemplates: {
myapp: {
options: {
base: 'src/views', // $templateCache ID will be relative to this folder
prepend: '/static/assets/', // (Optional) Prepend path to $templateCache ID
module: 'App' // (Optional) The module the templates will be added to
// Defaults to target name (e.g. `build`)
concat: 'dist/js/app.js' // (Optional) Append to existing `concat` target
},
src: 'src/views/**.html',
dest: 'dist/templates.js'
}
}
});
This will generate the following at dist/templates.js
:
angular.module('App').run(['$templateCache', function($templateCache) {
...
}]);
There are 3 different ways to make use of the compiled templates in your project:
an HTML script tag, an existing concat
task, or usemin
's dynamic concat
task.
<script src="dist/templates.js"></script>
Either add it explicitly to your concat
task:
concat: {
myapp: {
src: [
'src/js/**/*.js', // MyApp module first
'<%= ngtemplates.myapp.dest %>' // Generated templates (`dist/templates.js`)
],
dest: 'dist/js/app.js'
}
}
or have ngtemplates
add it to an existing concat
task for you:
concat: {
myapp: {
src: 'src/js/**/*.js', // Will automatically have `dist/templates.js` appended
dest: 'dist/js/app.js'
}
},
ngtemplates: {
myapp: {
options: {
concat: 'myapp' // Name of concat target to append to
},
src: 'src/views/**.html',
dest: 'dist/templates.js'
}
}
First, note the output of build:js
in your HTML:
<!-- build:js dist/js/app.js -->
<script src="src/js/app.js"></script>
...
Finally, add concat: 'dist/js/app.js
to the concat
option
ngtemplates: {
myapp: {
options: {
concat: 'dist/js/app.js'
},
src: 'src/views/**.html',
dest: 'dist/templates.js'
}
}
This will append the output file dist/js/templates.js
to
usemin
's dynamic concat
task: dist/js/app.js
.
concat
task when it's an array, thanks to @codefather (#23)Path
, thanks to @cgross (#19)concat
option for automatically adding compiled template file to existing concat
(or usemin
-created) task, thanks to @cgross (#17)module
option for setting which module the templates will be added to, thanks to @sidwood (#20)prepend
option for modifying final $templateCache
IDs, thanks to @mbarchein. (#16)myapp
) rather than being their own myapp.templates
module to be manually included, thanks to @geddesign. (#10)Fixes
./bin/grunt-angular-templates
. No need for it!Fixes
\\
to /
in template IDs (for on win32 systems) (#3)Fixes
New
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.
Copyright (c) 2013 Eric Clemmons Licensed under the MIT license.
FAQs
Grunt build task to concatenate & register your AngularJS templates in the $templateCache
The npm package grunt-angular-templates receives a total of 15,049 weekly downloads. As such, grunt-angular-templates popularity was classified as popular.
We found that grunt-angular-templates demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.