JSPM

  • Created
  • Published
  • Downloads 4122
  • Score
    100M100P100Q6476F

Minify CSS file with Source Maps. That's only.

Package Exports

  • csswring

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (csswring) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

CSSWring

Minify CSS file with Source Maps. That's only.

Written with PostCSS. See also grunt-csswring by @princed.

INSTALLATION

$ npm install csswring

QUICK USAGE

#!/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);

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.

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.

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

API

wring(css, [options])

Wring css.

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: true,
  from: 'from.css',
  to: 'to.css'
});
fs.writeFileSync('to.css', result.css);
fs.writeFileSync('to.css.map', result.map);

See also 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,
  from: 'from.css',
  to: 'to.css',
  preserveHacks: true
});

postcss

Returns a PostCSS processor.

You can use this property for combining with other PostCSS processors such as Autoprefixer.

var fs = require('fs');
var postcss = require('postcss');
var autoprefixer = require('autoprefixer');
var csswring = require('csswring');

var css = fs.readFileSync('test.css', 'utf8');
postcss().use(
  autoprefixer.postcss
).use(
  csswring.postcss
).process(css);

CLI USAGE

This package also installs a command line interface.

$ node ./node_modules/.bin/csswring --help
Usage:
  csswring [options] INPUT [OUTPUT]

Description:
  Minify CSS file with Source Maps. That's only.

Options:
      --sourcemap            Create source map file.
      --preserve-hacks       Preserve some CSS hacks.
      --remove-all-comments  Remove all comments.
  -h, --help                 Show this message.
  -v, --version              Print version information.

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.

LICENSE

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