How to remove templateCache using gulp?

I am using angular-template-cache. there is some code to delete template cache in app module, but I need to delete all templateCache using gulp on dev machine.

myApp.run(function($rootScope, $templateCache) {
   $rootScope.$on('$viewContentLoaded', function() {
      $templateCache.removeAll();
   });
});

      

+3


source to share


1 answer


The best way to avoid template caching is to revise your files.

Since you are using gulp

, you can edit your files with gulp-rev

or gulp-rev-all

.

What is revision?

Revision static assets by adding the content hash to the file names unicorn.css

unicorn-d41d8cd98f.css

.

ie, In each assembly, the filename is changed and thus avoids template caching. You can edit each file, including .html

, .css

, .js

, images

, videos

, etc.

Since it gulp-rev-all

is the latest and forks out gulp-rev

, tell just about gulp-rev-all

.

Revision using gulp-rev-all

:

var revAll = require('gulp-rev-all');

      

if you want to neglect some files from revision, you can do it like this.

var rev = new revAll({dontRenameFile: [/^\/favicon.ico$/g, /^\/index.html/g]})

      



Review all your files in the folder dist

and save the new files in the folder www

. (You can also save them to dist

. Given which www

is your build directory.)

return gulp.src('dist/**')
  .pipe(rev.revision())
  .pipe(gulp.dest('www'))

      

Then create a file manifest

to map the files to the changed. to use the function .manifestFile()

. which returns a transform function that will filter out any existing files passing through the pipe and produce a new manifest file. Should be called after .revision ().

.pipe(rev.manifest())
.pipe(gulp.dest('www/manifest'));

      

A resource attribute representing the original paths to the revised paths will be written to www/manifest/rev-manifest.json

:

{
 "css/unicorn.css": "css/unicorn.098f6bcd.css",
 "js/unicorn.js": "js/unicorn.273c2cin.js"
 ..... 
 ..... 
}

      

Complete code:

gulp.task('rev', () => {
  var revAll = require('gulp-rev-all'),
    rev = new revAll({dontRenameFile: [/^\/favicon.ico$/g, /^\/index.html/g]});
return gulp.src('dist/**')
  .pipe(rev.revision())
  .pipe(gulp.dest('www'))
  .pipe(rev.manifest())
  .pipe(gulp.dest('www/manifest'));
});

      

More about gulp-rev-all

here

+1


source







All Articles