How to include git revision into angular-cli application?

前端 未结 9 2190
甜味超标
甜味超标 2021-01-31 16:40

I need to display git revision on my angular2 application\'s about page. The project is based on angular-cli.

How can build be extended so git revision is put for exampl

9条回答
  •  星月不相逢
    2021-01-31 16:46

    Use gulp task using gulp-replace and git-rev-sync to add the hash and branch on build :

    1) Create the gulp task

    var gulp            =    require('gulp'),
        replace         =    require('gulp-replace'),
        git             =    require('git-rev-sync'),
    
    gulp.task('git', function () {
        gulp.src('src/index.html')
            .pipe(replace('{{git-branch}}', git.branch()))
            .pipe(replace('{{git-hash}}', git.short()))
            .pipe(gulp.dest('src/'))
    });
    
    // Build Tasks
    gulp.task('build', ['git']);
    

    2) Add the following code to index.html :

    {{git-branch}}@{{git-hash}}
    

    3) Run

    gulp build
    

提交回复
热议问题