Grunt plugin to compile files into AngularJs cache
*If you are new to Grunt, you will find a lot of answers to your questions in their getting started guide.
To install the module:
npm install --save-dev git@github.com:pborrazas/grunt-ng-cache.git
Include the task in your Gruntfile:
grunt.loadNpmTasks('grunt-ng-cache');
Create a config block within your Gruntfile:
ngCache: {
target: {
src: 'path/to/files/to/be/cached',
dest: 'path/to/dist/folder/',
moduleName: 'moduleName' /* Required. AngularJs module name */
},
options: {
cacheName: 'customCacheName', /* Use 'templates' for template files */,
cacheUrl: null,
standalone: false,
verbose: false
}
}
Type: String
Default: $http
Defaults to '$http', the default AngularJs cache name for http requests. Use 'templates' to cache HTML files.
Type: Function
Default: null
Allows customization of the urls files are added to the cache. The function receives the auto-generated url path as the first argument and is expected to return a string which will be used as the new url path for cache.
Type: Boolean
Default: false
Indicates whether the referenced module by ´moduleName´ is an existing module or a new one has to be created. Defaults to false
Type: Boolean
Default: false
Print details of the added files to cache.
Type: Boolean
Default: true
Whether the content should be escaped. Enabled by default.
Type: String
Default: ''
AngularJS module name by default.
ngCache: {
customCache: {
src: 'src/i18n/*.json',
dest: 'dist/l10nCache.js',
moduleName: 'demo'
}
}
ngCache: {
templateCache: {
src: 'src/templates/*.html',
dest: 'dist/templateCache.js',
moduleName: 'demo',
options: {
cacheName: 'templates'
}
}
}
ngCache: {
customCache: {
src: 'src/i18n/*.json',
dest: 'dist/l10nCache.js',
moduleName: 'demo',
options: {
cacheName: 'customCacheName'
}
}
}
ngCache: {
customCache: {
src: 'src/templates/*.html',
dest: 'dist/templateCache.js',
moduleName: 'demo',
options: {
cacheUrl: function (filePath) {
var fileName = filePath.replace(/\/|.*(?![^\/]*$)/g, '');
return 'custom-url-path/' + fileName;
}
}
}
}
ngCache: {
htmlmin: {
templates: {
options: {
removeComments: true,
collapseWhitespace: true
},
files: [{
src: '**/*.html',
dest: '.tmp/templates' /* <-- use a temporary folder to write on */
}]
}
},
customCache: {
src: '.tmp/templates/*.html', /* <-- and to read from */
dest: 'dist/templateCache.js',
moduleName: 'demo'
}
}
This grunt plugin is based on the following existent plugins: karma-ng-html2js-preprocessor grunt-angular-templates