# csswring

> A CSS minifier for PostCSS

Latest version **7.0.0** (published 2018-07-17) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install csswring
pnpm add csswring
yarn add csswring
bun add csswring
```

Provides the command `csswring`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 7.0.0 |
| Published | 2018-07-17 |
| First published | 2014-02-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 40 KB |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 152 |
| Author | Kyo Nagashima |
| Maintainers | hail2u |
| Keywords | css, minification, postcss-plugin |

## Links

- npm: https://www.npmjs.com/package/csswring
- Repository: https://github.com/hail2u/node-csswring
- Issues: https://github.com/hail2u/node-csswring/issues
- npm.io page: https://npm.io/package/csswring

## Dependencies (3)

- [postcss](https://npm.io/package/postcss.md) ^7.0.0
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [onecolor](https://npm.io/package/onecolor.md) ^3.0.5

## 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

- 7.0.0 (latest) — 2018-07-17
- 6.0.3 — 2018-02-13
- 6.0.2 — 2017-11-19
- 6.0.1 — 2017-08-21
- 6.0.0 — 2017-05-07
- 5.1.1 — 2016-12-21
- 5.1.0 — 2016-06-28
- 5.0.0 — 2016-05-07
- 4.2.3 — 2016-05-02
- 4.2.2 — 2016-03-16
- 4.2.1 — 2016-01-18
- 4.1.1 — 2015-12-05
- 4.0.0 — 2015-08-31
- 3.0.7 — 2015-08-24
- 3.0.5 — 2015-05-14
- … 26 more at https://npm.io/package/csswring/versions

## README

CSSWring
========

A CSS minifier for PostCSS


SYNOPSIS
--------

For readability, almost all CSS file contains a lot of white spaces, extra
semicolon, etc.:

    .foo {
      width: 100px;
    }
    
    .bar {
      margin-top: 0px;
    }
    
    .baz {
      color: rgb(255, 0, 0);
      background-color: rgb(36, 36, 36);
    }

This PostCSS plugin removes and converts these non-essential parts of CSS file,
like this:

    .foo{width:100px}.bar{margin-top:0}.baz{color:red;background-color:#242424}


INSTALL
-------

    $ npm install csswring


USAGE
-----

Of course, this package can be used as PostCSS plugin:

    "use strict";
    
    var fs = require("fs");
    var postcss = require("postcss");
    
    var css = fs.readFileSync("test.css", "utf8");
    postcss([
      require("autoprefixer")(),
      require("csswring")()
    ]).process(css).then(function (result) {
      fs.writeFileSync("test.min.css", result.css);
    });


### As standard Node.js package

To minify `test.css` to `test.min.css`:

    #!/usr/bin/env node
    
    "use strict";
    
    var fs = require("fs");
    var csswring = require("csswring");
    
    var css = fs.readFileSync("test.css", "utf8");
    fs.writeFileSync("test.min.css", csswring.wring(css).css);


## As CLI Program

This package also installs a command line interface.

    $ node ./node_modules/.bin/csswring --help
    Usage: csswring [options] INPUT [OUTPUT]
    
    Description:
      Minify CSS using PostCSS
    
    Options:
          --sourcemap            Create source map file.
          --preserve-hacks       Preserve some CSS hacks.
          --remove-all-comments  Remove all comments.
      -h, --help                 Show this message.
          --version              Print version information.
    
    Use a single dash for INPUT to read CSS from standard input.
    
    Examples:
      $ csswring foo.css
      $ csswring foo.css > foo.min.css
      $ cat foo.css bar.css baz.css | csswring - > fbb.min.css

When PostCSS failed to parse INPUT, CLI shows a CSS parse error in GNU error
format instead of Node.js stack trace.


MINIFICATIONS
-------------

CSSWring doesn’t remove only white spaces or comments, but also remove an
unnecessary parts of CSS. See [minification details][2] in our GitHub Wiki.


OPTIONS
-------

### preserveHacks

By default, CSSWring removes all unknown portion of CSS declaration that
includes some CSS hacks (e.g., underscore hacks and star hacks). If you want to
preserve these hacks, pass `preserveHacks: true` to this module.

    postcss([
      csswring({
        preserveHacks: true
      })
    ]).wring(css);


### removeAllComments

By default, CSSWring keeps a comment that start with `/*!`. If you want to
remove all comments, pass `removeAllComments: true` to this module.

    postcss([
      csswring({
        removeAllComments: true
      })
    ]).wring(css);


API
---

### wring(css, [options])

Wring `css` with specified `options`.

The second argument is optional. The `options` is same as the second argument of
PostCSS’s `process()` method. This is useful for generating source map.

    var fs = require("fs");
    var csswring = require("csswring");
    
    var css = fs.readFileSync("from.css", "utf8");
    var result = csswring.wring(css, {
      map: {
        inline: false
      },
      from: "from.css",
      to: "to.css"
    });
    fs.writeFileSync("to.css", result.css);
    fs.writeFileSync("to.css.map", result.map);

See also [Source Map section][3] in PostCSS document for more about this
`options`.

You can also merge CSSWring options mentioned above to the second argument:

    var result = csswring.wring(css, {
      map: true,
      preserveHacks: true
    });


LICENSE
-------

MIT: http://hail2u.mit-license.org/2014


[1]: https://github.com/postcss/postcss
[2]: https://github.com/hail2u/node-csswring/wiki
[3]: https://github.com/postcss/postcss#source-map

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