Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top