AngularJS,Gulp静态资产修订

时间:2017-12-07 15:57:44

标签: javascript angularjs gulp gulp-rev

我正在使用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 Code:

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'));

});

1 个答案:

答案 0 :(得分:0)

感谢@lzagkaretos的帮助。

使用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')); }); 解决了我的问题。

Gulp代码:

mapfile -t names < dates.txt && mkdir "${names[@]}"