Registry / devops / grunt-modernizr

grunt-modernizr

JSON →
library5.0.3jsnpmunverified

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-modernizr
INSTALL
IMPORT
SIG · GRUNT-MODERNIZR
G
grunt-modernizr
devopsjavascriptv5.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

grunt.loadNpmTasks
grunt.loadNpmTasks("grunt-modernizr");
import GruntModernizr from 'grunt-modernizr';
Grunt plugins are loaded via `grunt.loadNpmTasks` in the `Gruntfile.js`, not imported as standard JavaScript modules.
modernizr configuration object
module.exports = function(grunt) { grunt.initConfig({ modernizr: { dist: { /* ... config ... */ } } }); grunt.loadNpmTasks('grunt-modernizr'); grunt.registerTask('default', ['modernizr']); };
The `modernizr` configuration object is defined directly within `grunt.initConfig` in your `Gruntfile.js`. There's no direct JavaScript import for this object itself.

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`.

npm install grunt-modernizr --save-dev # Gruntfile.js example module.exports = function(grunt) { grunt.initConfig({ modernizr: { dist: { "parseFiles": true, "customTests": [], "devFile": "./node_modules/modernizr/modernizr.js", "dest": "./dist/modernizr-build.js", "tests": [ "cssfilters", "flexbox", "csstransforms", "touchevents" ], "options": [ "setClasses", "addTest", "html5printshiv", "testProp", "fnBind" ], "uglify": true } } }); grunt.loadNpmTasks("grunt-modernizr"); grunt.registerTask("default", ["modernizr:dist"]); }; # To run the task: grunt modernizr:dist # Or if 'default' task is registered: grunt
grunt --version
Debug
Known issues
breakingVersion 5.x of `grunt-modernizr` requires Node.js version 18 or higher. Projects running on older Node.js versions will encounter errors.
fix
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.
affects: >=5.0.0
breakingMajor version updates (e.g., from 3.x to 4.x, or 4.x to 5.x) often introduce breaking changes to the configuration options, which are largely dictated by the underlying `customizr` library. The `Gruntfile.js` configuration may require adjustments.
fix
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.
affects: >=4.0.0
gotchaThe full set of configurable options and their valid values for `grunt-modernizr` are documented within the `customizr` repository, not directly in `grunt-modernizr`'s README. Developers might miss advanced configuration options or encounter unexpected behavior if relying solely on this plugin's documentation.
fix
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`.
affects: >=3.0.0
Errors
Common errors & fixes
Warning: Task "modernizr" not found.
The `grunt-modernizr` plugin has not been correctly installed or loaded in the Gruntfile.
fix
Ensure the plugin is installed (`npm install grunt-modernizr --save-dev`) and loaded in your `Gruntfile.js` with `grunt.loadNpmTasks("grunt-modernizr");`.
Error: Cannot find module 'grunt'
The core Grunt library or Grunt CLI is not properly installed or accessible in the project environment.
fix
Install Grunt CLI globally (`npm install -g grunt-cli`) and Grunt locally in your project (`npm install grunt --save-dev`).
Generated Modernizr build does not include expected feature tests.
Incorrect configuration of `parseFiles`, `tests` array, or `options` array in the `modernizr` task within `Gruntfile.js`, or the files are not being parsed correctly.
fix
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.
Upgrade
Version history
5.0.3latest on npm
Audit
Dependencies
gruntrequiredThis package is a Grunt plugin and requires Grunt to function. Grunt must be installed locally in the project and the Grunt CLI globally.
Agent activity
4 hits · last 30 days
node
4
Resources
grunt-modernizr — npm install grunt-modernizr · libregistry