# postcss-modules-local-by-default

> A CSS Modules transform to make local scope the default

Latest version **4.2.0** (published 2024-12-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-modules-local-by-default
pnpm add postcss-modules-local-by-default
yarn add postcss-modules-local-by-default
bun add postcss-modules-local-by-default
```

## Health

**Score 43/100 (D)** — status: stable.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 4.2.0 |
| Published | 2024-12-11 |
| First published | 2015-05-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/postcss-modules-local-by-default) |
| Module format | CommonJS |
| Node | ^10 \|\| ^12 \|\| >= 14 |
| Dependencies | 3 |
| Unpacked size | 25.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 27 |
| Author | Mark Dalgleish |
| Maintainers | markdalgleish, sokra, geelen, evilebottnawi |
| Keywords | css-modules, postcss, css, postcss-plugin |

## Links

- npm: https://www.npmjs.com/package/postcss-modules-local-by-default
- Repository: https://github.com/css-modules/postcss-modules-local-by-default
- Homepage: https://github.com/css-modules/postcss-modules-local-by-default#readme
- Issues: https://github.com/css-modules/postcss-modules-local-by-default/issues
- npm.io page: https://npm.io/package/postcss-modules-local-by-default

## Dependencies (3)

- [icss-utils](https://npm.io/package/icss-utils.md) ^5.0.0
- [postcss-value-parser](https://npm.io/package/postcss-value-parser.md) ^4.1.0
- [postcss-selector-parser](https://npm.io/package/postcss-selector-parser.md) ^7.0.0

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 4.2.0 (latest) — 2024-12-11
- 4.0.0-rc.4 (next) — 2020-10-11
- 4.1.0 — 2024-11-11
- 4.0.5 — 2024-04-03
- 4.0.4 — 2024-01-17
- 4.0.3 — 2023-05-23
- 4.0.2 — 2023-05-22
- 4.0.1 — 2023-05-19
- 4.0.0 — 2020-10-13
- 4.0.0-rc.3 — 2020-10-08
- 4.0.0-rc.2 — 2020-10-08
- 4.0.0-rc.1 — 2020-09-22
- 4.0.0-rc.0 — 2020-09-16
- 3.0.3 — 2020-07-25
- 3.0.2 — 2019-06-04
- … 24 more at https://npm.io/package/postcss-modules-local-by-default/versions

## README

[![Build Status][ci-img]][ci] [![codecov][codecov-img]][codecov] [![npm][npm-img]][npm]

# CSS Modules: Local by Default

Transformation examples:

Selectors (mode `local`, by default)::

<!-- prettier-ignore-start -->
```css
.foo { ... } /* => */ :local(.foo) { ... }

.foo .bar { ... } /* => */ :local(.foo) :local(.bar) { ... }

/* Shorthand global selector */

:global .foo .bar { ... } /* => */ .foo .bar { ... }

.foo :global .bar { ... } /* => */ :local(.foo) .bar { ... }

/* Targeted global selector */

:global(.foo) .bar { ... } /* => */ .foo :local(.bar) { ... }

.foo:global(.bar) { ... } /* => */ :local(.foo).bar { ... }

.foo :global(.bar) .baz { ... } /* => */ :local(.foo) .bar :local(.baz) { ... }

.foo:global(.bar) .baz { ... } /* => */ :local(.foo).bar :local(.baz) { ... }
```
<!-- prettier-ignore-end -->

Declarations (mode `local`, by default):

<!-- prettier-ignore-start -->
```css
.foo {
  animation-name: fadeInOut, global(moveLeft300px), local(bounce);
}

.bar {
  animation: rotate 1s, global(spin) 3s, local(fly) 6s;
}

/* => */ 

:local(.foo) {
  animation-name: :local(fadeInOut), moveLeft300px, :local(bounce);
}

:local(.bar) {
  animation: :local(rotate) 1s, spin 3s, :local(fly) 6s;
}
```
<!-- prettier-ignore-end -->

## Pure Mode

In pure mode, all selectors must contain at least one local class or id
selector

To ignore this rule for a specific selector, add the a `/* cssmodules-pure-ignore */` comment in front
of the selector:

```css
/* cssmodules-pure-ignore */
:global(#modal-backdrop) {
  ...;
}
```

or by adding a `/* cssmodules-pure-no-check */` comment at the top of a file to disable this check for the whole file:

```css
/* cssmodules-pure-no-check */

:global(#modal-backdrop) {
  ...;
}

:global(#my-id) {
  ...;
}
```

## Building

```bash
$ npm install
$ npm test
```

- Build: [![Build Status][ci-img]][ci]
- Lines: [![coveralls][coveralls-img]][coveralls]
- Statements: [![codecov][codecov-img]][codecov]

## Development

```bash
$ yarn test:watch
```

## License

MIT

## With thanks

- [Tobias Koppers](https://github.com/sokra)
- [Glen Maddern](https://github.com/geelen)

---

Mark Dalgleish, 2015.

[ci-img]: https://github.com/css-modules/postcss-modules-local-by-default/actions/workflows/nodejs.yml/badge.svg
[ci]: https://github.com/css-modules/postcss-modules-local-by-default/actions/workflows/nodejs.yml
[npm-img]: https://img.shields.io/npm/v/postcss-modules-local-by-default.svg?style=flat-square
[npm]: https://www.npmjs.com/package/postcss-modules-local-by-default
[coveralls-img]: https://img.shields.io/coveralls/css-modules/postcss-modules-local-by-default/master.svg?style=flat-square
[coveralls]: https://coveralls.io/r/css-modules/postcss-modules-local-by-default?branch=master
[codecov-img]: https://img.shields.io/codecov/c/github/css-modules/postcss-modules-local-by-default/master.svg?style=flat-square
[codecov]: https://codecov.io/github/css-modules/postcss-modules-local-by-default?branch=master

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