Skip to content

RikhartBekkevold/WebMin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A css minifier

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published