• This repository has been archived on 22/Mar/2019
  • Stars
    star
    157
  • Rank 238,399 (Top 5 %)
  • Language
    JavaScript
  • Created over 10 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A CSS minifier for PostCSS

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

More Repositories

1

html-best-practices

For writing maintainable and scalable HTML documents
4,113
star
2

node-css-mqpacker

Pack same CSS media query rules into one using PostCSS
JavaScript
675
star
3

vim-css3-syntax

CSS3 syntax (and syntax defined in some foreign specifications) support for Vim's built-in syntax/css.vim
CSS
537
star
4

normalize.scss

Modularized and Sassy normalize.css
CSS
130
star
5

color-blindness-emulation

SVG filter collection that emulate 8 types of color blindness
HTML
107
star
6

drawic

A small set of SVG social icons
HTML
84
star
7

jquery.query-yql

Query YQL simply.
HTML
48
star
8

scss-partials

SCSS partials
CSS
41
star
9

roremu-ipusamu

ロレム・イプサムはそこそこ意味の通った英数字交じりの日本語の文章をCC0で登録・収集するプロジェクトです。主にウェブ・ページやウェブ・アプリケーション等のモックアップに使うことを想定しています。
33
star
10

hail2u.net-styles

Repository for tracking (or stalking) changes on CSS or Sassy CSS (SCSS) files for Hail2u.net.
CSS
33
star
11

jquery.table-filter

Insert a input form for filtering table rows dynamically.
JavaScript
28
star
12

jquery.highlight-search-terms

jQuery Plugin: Highlight Search Terms: Highlight search terms in referrer URL from Google, Yahoo!, Bing and custom site.
JavaScript
21
star
13

hail2u.net

The source files of Hail2u website
HTML
20
star
14

mn

The monospace fonts from the Google Fonts directory
HTML
19
star
15

google-code-prettify-language-handlers

Additional or modified language handlers for Google Code Prettify.
JavaScript
17
star
16

html-best-practices-ja-detailed

普通のHTMLの書き方: 保守しやすく、規模に依存しないHTML文書のために
HTML
16
star
17

node-gfmtoc

The GitHub flavored Markdown ToC generator.
JavaScript
15
star
18

jquery.harmonize-text

Change font-size of selected elements to harmonize text with their parent element.
JavaScript
13
star
19

grunt-css-mqpacker

Pack same media query rules into one media query rule using CSS MQPacker.
JavaScript
12
star
20

vim-css-syntax

Patched version of Vim's built-in `syntax/css.vim`.
Vim Script
8
star
21

node-edjo

Convert CSS file into Every Declaration Just Once format.
CSS
8
star
22

postcss-single-charset

A PostCSS plugin for popping first @charset rule up in CSS file
JavaScript
8
star
23

detect-font-loading

A JavaScript library for adding class name to `html` element when font loaded.
JavaScript
8
star
24

scss-functions

Drop-in but useless SCSS functions.
CSS
6
star
25

unutm

A JavaScript library for removing Urchin Traffic Monitor (UTM) parameters from URL
JavaScript
6
star
26

node-pit-ro

Read-only pit for Node.js.
JavaScript
5
star
27

hail2u.github.com

GitHub Pages of Kyo Nagashima.
HTML
5
star
28

bookmark-all

Firefox extension: Bookmark all opening tabs quickly without any dialog.
JavaScript
4
star
29

scss-column-equation

Generate variables for creating CSS column definition, the Sassy way.
CSS
4
star
30

h2u_colorscheme

gVim colorscheme: h2u_black, h2u_dark, and h2u_white.
Vim Script
4
star
31

postcss-fmt

Format a CSS file.
JavaScript
3
star
32

hail2u.net-weblog

Blosxom entry files for Weblog - Hail2u.net.
3
star
33

grunt-svg-rasterizer

Rasterize SVG file with Inkscape CLI.
JavaScript
3
star
34

grunt-selector4096

Warn if CSS file has more than equal 4096 selectors.
JavaScript
3
star
35

grunt-pubsubhubbub_publish

Publish a feed updates to Google PubSubHubbub hub.
JavaScript
3
star
36

jquery.xhashchange

jQuery Plugin: Add hashchange event to any browser
JavaScript
3
star
37

hail2u-ipsum

Generating dummy text from Hail2u website
JavaScript
3
star
38

grunt-long-url

Warn long URL in CSS files.
JavaScript
3
star
39

ufyu

blosxom plugin: Simple TXT-to-HTML coverter.
Perl
2
star
40

amp

Some old thoughts about AMP
2
star
41

abbread

Spreads a `title` attribute of an `abbr` element
JavaScript
2
star
42

vscode-color-scheme-for-windows-terminal

Bring VSCode Dark/Light theme to Windows Terminal
2
star
43

iine.hail2u.net

DISCONTINUED
HTML
2
star
44

postcss-round-float

A PostCSS plugin for rounding floating-point numbers in CSS file
JavaScript
2
star
45

context-style-switcher

Firefox extension: Change Page Style via context menu or toolbar button.
JavaScript
2
star
46

picks.hail2u.net

DISCONTINUED
CSS
1
star
47

grunt-rsync-ac

Run "rsync -aC --exclude-from=.rsyncignore".
JavaScript
1
star
48

node-dns-prefetch

Generate <link rel="dns-prefetch">s from URL.
JavaScript
1
star
49

vim-float-round

Round float numbers of current line.
Vim Script
1
star
50

node-git-release

Automatic release tool for Git
JavaScript
1
star
51

vim-tass-syntax

Vim syntax file for TASS
Vim Script
1
star
52

grunt-png2ico

Generate ICO file from multiple PNG files with ImageMagick.
JavaScript
1
star
53

node-inlining

Inline external CSS files referenced by link element to the HTML file
HTML
1
star
54

asamashi09

外部ドメインに置いたテンプレート・ファイルにより出力をカスタマイズすることができるPure JavaScriptなAmazonアソシエイト・ツール
JavaScript
1
star