Concatenating and wrapping resources to cache
Install with npm
npm install gulp-resource-cache
gulp.src('*.html')
.pipe(gulpResourceCache({
wrapperTpl: 'function(){ var cache = window.cache; <%= contents %> }',
name: 'templates.html'
}))
.pipe(gulp.dest('compiled'));
You get merged file:
function(){ var cache = window.cache;
cache.put("templates/template1.html", "<div>Template 1</div>");
cache.put("templates/template2.html", "<div>Template 2</div>");
cache.put("templates/template3.html", "<div>Template 3</div>");
}
Note: you need defined cache.put
method in your application.
You can define wrapperTpl
for any case and any frameworks.
amd:
define("<%= name %>", [], function(){ var cache = window.cache; <%= contents %> });
angular template cache:
angular.module("<%= name %>").run(["$templateCache", function(cache) {<%= contents %> }]);
angular http cache:
angular.module("<%= name %>").run(["$cacheFactory", function($cacheFactory) {var cache = $cacheFactory.get("$http"); <%= contents %> }]);
etc.
Object with the following parameters
Type: String
Default: ''
Root path for resource url cache.put(root + url, content)
Type: String
Default: file.base
Base path for resource url. It is subtracted from the address of the resource
Type: String
Default: 'cached' + extention
Merged file name
Type: String
Default: 'cache.put("<%= url %>", "<%= contents %>");\n'
Cached resource template
Type: String
Default: '<%= contents %>'
Wrapper template
Type: Object
Custom data for cacheTpl
and wrapperTpl
© Oleg Istomin 2015. Released under the MIT license