Skip to content

Latest commit

 

History

History
165 lines (130 loc) · 5.97 KB

README.md

File metadata and controls

165 lines (130 loc) · 5.97 KB

WebMin

A CSS minifier. Can be used as CLI or API.

Try

Playground

API

Pass a string or filepaths. Simple use-case:

var minify = require('WebMin');
var min_css = minify(
  `
    body {
      margin: 2px;
    }
    div {
      height: 20%;
    }
  `
);
console.log(min_css);
// "body{margin:2px;}div{height: 20%}"

Take note that the string must represent valid CSS. The minifier cannot work with invalid CSS.

You can customize the minification process by overriding many of the default config variables used during the process, to do so pass an object as the second argument:

var minify = require('WebMin');

// any config passed will override the default config
var min_css = minify("body {}", {
  // will leave empty selectors untouched,
  // normally these would be removed during minification
  removeEmptySelectors: false
})

console.log(min_css); // -> "body{}"

Here is a list of all config options currently available and their default values:

minify("body {margin: 2px;}", {
  removeEmptyAtRules: true,
  prependComment: "",                  
  removeSpace: true,
  removeComments: true,
  skipTrailingZero: true,
  removeExcessUnits: true,
  shortenUnsafeHex: false,              
  replaceRgbWithHex: true,              
  useShortestColorValue: true,          
  replaceColorNameWithHex: true,
  keepImportantInKeyframes: false,      
  removeRedundantImportant: true,
  removeExcessImportant: false,
  removeCharset: false,
  removeDeprecatedAtRules: false,      
  shortenShortHand: true,              
  removeOverridenDeclarations: true,
  mergeDupliSelectors: true,
  removeEmptySelectors: true,           
  longhandToShorthand: false,          
  mangleKeyframeNames: true,
  mangleNames: false,
  keepFirstComment: false,
  roundColorValuesHex: false
})

CLI

Run to minify:

webmin -i style.css media.css alt_style.css -o ./css/min.css

-i Input files. Can also skip the -i flag.

-o Output file. specific "/dir/file.js" for dir.

-c Config variables passed to minification process (make shell). Cant also make a webmin.config.js file in root.

Additionally you can print extra info: --help Lists all options.

Licence

MIT