I’m using https://github.com/jney/grunt-htmlcompressor to compress HTML files. But it’s requiring me to manually type-in all the HTML files which I want minified:

grunt.initConfig({
  htmlcompressor: {
    compile: {
      files: {
        'dest/index.html': 'src/index.html'
      },
      options: {
        type: 'html',
        preserveServerScript: true
      }
    }
  }
});

Is there a way to specify that I want to minify all HTML files of the entire folder (and subfolders)?

Or, in case this html-compressor is limited, are you aware of a different npm package that does this HTML mification?

有帮助吗?

解决方案

The glob pattern should be allowed for any grunt task by default. Then simply use dynamic files to build each one to your dest

Instead of:

files: {
        'dest/index.html': 'src/index.html'
      },

Go with:

files: [
        {
          expand: true,     // Enable dynamic expansion.
          cwd: 'src/',      // Src matches are relative to this path.
          src: ['**/*.html'], // Actual pattern(s) to match.
          dest: 'dest/',   // Destination path prefix.
        },
      ],

As far as another plugin I would recommend grunts contrib version since it's more common and maintained by the grunt team.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top