# postcss-elm-modules

> Transpile CSS modules to Elm.

Latest version **0.6.0** (published 2017-07-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-elm-modules
pnpm add postcss-elm-modules
yarn add postcss-elm-modules
bun add postcss-elm-modules
```

## 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.6.0 |
| Published | 2017-07-05 |
| First published | 2017-07-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Zach Green |
| Maintainers | zgreen |
| Keywords | postcss-plugin, postcss plugin, postcss, elm, elmlang, css modules |

## Links

- npm: https://www.npmjs.com/package/postcss-elm-modules
- Repository: https://github.com/zgreen/postcss-elm-modules
- Homepage: https://github.com/zgreen/postcss-elm-modules#readme
- Issues: https://github.com/zgreen/postcss-elm-modules/issues
- npm.io page: https://npm.io/package/postcss-elm-modules

## Dependencies (4)

- [chalk](https://npm.io/package/chalk.md) ^2.0.1
- [postcss](https://npm.io/package/postcss.md) ^6.0.4
- [generic-names](https://npm.io/package/generic-names.md) ^1.0.2
- [postcss-icss-selectors](https://npm.io/package/postcss-icss-selectors.md) ^2.0.3

## Recent versions

- 0.6.0 (latest) — 2017-07-05
- 0.5.1 — 2017-07-05
- 0.5.0 — 2017-07-05
- 0.4.0 — 2017-07-05
- 0.3.0 — 2017-07-04
- 0.2.0 — 2017-07-03
- 0.1.0 — 2017-07-03

## README

# PostCSS Elm Modules

![Travis build status](https://travis-ci.org/zgreen/postcss-elm-modules.svg?branch=master)

Transpile [CSS modules](https://github.com/css-modules/css-modules) to [Elm](http://elm-lang.org/).

## Install
```bash
npm install --save-dev postcss-elm-modules
```
or
```bash
yarn add -D postcss-elm-modules
```

## What does this plugin do?
This plugin creates valid Elm modules from CSS modules.

For example, consider the following CSS module:

### `example.css`
```css
.foo {
  color: tomato
}

.bar {
  color: gold
}
```

This plugin will then create an Elm module based on `example.css`, containing a record of the selectors and their locally-scoped versions:

### `Styles.elm`

```elm
-- Elm CSS Module, generated by postcss-elm-modules
module Styles exposing (styles)


styles =
    { foo = "file__foo---2-9NY"
    , bar = "file__bar---7FSOM"
    }
```

You can then use these selectors much as you would when using CSS modules in JavaScript:

### `Main.elm`

```elm
module Main exposing (..)

import Html exposing (..)
import Html.Attributes exposing (..)
import Styles exposing (styles)

main =
    h1 [ class (styles.foo ++ " " ++ styles.bar) ] [ text "Hello, World." ]
```

## Plugin arguments

This plugin takes a single object as an argument, with the following valid properties:

### `cssModules: Object<bool, string>`

- `cssModules.enabled: bool` Enable CSS modules. Default `true`.
- `cssModules.scopePattern: string` The scoping pattern to use. Default `'[name]__[local]---[hash:base64:5]'`.

### `dir: string`

Directory where the Elm module will be written. Default `''`.

### `log: bool`

Log the output to console. Default `true`.

### `moduleName: string`

The name of the Elm module to write. Default `'styles'`.

#### Example PostCSS config

```js
module.exports = {
  plugins: [require('postcss-elm-modules')({
    cssModules: {
      enabled: true,
      scopePattern: '[name]__[local]---[hash:base64:5]'
    },
    dir: '',
    log: true,
    moduleName: 'styles'
  })]
}
```

## atRule arguments

You may optionally set the `moduleName` and `dir` inline, using an atRule. For example:

```css
@elmModule Foo src;
.foo {
  color: tomato
}

.bar {
  color: gold
}
```

This will write an Elm module `Foo.elm` at directory `src/`.

## Try it out.

An example is available in this repo. Use the command `yarn example` or `npm run example` to try it out.

## Justification

If you prefer authoring your styles in CSS rather than in Elm, and if you prefer the scoped selector approach offered by CSS Modules, consider giving this plugin a try.

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