문제

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