Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

css-modules-require-hook

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-modules-require-hook

A require hook to compile CSS Modules on the fly

  • 4.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
247K
increased by9.29%
Maintainers
1
Weekly downloads
 
Created

What is css-modules-require-hook?

The css-modules-require-hook package is a tool that allows you to use CSS Modules in Node.js by transforming CSS files into JavaScript objects. This is particularly useful for server-side rendering (SSR) and testing environments where you need to handle CSS files in a Node.js context.

What are css-modules-require-hook's main functionalities?

Basic Setup

This feature allows you to set up the css-modules-require-hook with a custom naming pattern for the generated CSS class names. The code sample demonstrates how to configure the hook and require a CSS file, which will be transformed into a JavaScript object.

const hook = require('css-modules-require-hook');

hook({
  generateScopedName: '[name]__[local]___[hash:base64:5]'
});

const styles = require('./styles.css');
console.log(styles);

Custom Preprocessor

This feature allows you to use a custom preprocessor like Sass. The code sample shows how to configure the hook to preprocess SCSS files using node-sass before transforming them into JavaScript objects.

const hook = require('css-modules-require-hook');
const sass = require('node-sass');

hook({
  extensions: ['.scss'],
  preprocessCss: (data, filename) => {
    return sass.renderSync({
      data,
      file: filename
    }).css;
  }
});

const styles = require('./styles.scss');
console.log(styles);

Custom CamelCase

This feature enables the conversion of CSS class names to camelCase in the resulting JavaScript object. The code sample demonstrates how to configure the hook to use camelCase and access the class names in camelCase format.

const hook = require('css-modules-require-hook');

hook({
  camelCase: true
});

const styles = require('./styles.css');
console.log(styles);
console.log(styles.someClassName); // Access class names in camelCase

Other packages similar to css-modules-require-hook

Keywords

FAQs

Package last updated on 10 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc