grunt-modernizr is a Grunt.js plugin that automates the process of generating highly customized and optimized Modernizr builds. It functions by crawling a project's JavaScript and CSS files for references to Modernizr feature tests, then dynamically creating a minified Modernizr script that includes only the detected tests. The package is currently at stable version 5.0.3 and is actively maintained, with recent updates ensuring compatibility with newer Node.js versions. Its release cadence involves periodic major version bumps, indicating significant updates rather than daily changes. A key differentiator is its seamless integration into a Grunt build pipeline, eliminating the need for manual Modernizr configuration via the web interface and ensuring that the final build is lean, containing only the necessary feature detections to improve load times and overall application performance. It wraps the core `customizr` logic to achieve its build optimization.
npm install grunt-modernizrVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to install `grunt-modernizr`, configure a basic `Gruntfile.js` to automatically detect Modernizr tests from your project files, and then execute the task to generate a custom, minified Modernizr build. It includes essential configuration options like `parseFiles`, `dest`, and `uglify`.
Upgrade your Node.js environment to version 18 or later. Alternatively, for older Node.js versions, consider using `grunt-modernizr` version 4.x or earlier.
Consult the `customizr` repository's documentation (linked in `grunt-modernizr`'s README) for specific configuration changes between versions. Review your `Gruntfile.js` `modernizr` task configuration against the latest examples.
Always refer to the `customizr` GitHub repository (https://github.com/Modernizr/customizr#config-file) for a comprehensive list of all available settings and their usage when configuring the `modernizr` task in your `Gruntfile.js`.
Ensure the plugin is installed (`npm install grunt-modernizr --save-dev`) and loaded in your `Gruntfile.js` with `grunt.loadNpmTasks("grunt-modernizr");`.Install Grunt CLI globally (`npm install -g grunt-cli`) and Grunt locally in your project (`npm install grunt --save-dev`).
Verify that `parseFiles` is set to `true` if you want automatic detection. Explicitly list desired tests in the `tests` array. Ensure the `options` array includes necessary build options (e.g., `setClasses`). Double-check file paths and patterns being parsed.