{"id":14611,"library":"grunt-processhtml","title":"Grunt HTML Processor","description":"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.","status":"abandoned","version":"0.4.4","language":"javascript","source_language":"en","source_url":"git://github.com/dciccale/grunt-processhtml","tags":["javascript","process","html","index","build","buildtime","environment","target","optimize"],"install":[{"cmd":"npm install grunt-processhtml","lang":"bash","label":"npm"},{"cmd":"yarn add grunt-processhtml","lang":"bash","label":"yarn"},{"cmd":"pnpm add grunt-processhtml","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime peer dependency; essential for the plugin to function within a Grunt project.","package":"grunt","optional":false}],"imports":[{"note":"Grunt plugins are activated by calling `grunt.loadNpmTasks` in your Gruntfile.js, not through standard JavaScript module import or CommonJS require statements.","wrong":"import { loadNpmTasks } from 'grunt';","symbol":"loadNpmTasks","correct":"grunt.loadNpmTasks('grunt-processhtml');"},{"note":"The 'processhtml' task's behavior and file mappings are defined within the `grunt.initConfig` object, under the `processhtml` key. This is a Grunt-specific configuration pattern, not a module import.","wrong":"const processhtml = require('grunt-processhtml');","symbol":"processhtml task configuration","correct":"grunt.initConfig({ processhtml: { /* ... task target configuration ... */ } });"},{"note":"To run the 'processhtml' task, you invoke it via a Grunt task alias (e.g., 'default') or directly from the command line, referencing its configured targets (e.g., `grunt processhtml:dist`).","wrong":"processhtml.run();","symbol":"processhtml task execution","correct":"grunt.registerTask('default', ['processhtml:dist']);"}],"quickstart":{"code":"// Gruntfile.js\nmodule.exports = function(grunt) {\n  grunt.initConfig({\n    pkg: grunt.file.readJSON('package.json'),\n    processhtml: {\n      options: {\n        data: {\n          version: '<%= pkg.version %>',\n          env: grunt.option('env') || 'development'\n        }\n      },\n      dist: {\n        files: {\n          'dist/index.html': ['src/index.html']\n        }\n      },\n      dev: {\n        options: {\n          data: {\n            env: 'development'\n          }\n        },\n        files: {\n          'dev/index.html': ['src/index.html']\n        }\n      }\n    }\n  });\n\n  grunt.loadNpmTasks('grunt-processhtml');\n\n  grunt.registerTask('build', ['processhtml:dist']);\n  grunt.registerTask('serve', ['processhtml:dev']);\n  grunt.registerTask('default', ['serve']);\n};\n\n// src/index.html\n<!DOCTYPE html>\n<html>\n<head>\n    <title>My App - <!-- build:template %%= options.env %%= --></title>\n    <!-- build:css css/app.min.css -->\n    <link rel=\"stylesheet\" href=\"css/normalize.css\">\n    <link rel=\"stylesheet\" href=\"css/main.css\">\n    <!-- /build -->\n</head>\n<body>\n    <h1>Welcome to Version <!-- build:template %%= options.version %%= --></h1>\n    <!-- build:js js/app.min.js -->\n    <script src=\"js/lib.js\"></script>\n    <script src=\"js/app.js\"></script>\n    <!-- /build -->\n\n    <!-- build:remove:dist -->\n    <p>This content is for development only.</p>\n    <!-- /build -->\n\n    <!-- build:[data-env]:dev -->\n    <div data-env=\"development\">Development Environment</div>\n    <!-- /build -->\n</body>\n</html>\n","lang":"javascript","description":"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."},"warnings":[{"fix":"Avoid using this package for new projects. For existing projects, consider migrating to more modern HTML processing tools like `gulp-htmlmin`, `html-webpack-plugin`, or standalone NodeJS HTML parsing and transformation libraries.","message":"The 'grunt-processhtml' package is no longer actively maintained. Its last code commit was over 8 years ago, and the last npm publish was 2 years ago, largely for dependency updates. There will be no further bug fixes, security patches, or feature enhancements.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Strictly adhere to the documented comment syntax. Thoroughly test and validate the processed HTML output in all build environments to catch any unintended changes or errors. Consider using a linter or schema validator if available.","message":"The plugin relies heavily on a specific HTML comment syntax (<!-- build:type[:target] -->) for all its transformations. Deviations from this precise syntax, or conflicts with other HTML comments, can lead to parsing errors, unexpected output, or blocks being ignored.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"For new projects or those migrating away from Grunt, explore build tools with native HTML processing capabilities or standalone HTML parsers. If using Grunt, ensure your Gruntfile is well-maintained and that all dependencies are up-to-date (though this package itself is not).","message":"This plugin is tightly coupled with the Grunt.js task runner ecosystem. While Grunt remains functional, its usage has declined in favor of more modern build tools like Gulp, Webpack, or Vite. Integrating `grunt-processhtml` requires a full Grunt setup, potentially adding unnecessary complexity to projects not already using Grunt.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure that `grunt.loadNpmTasks('grunt-processhtml');` is present in your `Gruntfile.js` and that the task is correctly referenced in your `registerTask` calls or command-line arguments (e.g., `grunt processhtml:dist`).","cause":"The 'grunt-processhtml' plugin was not properly loaded in the `Gruntfile.js`, or the task name was misspelled when attempting to run it.","error":"Warning: Task \"processhtml\" not found. Use --force to continue."},{"fix":"Review the `<!-- build: -->` comment in your HTML file. The `type` must be one of `js`, `css`, `remove`, `template`, `include`, or an HTML attribute enclosed in brackets like `[src]` or `[href]`.","cause":"An unsupported or misspelled 'type' was used within an HTML build comment. The plugin expects specific types or attribute names.","error":"Error: Parse error on line X: <!-- build:invalid-type --> Expected build type 'js', 'css', 'remove', 'template', 'include' or attribute like '[href]'. Got 'invalid-type'."},{"fix":"For a `remove` block to be removed for a specific target (e.g., `dist`), you typically define it as `<!-- build:remove:dist -->`. This means it *will be removed when the `dist` target is active*. If you want it removed for *all but* a specific target, you might need inverse logic or multiple blocks, or configure `customBlockTypes`.","cause":"Misunderstanding the `build:type[:target]` syntax, specifically how targets interact with the `remove` type. The target in the comment refers to the *Grunt task target* that *should* process the block, not to *remove* it for that specific target by default.","error":"Grunt-processhtml remove not working when specifying a target"}],"ecosystem":"npm"}