Registry / devops / webpack-modernizr-loader

webpack-modernizr-loader

JSON →
library5.0.0jsnpmunverified

A Webpack loader that bundles a custom Modernizr build into your bundle. Current stable version is 5.0.0. Release cadence is irregular; last major version 4.0.0 was released in 2018 and 5.0.0 is the latest, but no recent activity. Key differentiator: allows Modernizr feature detection to be included in a Webpack bundle without manual downloads or separate build steps. Alternatives include manual Modernizr download or other loaders like 'modernizr-webpack-plugin'.

npm install webpack-modernizr-loader
INSTALL
IMPORT
SIG · WEBPACK-MODERNIZR-
W
webpack-modernizr-loader
devopsjavascriptv5.0.0
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.

default
module.exports = { module: { rules: [{ test: /\.modernizrrc\.js$/, loader: 'webpack-modernizr-loader' }] } }
const ModernizrLoader = require('webpack-modernizr-loader');
Used as a Webpack loader, not a library to import directly. Configure in webpack.config.js rule.
require('modernizr')
const modernizr = require('modernizr');
import modernizr from 'modernizr';
Modernizr is typically required in your source code after the loader replaces the module. ES import may not work due to CommonJS output.
options
options: { 'feature-detects': ['test/css/flexbox'] }
options: { featureDetects: ['test/css/flexbox'] }
Options use the exact keys from Modernizr config-all.json (e.g. 'feature-detects' kebab-case).
useConfigFile
options: { useConfigFile: true }
options: { configFile: true }
To use a separate config file, set 'useConfigFile: true' and point alias to the file, not directly passing config.

Demonstrates configuring webpack-modernizr-loader with inline options and alias to load a custom Modernizr build.

// webpack.config.js const path = require('path'); module.exports = { module: { rules: [ { test: /\.modernizrrc\.js$/, loader: 'webpack-modernizr-loader', options: { 'feature-detects': [ 'test/css/flexbox', 'test/es6/promises', 'test/serviceworker' ] } } ] }, resolve: { alias: { modernizr$: path.resolve(__dirname, 'path/to/empty-alias-file.js') } } }; // In your source code: const modernizr = require('modernizr'); if (modernizr.flexbox) { console.log('Flexbox supported'); }
Debug
Known issues
breakingVersion 4.0.0 dropped support for Webpack 1 and 2, requires Webpack v4.
fix
Upgrade Webpack to v4 or later.
affects: >=4.0.0
breakingVersion 3.0.0 removed support for Webpack v1 and changed minimum loader-utils version.
fix
Update loader-utils to ~1.0.0 or later.
affects: >=3.0.0 <4.0.0
deprecatedThe `config` option for passing Modernizr settings directly was removed in v2.0.0. Use `useConfigFile` or inline options.
fix
Use `useConfigFile: true` or pass options in loader configuration.
affects: >=2.0.0
gotchaThe empty alias file must exist and can be a placeholder; commenting 'Please do not delete this file' is recommended.
fix
Ensure the file exists at the alias path, even if empty.
affects: *
gotchaOption keys must exactly match those in Modernizr's config-all.json (kebab-case). Using camelCase will be silently ignored.
fix
Use 'feature-detects' not 'featureDetects', 'minify' not 'minify', etc.
affects: *
Errors
Common errors & fixes
Module parse failed: Unexpected character '#' (1:0)
Loader not properly configured; webpack is trying to parse the Modernizr output as a module.
fix
Ensure the rule uses 'webpack-modernizr-loader' and the alias file exists.
Cannot find module 'modernizr'
The 'modernizr' alias is not resolved correctly.
fix
Check the alias path in webpack config: alias: { modernizr$: path.resolve(__dirname, 'path/to/file.js') }
Invalid configuration object. webpack has been initialised using a configuration object that does not match the API schema.
Webpack 4+ requires 'module.rules' format; using 'loaders' or 'module.loaders' is deprecated.
fix
Use 'module.rules' array with 'test' and 'loader' properties.
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies
modernizrrequiredPeer dependency; required to generate the Modernizr build.
webpackrequiredPeer dependency; loader is designed for Webpack 4+.
Agent activity
6 hits · last 30 days
node
6
Resources
webpack-modernizr-loader — npm install webpack-modernizr-loader · libregistry