Registry / devops / modernizr-loader

modernizr-loader

JSON →
library1.0.1jsnpmunverified

A webpack loader that enables importing custom Modernizr builds as modules. Version 1.0.1 requires modernizr ^3.1.0 as a peer dependency. Maintained by peerigon. Unlike manual builds, this integrates seamlessly with webpack's module system, allowing feature detection to be bundled conditionally. The loader reads a .modernizrrc (JSON or JS) configuration file. Breaking change in 1.0.0: Modernizr is no longer attached to window; must import as a module. Supports webpack 1 and 2, but webpack 1 requires json-loader for JSON configs.

npm install modernizr-loader
INSTALL
IMPORT
SIG · MODERNIZR-LOADER
M
modernizr-loader
devopsjavascriptv1.0.1
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.

modernizr module (default import)
import Modernizr from 'modernizr';
const Modernizr = require('modernizr');
With webpack, the alias resolves to your custom build. Use ESM import for tree-shaking.
.modernizrrc config file
// .modernizrrc (JSON or JS) with feature-detects and options
// Using a file named .modernizrrc.yml or without proper loader config
File must be named .modernizrrc (with optional .json or .js extension) and in the project root or aliased.
webpack alias for modernizr
resolve: { alias: { modernizr$: path.resolve(__dirname, 'path/to/.modernizrrc') } }
resolve: { alias: { modernizr: path.resolve(__dirname, '.modernizrrc') } }
Must include the $ for exact match; otherwise imports like 'modernizr/...' also match.

Shows setup of .modernizrrc config, webpack loader rules for JS and JSON configs, alias, and usage in app.

// .modernizrrc { "minify": true, "options": ["setClasses"], "feature-detects": ["test/svg", "test/promises"] } // webpack.config.js const path = require('path'); module.exports = { module: { loaders: [ { test: /\.modernizrrc\.js$/, loader: "modernizr" }, { test: /\.modernizrrc(\.json)?$/, loader: "modernizr!json" } ] }, resolve: { alias: { modernizr$: path.resolve(__dirname, ".modernizrrc") } } }; // app.js import Modernizr from 'modernizr'; if (!Modernizr.svg) { // fallback }
Debug
Known issues
breakingModernizr is no longer attached to window. Must import as a module.
fix
Change from using window.Modernizr to import Modernizr from 'modernizr'.
affects: >=1.0.0
gotchaJSON configuration files require json-loader in webpack 1.
fix
Add 'modernizr!json' loader chain for .modernizrrc(.json)? files, or switch to JS config with .modernizrrc.js.
affects: >=1.0.0 <2.0.0
deprecatedThe 'options' field in config is deprecated? Check Modernizr docs. Some options may not be supported.
fix
Refer to Modernizr's config-all.json for supported options and feature-detects.
affects: >=1.0.0
gotchaAlias must end with $ to avoid matching other packages starting with 'modernizr'.
fix
Use 'modernizr$' in alias key.
affects: >=1.0.0
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'modernizr'
Missing alias or incorrect alias path in webpack config.
fix
Add resolve.alias.modernizr$ pointing to your .modernizrrc file.
You may need an appropriate loader to handle this file type.
Missing loader rule for .modernizrrc files.
fix
Add loader rules for .modernizrrc(.js)? and .modernizrrc(.json)? as shown in quickstart.
Cannot find module 'modernizr'
modernizr npm package not installed.
fix
Run npm install --save-dev modernizr
Unexpected token . in JSON at position 0
.modernizrrc is a JavaScript file but using JSON loader without handling JS.
fix
Rename to .modernizrrc.js and use loader: 'modernizr' (no json). Or for JSON, keep .modernizrrc.json and use 'modernizr!json' loader.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
modernizrrequiredRequired to generate Modernizr build from configuration. Must be installed as a peer dependency.
Agent activity
2 hits · last 30 days
node
2
Resources
modernizr-loader — npm install modernizr-loader · libregistry