patrickkettner / grunt-compile-handlebars

grunt plugin to compile static html from a handlebars plugin
MIT License
115 stars 29 forks source link

seems to append to dest rather than writing to it #66

Closed jayenashar closed 8 years ago

jayenashar commented 8 years ago

Gruntfile.js:

    'compile-handlebars': {
        front: {
            files: [{
                src: 'src/main/templates/front/index.hbs',
                dest: 'src/main/webapp/index.html'
            }],
            templateData: {},
            partials: 'target/main/templates/front/*.hbs'
        },

not sure why this appends to src/main/webapp/index.html instead of writing it it...

anamartinez commented 8 years ago

See https://github.com/patrickkettner/grunt-compile-handlebars/issues/56

This is the behavior because you may have multiple files that are being appended to during the run. In addition, If you want to remove files between runs, I suggest grunt-contrib-clean

Once you install it ( npm install grunt-contrib-clean --save-dev), you should add the task to your Gruntfile.js. This is how mine looks like:

module.exports = function(grunt) {
  grunt.initConfig({
    clean: {
      folder: ['src/*'],
     },
    'compile-handlebars': {
      index: {
        files: [{
          src: 'handlebars/index.handlebars',
          dest: 'src/index.html'
        }],
        partials: 'handlebars/partials/*.handlebars',
        templateData: {}
      }
    }
  });

  grunt.registerTask('default', ['clean', 'compile-handlebars']);
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-compile-handlebars');
};

After that, running the default task will delete the files in the directory before compiling them again.

jayenashar commented 8 years ago

thanks for that. seems inconsistent with plugins like uglify which concatenate src and write the file once. i just patched the plugin to never append.

jkytomaki commented 8 years ago

I agree with jayenashar. Could there be an option for overwriting instead of appending?

akinnee-gl commented 8 years ago

+1

navFooh commented 8 years ago

+1

andyexeter commented 8 years ago

Agree with @jayenashar - This is the only Grunt plugin I've used which appends to destination files like this.

patrickkettner commented 8 years ago

as mentioned in #54

This is the behavior because you may have multiple files that are being appended to during the run. In addition, If you want to remove files between runs, I suggest grunt-contrib-clean