我使用角模板緩存。 下面的代碼存在用於刪除應用程序模塊中的模板緩存,但我需要在開發機器上刪除所有具有吞噬功能的templateCache。如何使用gulp刪除templateCache?
myApp.run(function($rootScope, $templateCache) {
$rootScope.$on('$viewContentLoaded', function() {
$templateCache.removeAll();
});
});
我使用角模板緩存。 下面的代碼存在用於刪除應用程序模塊中的模板緩存,但我需要在開發機器上刪除所有具有吞噬功能的templateCache。如何使用gulp刪除templateCache?
myApp.run(function($rootScope, $templateCache) {
$rootScope.$on('$viewContentLoaded', function() {
$templateCache.removeAll();
});
});
避免模板緩存的最好方法是修改您的文件。
由於您使用的是gulp
,因此您可以使用gulp-rev
或gulp-rev-all
修訂文件。
什麼是修訂?
靜態資產修改通過將內容哈希附加到文件名unicorn.css
→unicorn-d41d8cd98f.css
。
即,在每個版本上,文件名改變並且這樣避免了模板緩存。 您可以修改每一個文件,包括.html
,.css
,.js
,images
,videos
等
由於gulp-rev-all
是最新的,並從gulp-rev
分叉,讓我們對gulp-rev-all
只說說。
Revisioning使用gulp-rev-all
:
var revAll = require('gulp-rev-all');
,如果你想從忽略一些revisioning文件,你可以是這樣做的。
var rev = new revAll({dontRenameFile: [/^\/favicon.ico$/g, /^\/index.html/g]})
考慮您的所有文件夾dist
和保存的文件夾www
新revisioned文件。(你可以將它們保存在dist
也。考慮www
是你的build目錄。)
return gulp.src('dist/**')
.pipe(rev.revision())
.pipe(gulp.dest('www'))
接下來,創建一個manifest
文件來映射您的文件與修訂的文件。爲此使用.manifestFile()
函數。它將返回一個轉換函數,該函數將過濾掉通過管道的所有現有文件併發出新的清單文件。必須在.revision()之後調用。
.pipe(rev.manifest())
.pipe(gulp.dest('www/manifest'));
的資產清單,映射所述原始路徑的revisioned路徑,將被寫入到www/manifest/rev-manifest.json
:
{
"css/unicorn.css": "css/unicorn.098f6bcd.css",
"js/unicorn.js": "js/unicorn.273c2cin.js"
.....
.....
}
完整代碼:
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'));
});
瞭解更多關於gulp-rev-all
here
感謝您的回答,但我使用角模板緩存模板緩存,我想在開發機器上刪除templateCache與吞噬。 –