Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

csswring

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csswring

A CSS minifier for PostCSS

  • 7.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.7K
increased by63.15%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 17 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc