Javascript 让Grunt使用最小HTML任务创建新文件,而不是重写

Javascript 让Grunt使用最小HTML任务创建新文件,而不是重写,javascript,gruntjs,yeoman,grunt-usemin,Javascript,Gruntjs,Yeoman,Grunt Usemin,我有一个简单的Gruntfile,使用usemin和一个来自Yeoman生成器的基本默认配置。我需要能够创建一个新的html文件,而不是重写html文件。这正是我所希望的: useminPrepare: { html: 'index.tpl', options: { dest: '.', flow: { html: { steps: { js: ['concat', 'uglifyjs'], css: [

我有一个简单的Gruntfile,使用usemin和一个来自Yeoman生成器的基本默认配置。我需要能够创建一个新的html文件,而不是重写html文件。这正是我所希望的:

useminPrepare: {
  html: 'index.tpl',
  options: {
    dest: '.',
    flow: {
      html: {
        steps: {
          js: ['concat', 'uglifyjs'],
          css: ['cssmin']
        },
        post: {}
      }
    }
  }
},

usemin: {
  html: {
    src: 'index.tpl',
    dest: 'index.html'
  }
}
这样的事情可能吗?

这还不可能。 实际上,唯一的方法是使用grunt contrib副本(或这样的插件)复制index.html文件,然后使用usemin任务更改的副本

以下是此解决方案的一个示例: (摘自mvolkmann的帖子,网址为)

module.exports = function (grunt) {
  grunt.initConfig({
    clean: ['build'],
    copy: {
      html: { // in preparation for usemin
        files: [
          {src: 'index.html', dest: 'build/'}
        ]
      }
    }, 
    uglify: {
      all: {
        files: {
          'build/output.min.js': ['lib/angular.min.js', 'scripts/*.js']
        }
      }
    },
    useminPrepare: {
      options: {dest: 'build'}
    },
    usemin: {
      html: 'build/index.html', // must have this
      //css: '*.css',
      options: {
        dirs: ['lib', 'scripts']
      }
    },
  });

  var tasks = [
    'grunt-contrib-clean',
    'grunt-contrib-copy',
    'grunt-contrib-cssmin',
    'grunt-contrib-uglify',
    'grunt-usemin'
  ];
  tasks.forEach(grunt.loadNpmTasks);

  grunt.registerTask('min', ['copy', 'useminPrepare', 'uglify', 'usemin']);
};