Registry / devops / customizr

customizr

JSON →
library3.0.5jsnpmunverified

Customizr is a build tool designed to optimize Modernizr installations by automatically detecting used feature tests within a project's JavaScript and (S)CSS files and generating a custom, minified Modernizr bundle. It helps developers create lean, performant websites by eliminating unused Modernizr tests, thereby reducing asset size and improving load times. The current stable version is 3.0.5, with recent minor updates indicating active maintenance and compatibility with modern Node.js environments. It operates primarily as a command-line interface tool, offering extensive configuration options via a JSON file. Key differentiators include its intelligent crawling capabilities for automated test detection, a high degree of configurability, and seamless integration with popular build systems like Grunt and Gulp through dedicated wrapper packages. This streamlines the Modernizr optimization process, ensuring only the necessary feature detections are included in the final build.

npm install customizr
INSTALL
IMPORT
SIG · CUSTOMIZR
C
customizr
devopsjavascriptv3.0.5
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

init
✓ import { init } from 'customizr';
✗ import customizr from 'customizr';
The primary programmatic entry point is the `init` function for ESM consumption.
init
✓ const { init } = require('customizr');
✗ const customizr = require('customizr');
For CommonJS environments, the `init` function is exported as a named property.
* as Customizr
✓ import * as Customizr from 'customizr';
✗ import Customizr from 'customizr';
While less common, you can import all named exports as a namespace object in ESM. The `init` function would then be accessed via `Customizr.init`.

Demonstrates creating a configuration file for Customizr and then running it via the command line interface to generate a custom Modernizr build based on detected features in source files.

{ "cache": true, "devFile": false, // Set to your development Modernizr build file if used "dest": "./dist/modernizr-custom.js", "options": [ "addTest", "html5printshiv", "testProp" ], "uglify": true, "tests": [ "cssanimations", "csstransitions", "flexbox", "websockets" ], "excludeTests": [], "crawl": true, "files": { "src": [ "src/**/*.{js,css,scss,less}", "!src/lib/**/*" ] }, "customTests": [], "classPrefix": "" } // 1. Save the above JSON as customizr.config.json // 2. Create some files in `src/` that use Modernizr tests, e.g.: // src/app.js: // if (Modernizr.flexbox) { console.log('Flexbox supported'); } // else { console.log('No flexbox'); } // src/style.css: // .flexbox { display: flex; } // .no-flexbox { /* fallback styles */ } // 3. Run Customizr via CLI: // npx customizr -c customizr.config.json // This will generate `./dist/modernizr-custom.js` with only the detected tests.
customizr --version
Debug
Known issues
breakingCustomizr v3.0.0 and above requires Node.js version 18 or higher. Projects running on older Node.js environments must upgrade their Node.js version or remain on a Customizr v2.x release.
fix
Upgrade your Node.js installation to version 18 or newer using a version manager like nvm (e.g., `nvm install 18 && nvm use 18`).
affects: >=3.0.0
gotchaWhen crawling CSS/SCSS/LESS files, Customizr looks for Modernizr's generated class names (e.g., `.flexbox`, `.no-flexbox`) in selectors, not for actual CSS properties (e.g., `display: flex`). Ensure your CSS follows this pattern for proper detection.
fix
Use Modernizr's generated CSS classes (e.g., `.flexbox`, `.no-flexbox`) in your stylesheets to correctly trigger detection by Customizr's crawler.
affects: >=1.0.0
gotchaIf `crawl` is enabled, specifying a `devFile` in your configuration is crucial. Omitting `devFile` can lead to false positives, as Customizr might crawl your full development Modernizr build, resulting in an overly inclusive custom build.
fix
Set the `devFile` option in your configuration to the path of your development Modernizr file, or ensure `crawl` is set to `false` if you are manually defining `tests`.
affects: >=1.0.0
gotchaUse the `excludeTests` option to prevent unintended inclusions. For example, if you have a CSS class named `.notification` that is unrelated to the Modernizr Notification API test, `excludeTests: ['notification']` will prevent its inclusion.
fix
Add the specific test name to the `excludeTests` array in your configuration to explicitly ignore it during the crawling process.
affects: >=1.0.0
gotchaThe `cache` option (defaulting to `true`) avoids rebuilding Modernizr if criteria are met. While beneficial for performance, unexpected changes in source files not tracked by the caching mechanism might lead to outdated builds. If in doubt, run with `--force` flag.
fix
To force a rebuild and ignore the cache, use the `--force` command-line option (`npx customizr -c customizr.config.json --force`) or set `cache: false` in your config temporarily.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Config file not found at path/to/config.json
The command-line interface was invoked with a `--config` flag pointing to a non-existent or inaccessible JSON configuration file.
fix
Ensure the path provided with the `-c` or `--config` flag is correct and the file exists, e.g., `npx customizr -c ./customizr.config.json`.
ReferenceError: Modernizr is not defined
The generated Modernizr file was not correctly included in the HTML document, or it was included after scripts that attempt to use `Modernizr`.
fix
Include the custom-built Modernizr JavaScript file in your HTML using a `<script>` tag, ensuring it loads before any scripts that depend on the `Modernizr` global object.
Node.js vX.Y.Z is not supported. Please use Node.js >=18.
The installed Node.js version is older than the minimum requirement specified by Customizr (v3.x requires Node.js >=18).
fix
Update your Node.js environment to version 18 or newer. Tools like `nvm` (Node Version Manager) can help switch versions easily: `nvm install 18 && nvm use 18`.
Error: 'devFile' must be specified when 'crawl' is true to prevent false positives.
When Customizr is configured to crawl project files (`crawl: true`), it requires a `devFile` path to exclude the full Modernizr development build from its crawling process, preventing an over-inclusive final build.
fix
Provide a path to your development Modernizr file in the `devFile` option within your configuration (e.g., `"devFile": "./node_modules/modernizr/modernizr.js"`), or set `crawl: false` if you intend to manually specify all `tests`.
Upgrade
Version history
3.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
4
Resources
customizr — npm install customizr · libregistry