how to prevent usemin from overwriting original index.html file

294 views Asked by At

I'm using usemin and I generally like it, but I really dislike the fact that usemin overwrites my original index.html file. I have a pretty typical setup in my Gruntfile:

useminPrepare: {
  html: '<%= yeoman.app %>/index.html',
  options: {
    root: '<%= yeoman.root %>',
    staging: '<%= yeoman.tmp %>',
    dest: '<%= yeoman.dist %>',
    flow: {
      html: {
        steps: {
          js: ['concat', 'uglifyjs'],
          css: ['cssmin']
        },
        post: {}
      }
    }
  }
},

Whenever I build using grunt everything in the end gets dumped into a dist directory. Most other tasks that need to do 'temporary' modifications copy and modify files in a .tmp directory.

usemin mucks with the actual index.html file though. I particularly don't like this because it makes Github think the file has changed every time I check in new code.

Is there a way to tell usemin to use the .tmp directory like most other grunt plugins?

I do specify my temp directory with:

staging: '<%= yeoman.tmp %>'

but that doesn't seem to prevent the index.html file from being overwritten.

Thanks.

UPDATE (per the comment below)

Here is the usemin task itself:

// Performs rewrites based on filerev and the useminPrepare configuration
usemin: {
  html: ['<%= yeoman.dist %>/{,*/}*.html'],
  css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
  options: {
    assetsDirs: ['<%= yeoman.dist %>','<%= yeoman.dist %>/images']
  }
},

and here is the grunt task that uses both useminPrepare and usemin:

grunt.registerTask('build', [
  'clean:dist',
  'wiredep',
  'useminPrepare',
  'concurrent:dist',
  'autoprefixer',
  'concat',
  'ngAnnotate',
  'copy:dist',
  'cdnify',
  'cssmin',
  'uglify',
  'filerev',
  'usemin',
  'htmlmin',
  'bridge:dist'
]);
1

There are 1 answers

2
plrthink On

just do not perform filerev task. This is the task that modify the original html files.