AngularJS, Gulp 静态资产修订

AngularJS, Gulp Static asset revisioning

我正在使用 gulp-rev 模块对我的源文件进行静态资产重新定位,它会生成所有文件 - CSS、JS 和 HTML,并在新文件名后附加哈希码在里面。

Before : app.js  
After  : app-2cba45c.js  

但是在我的 AngularJS 代码和 HTML 页面中我用实际名称引用了其他 HTML,当我使用 gulp-rev 时如何处理这个问题?

例如:

HTML代码:

        <div class="wd pull-left colapse_border">
            <ng-include src="'views/Header.html'"></ng-include>  <!-- how to handle this -->
           // This didn't work
            <!--  
                 <ng-include src="'views/Header*.html'"></ng-include>
            -->
        </div>

JS代码:

$routeProvider中:

            .when('/head',
            {
                templateUrl: 'views/Header.html', // how to handle this
                // This didn't work
                // templateUrl: 'views/Header*.html',
                controller: 'HeaderController'
            })  

Gulp代码:

var gulp = require('gulp'), 
    fileSort = require('gulp-angular-filesort'),
    cleanCss = require('gulp-clean-css'),
    rev = require('gulp-rev');

gulp.task('appFiles', function () {

var jsFiles = gulp.src('./src/**/*.js')
    .pipe(fileSort())
    .pipe(rev())
    .pipe(gulp.dest('./build'));

var cssFiles = gulp.src('./src/**/*.css')
    .pipe(cleanCss({debug: true}))
    .pipe(rev())
    .pipe(gulp.dest('./build' + '/Styles/CSS'));

var htmlFiles = gulp.src(['./src/**/*.html',  '!' + './src/index.html'])
    .pipe(rev())
    .pipe(gulp.dest('./build'));

var jsonFiles = gulp.src('./src +/**/*.json')
    .pipe(rev())
    .pipe(gulp.dest('./build'));

});

感谢@lzagkaretos 的帮助。

使用 gulp-rev-replace 解决了我的问题。

Gulp代码:

var rev = require('gulp-rev'),
    revReplace = require('gulp-rev-replace');

gulp.task('build', function () {
return gulp.src(['./src' + '/**/*.js', './src' + '/**/*.css', './src' + '/**/*.html', './src' + '/**/*.png', './src' + '/**/*.json', '!' + './src' + '/index.html'])
    .pipe(rev())
    .pipe(gulp.dest('./dist'))
    .pipe(rev.manifest())
    .pipe(gulp.dest('./dist'))
});

gulp.task("revreplace", function () {
var manifest = gulp.src("./dist/rev-manifest.json");
return gulp.src(['./dist/app/**/*.*','./dist/resources/*.*','./dist/styles/*.*'])
  .pipe(revReplace({manifest: manifest}))
  .pipe(gulp.dest('./build/app'));
});