{"id":13265,"library":"grunt-modernizr","title":"Grunt Modernizr Plugin","description":"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.","status":"active","version":"5.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/Modernizr/grunt-modernizr","tags":["javascript","gruntplugin","modernizr","customizr"],"install":[{"cmd":"npm install grunt-modernizr","lang":"bash","label":"npm"},{"cmd":"yarn add grunt-modernizr","lang":"bash","label":"yarn"},{"cmd":"pnpm add grunt-modernizr","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package is a Grunt plugin and requires Grunt to function. Grunt must be installed locally in the project and the Grunt CLI globally.","package":"grunt","optional":false}],"imports":[{"note":"Grunt plugins are loaded via `grunt.loadNpmTasks` in the `Gruntfile.js`, not imported as standard JavaScript modules.","wrong":"import GruntModernizr from 'grunt-modernizr';","symbol":"grunt.loadNpmTasks","correct":"grunt.loadNpmTasks(\"grunt-modernizr\");"},{"note":"The `modernizr` configuration object is defined directly within `grunt.initConfig` in your `Gruntfile.js`. There's no direct JavaScript import for this object itself.","symbol":"modernizr configuration object","correct":"module.exports = function(grunt) {\n  grunt.initConfig({\n    modernizr: {\n      dist: { /* ... config ... */ }\n    }\n  });\n  grunt.loadNpmTasks('grunt-modernizr');\n  grunt.registerTask('default', ['modernizr']);\n};"}],"quickstart":{"code":"npm install grunt-modernizr --save-dev\n\n# Gruntfile.js example\nmodule.exports = function(grunt) {\n  grunt.initConfig({\n    modernizr: {\n      dist: {\n        \"parseFiles\": true,\n        \"customTests\": [],\n        \"devFile\": \"./node_modules/modernizr/modernizr.js\",\n        \"dest\": \"./dist/modernizr-build.js\",\n        \"tests\": [\n          \"cssfilters\",\n          \"flexbox\",\n          \"csstransforms\",\n          \"touchevents\"\n        ],\n        \"options\": [\n          \"setClasses\",\n          \"addTest\",\n          \"html5printshiv\",\n          \"testProp\",\n          \"fnBind\"\n        ],\n        \"uglify\": true\n      }\n    }\n  });\n\n  grunt.loadNpmTasks(\"grunt-modernizr\");\n\n  grunt.registerTask(\"default\", [\"modernizr:dist\"]);\n};\n\n# To run the task:\ngrunt modernizr:dist\n# Or if 'default' task is registered:\ngrunt","lang":"javascript","description":"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`."},"warnings":[{"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.","message":"Version 5.x of `grunt-modernizr` requires Node.js version 18 or higher. Projects running on older Node.js versions will encounter errors.","severity":"breaking","affected_versions":">=5.0.0"},{"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.","message":"Major 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.","severity":"breaking","affected_versions":">=4.0.0"},{"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`.","message":"The 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.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure the plugin is installed (`npm install grunt-modernizr --save-dev`) and loaded in your `Gruntfile.js` with `grunt.loadNpmTasks(\"grunt-modernizr\");`.","cause":"The `grunt-modernizr` plugin has not been correctly installed or loaded in the Gruntfile.","error":"Warning: Task \"modernizr\" not found."},{"fix":"Install Grunt CLI globally (`npm install -g grunt-cli`) and Grunt locally in your project (`npm install grunt --save-dev`).","cause":"The core Grunt library or Grunt CLI is not properly installed or accessible in the project environment.","error":"Error: Cannot find module 'grunt'"},{"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.","cause":"Incorrect configuration of `parseFiles`, `tests` array, or `options` array in the `modernizr` task within `Gruntfile.js`, or the files are not being parsed correctly.","error":"Generated Modernizr build does not include expected feature tests."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"grunt","cli_version":null}