ignore-styles is a utility that provides a Node.js `require` hook to prevent style and asset imports (like CSS, SASS, images, videos) from causing `SyntaxError` crashes when running JavaScript code directly in Node.js, typically during testing environments (e.g., Mocha) that don't process these file types. It is currently at version 5.0.1 and primarily sees updates to extend the list of default ignored file extensions, with major version increments reflecting these additions. A key differentiator is its specific purpose for Node.js execution *outside* of a Webpack build process, contrasting with Webpack-specific loaders like `ignore-loader`. It offers flexibility through a customizable list of file extensions to ignore and an optional custom handler function for more advanced scenarios, such as returning mock data for `react-css-modules`.
npm install ignore-stylesVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and register `ignore-styles` with a custom list of extensions and a handler function to mock image and style imports for Node.js environments.
Ensure `ignore-styles` is only used in Node.js runtime environments outside of your build process. For Webpack, consider `ignore-loader` or `null-loader`.
Use `require('ignore-styles').default([extensions], handler)` for customization in CommonJS.Review the release notes for each major version update to understand any new default extensions. If specific control is needed, explicitly pass your desired array of extensions to the `register` function.
Ensure `ignore-styles` is loaded before your application code, typically via `mocha --require ignore-styles` or `node -r ignore-styles your-script.js`.
Change `require('ignore-styles')([extensions]);` to `require('ignore-styles').default([extensions]);`No dependency data recorded yet.