# babel-plugin-style-guard

> Guard CSS modules against potentially missing styles in dev mode

Latest version **0.1.1** (published 2021-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-style-guard
pnpm add babel-plugin-style-guard
yarn add babel-plugin-style-guard
bun add babel-plugin-style-guard
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2021-01-08 |
| First published | 2021-01-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 13.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | David Wells |
| Maintainers | davidwells |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-style-guard
- npm.io page: https://npm.io/package/babel-plugin-style-guard

## Dependencies (3)

- [logical-not](https://npm.io/package/logical-not.md) ^1.0.7
- [style-guard](https://npm.io/package/style-guard.md) ^0.1.1
- [@babel/template](https://npm.io/package/@babel/template.md) ^7.12.7

## Recent versions

- 0.1.1 (latest) — 2021-01-08
- 0.0.4 — 2021-01-03

## README

# Style Guard Babel Plugin

Use proxies in dev to guard against potentially missing styles for CSS modules.

## Install

```
npm install babel-plugin-style-guard -D
```

To use, add to your babel config

```
{
  plugins: [
    'babel-plugin-style-guard',
  ],
}
```

After adding to babel config, all CSS modules will be automatically wrapped with [style guard](https://www.npmjs.com/package/style-guard) in DEV mode.

## Example

In:

```js
import React from 'react'
import styles from './styles.css'

export default function NavBar(props) {
  const { auth, handleLogout } = props
  return (
    <div className={styles.thing}>
      <span className={styles.doesNotExist}>
        xyz
      </span>
    </div>
  )
}
```

Out:

```js
import React from 'react'
import __styles from './styles.css'
import styleGuard from 'style-guard'

// Automatically gaurd styles in dev mode
const styles = styleGuard(__styles)
// styles is now proxied object in dev to throw if unknown properties are called

export default function NavBar(props) {
  const { auth, handleLogout } = props
  return (
    <div className={styles.thing}>
      <span className={styles.doesNotExist}>
        xyz
      </span>
    </div>
  )
}

/*
  styles.doesNotExist will cause a dev error because its missing or has been removed!
*/
```

Now unknown class names will throw errors in dev mode.

Resulting in an error like so:

![image](https://user-images.githubusercontent.com/532272/103469934-54af5100-4d20-11eb-99d8-144a1065cf14.png)

This will help prevent style regressions in dev mode

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