Grunt HTML Processor

0.4.4 · abandoned · verified Sun Apr 19

grunt-processhtml is a Grunt plugin designed for modifying HTML files during the build process, adapting their content based on the target release environment. It operates by interpreting special `<!-- build:type[:target] -->...<!-- /build -->` comments within HTML files. These directives allow for operations such as concatenating and replacing script or stylesheet tags with a single optimized file, inlining JavaScript or CSS directly into the HTML, removing specific blocks of content for certain environments, or modifying HTML attributes like `src` or `href`. The current stable version is `0.4.4`, last published 2 years ago, but the latest commit was 8 years ago, and the project is considered effectively abandoned, having seen no significant updates since its last release. Its primary differentiator is its integration with the Grunt task runner and its comment-driven approach to build-time HTML manipulation, but it lacks modern tooling support and is tied to an older ecosystem. While functional for its intended purpose within older Grunt-based workflows, it is not recommended for new projects.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates `grunt-processhtml` configuration in a `Gruntfile.js` for `dist` and `dev` targets. It shows how to use special HTML comments for concatenating CSS/JS, templating dynamic values (like version and environment), removing development-specific blocks, and modifying attributes based on the build target.

// Gruntfile.js
module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    processhtml: {
      options: {
        data: {
          version: '<%= pkg.version %>',
          env: grunt.option('env') || 'development'
        }
      },
      dist: {
        files: {
          'dist/index.html': ['src/index.html']
        }
      },
      dev: {
        options: {
          data: {
            env: 'development'
          }
        },
        files: {
          'dev/index.html': ['src/index.html']
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-processhtml');

  grunt.registerTask('build', ['processhtml:dist']);
  grunt.registerTask('serve', ['processhtml:dev']);
  grunt.registerTask('default', ['serve']);
};

// src/index.html
<!DOCTYPE html>
<html>
<head>
    <title>My App - <!-- build:template %%= options.env %%= --></title>
    <!-- build:css css/app.min.css -->
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/main.css">
    <!-- /build -->
</head>
<body>
    <h1>Welcome to Version <!-- build:template %%= options.version %%= --></h1>
    <!-- build:js js/app.min.js -->
    <script src="js/lib.js"></script>
    <script src="js/app.js"></script>
    <!-- /build -->

    <!-- build:remove:dist -->
    <p>This content is for development only.</p>
    <!-- /build -->

    <!-- build:[data-env]:dev -->
    <div data-env="development">Development Environment</div>
    <!-- /build -->
</body>
</html>

view raw JSON →