New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

react-scripts-cssmodules

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-scripts-cssmodules

Configuration and scripts for Create React App - With CSS Modules

Source
npmnpm
Version
1.0.171
Version published
Weekly downloads
64
-17.95%
Maintainers
1
Weekly downloads
 
Created
Source

react-scripts-cssmodules

Adds CSS Modules to Create React App.

How to use

Either create a new project using create-react-app my-app --scripts-version react-scripts-cssmodules or within your existing project uninstall react-scripts and install react-scripts-cssmodules.

Using CSS and CSS Modules

To import as regular css, do the same as in CRA. import mystyles.css To import as css modules, rename the file to [name].module.css and the use as normal css modules.

Example

Button.module.css

.button {
  padding: 20px;
}

another-stylesheet.css

.button {
  color: green;
}

Button.js

import React, { Component } from 'react';
import './another-stylesheet.css'; // Import regular stylesheet
import styles from './Button.module.css'; // Import css modules stylesheet as styles

class Button extends Component {
  render() {
    // You can use them as regular CSS styles
    return <div className={styles.button} />;
  }
}

exported HTML

No clashes from other .button classnames

<div class="src__Button-module___button"></div>

Versioning

This package is 10:1 with Create React App. E.g. v0.9.10 of this package is the same as and interchanable with v0.9.1 of Create React App.

Any additional numbers are fixes for this app only. E.g. v0.9.21 is v0.9.2 of React App with a fix only for cssmodules.

See this CRA Issue for more details, or for a more indepth guide check out this article.

FAQs

Package last updated on 13 Nov 2017

Related posts