# classnames-loader

> Webpack loader to automatically bind css-modules to classnames

Latest version **2.1.0** (published 2019-03-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install classnames-loader
pnpm add classnames-loader
yarn add classnames-loader
bun add classnames-loader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2019-03-21 |
| First published | 2015-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 114 |
| Author | Anton Petrov |
| Maintainers | itsmepetrov |
| Keywords | webpack, loader, css, modules, css-modules, classnames, styles, react, bind |

## Links

- npm: https://www.npmjs.com/package/classnames-loader
- Repository: https://github.com/itsmepetrov/classnames-loader
- Homepage: https://github.com/itsmepetrov/classnames-loader#readme
- Issues: https://github.com/itsmepetrov/classnames-loader/issues
- npm.io page: https://npm.io/package/classnames-loader

## Dependencies (1)

- [loader-utils](https://npm.io/package/loader-utils.md) ^0.2.11

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2019-03-21
- 2.0.0 — 2016-07-16
- 1.0.0 — 2015-11-19

## README

# classnames-loader

[![npm version](https://img.shields.io/npm/v/classnames-loader.svg?style=flat-square)](https://www.npmjs.com/package/classnames-loader)

This is a webpack loader that automatically bind [css-modules](https://github.com/css-modules/css-modules) to [classnames](https://github.com/JedWatson/classnames).

If you are using css-modules, or a similar approach to abstract class "names" and the real `className` values that are actually output to the DOM, you may want to use the [bind](https://github.com/JedWatson/classnames#alternate-bind-version-for-css-modules) variant of classnames module.

Check out [this example](https://gist.github.com/itsmepetrov/7dbe519bb1332dd0f6c9) that shows the difference between `classNames`, `classNames/bind` and `classnames-loader`

### Installation

```
npm install --save-dev classnames-loader
```

## Usage

To enable this loader add `classnames` before `style` loader in webpack config: 

```js
{
  test: /\.css$/,
  loader: 'classnames!style!css')
}
```

If you're using `ExtractTextPlugin` your webpack config should look like this:

```js
{
  test: /\.css$/,
  loaders: ['classnames', ExtractTextPlugin.extract('style', 'css')])
}
```

Example usage in component:

```js
import { Component } from 'react';
import cx from './submit-button.css';

export default class SubmitButton extends Component {
  render () {
    let text = this.props.store.submissionInProgress ? 'Processing...' : 'Submit';
    let className = cx({
      base: true,
      inProgress: this.props.store.submissionInProgress,
      error: this.props.store.errorOccurred,
      disabled: !this.props.form.valid,
    });
    return <button className={className}>{text}</button>;
  } 
}
```

You can also access the class names just as you would do that with [css-modules](https://github.com/css-modules/css-modules):

```js
import { Component } from 'react';
import styles from './submit-button.css';

export default class SubmitButton extends Component {
  render () {
    let text = this.props.store.submissionInProgress ? 'Processing...' : 'Submit';
    return <button className={styles.submitButton}>{text}</button>;
  } 
}
```

## Thanks

[@JedWatson](https://github.com/JedWatson) for [classnames](https://github.com/JedWatson/classnames) module

## License

[MIT](LICENSE.md)

---
_Source: https://npm.io/package/classnames-loader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
