Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @askalione/optimizer with all npm packages installed. Try it out:

var optimizer = require("@askalione/optimizer")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@askalione/optimizer v1.1.0

Utility for css and js optimization

Optimizer

Optimizer is a simple utility for minification css and javascript depend on environment mode.

References

Usage

CSS optimization

Default usage:

const optimizer = required('@askalione/optimizer');

var original = 'body { color: #000; }';

var minified = optimizer.optimizeCss(original); // return minified css

Production/Development usage:

const optimizer = required('@askalione/optimizer');
const PRODUCTION = process.env.NODE_ENV === 'production' || false;

var original = 'body { color: #000; }';

var minified = optimizer.optimizeCss(original, PRODUCTION); // return minified css if production mode otherwise not

Options usage:

const optimizer = required('@askalione/optimizer');
const PRODUCTION = process.env.NODE_ENV === 'production' || false;

var original = 'body { color: #000; }';

var minified = optimizer.optimizeCss(original, PRODUCTION, 
{ 
    cleanCss:  {
    ... // CleanCSS options
    }
}); // return minified css if production mode otherwise not

Path options:

const optimizer = required('@askalione/optimizer');
const PRODUCTION = process.env.NODE_ENV === 'production' || false;

var original = 'body { color: #000; }';

var minified = optimizer.optimizeCss(original, PRODUCTION, 
{ 
    path: 'css/site.css'
}); // return object { path, css } where path has minification suffix if css was minified. Css minified if production mode otherwise not. E.g path = 'css/site.min.css' if minified otherwise 'css/site.css'.

Options:

NameTypeDefaultDescription
pathstringundefinedFile path. If undefined optimizaeCss return string = css.
suffixstringminOptimized file suffix.
callbackfunctionminified => minified.stylesCallback for CleanCSS minify method.
cleanCssobjectlevel: { 1: { specialComments: false } }CleanCSS options

JS optimization

Default usage:

const optimizer = required('@askalione/optimizer');

var original = 'var a = function() {};';

var minified = optimizer.optimizeJs(original); // return minified js

Production/Development usage:

const optimizer = required('@askalione/optimizer');
const PRODUCTION = process.env.NODE_ENV === 'production' || false;

var original = 'var a = function() {};';

var minified = optimizer.optimizeJs(original, PRODUCTION); // return minified js if production mode otherwise not

Options usage:

const optimizer = required('@askalione/optimizer');
const PRODUCTION = process.env.NODE_ENV === 'production' || false;

var original = 'var a = function() {};';

var minified = optimizer.optimizeJs(original, PRODUCTION, 
{ 
    uglifyJs:  {
    ... // UglifyJS options
    }
}); // return minified js if production mode otherwise not

Path options:

const optimizer = required('@askalione/optimizer');
const PRODUCTION = process.env.NODE_ENV === 'production' || false;

var original = 'var a = function() {};';

var minified = optimizer.optimizeJs(original, PRODUCTION, 
{ 
    path: 'js/site.js'
}); // return object { path, js } where path has minification suffix if js was minified. Js minified if production mode otherwise not. E.g path = 'js/site.min.js' if minified otherwise 'js/site.js'.

Options:

NameTypeDefaultDescription
pathstringundefinedFile path. If undefined optimizaeJs return string = js.
suffixstringminOptimized file suffix.
callbackfunctionminified => minified.codeCallback for UglifyJS minify method.
uglifyJsobject{}UglifyJS options

License

Optimizer is open source, licensed under the MIT License.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free