Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clean-css-cli

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clean-css-cli - npm Package Compare versions

Comparing version 4.3.0 to 5.0.0

9

History.md

@@ -0,1 +1,10 @@

[5.0.0 / 2021-02-10](https://github.com/jakubpawlowicz/clean-css-cli/compare/4.3...v5.0.0)
==================
* Adds `--batch-suffix` option to specify what gets appended to output filename in batch mode.
* Bumps clean-css dependency to 5.0.
* Bumps commander dependency to 7.0.
* Fixed issue [#18](https://github.com/jakubpawlowicz/clean-css-cli/issues/18) - allows batch processing of input files.
* Fixed issue [#36](https://github.com/jakubpawlowicz/clean-css-cli/issues/36) - automatically creates missing output directories.
[4.3.0 / 2019-04-06](https://github.com/jakubpawlowicz/clean-css-cli/compare/4.2...v4.3.0)

@@ -2,0 +11,0 @@ ==================

273

index.js

@@ -5,3 +5,3 @@ var fs = require('fs');

var CleanCSS = require('clean-css');
var commands = require('commander');
var program = require('commander');
var glob = require('glob');

@@ -16,4 +16,3 @@

var fromStdin;
var debugMode;
var removeInlinedFiles;
var inputOptions;
var options;

@@ -26,94 +25,48 @@ var stdin;

// Specify commander options to parse command line params correctly
commands
.version(buildVersion, '-v, --version')
program
.usage('[options] <source-file ...>')
.option('-b, --batch', 'If enabled, optimizes input files one by one instead of joining them together')
.option('-c, --compatibility [ie7|ie8]', 'Force compatibility mode (see Readme for advanced examples)')
.option('-d, --debug', 'Shows debug information (minification time & compression efficiency)')
.option('-f, --format <options>', 'Controls output formatting, see examples below')
.option('-h, --help', 'display this help')
.option('-o, --output [output-file]', 'Use [output-file] as output instead of STDOUT')
.option('-O <n> [optimizations]', 'Turn on level <n> optimizations; optionally accepts a list of fine-grained options, defaults to `1`, see examples below', function (val) { return Math.abs(parseInt(val)); })
.option('-O <n> [optimizations]', 'Turn on level <n> optimizations; optionally accepts a list of fine-grained options, defaults to `1`, see examples below, IMPORTANT: the prefix is O (a capital o letter), NOT a 0 (zero, a number)', function (val) { return Math.abs(parseInt(val)); })
.version(buildVersion, '-v, --version')
.option('--batch-suffix <suffix>', 'A suffix (without extension) appended to input file name when processing in batch mode (`-min` is the default)', '-min')
.option('--inline [rules]', 'Enables inlining for listed sources (defaults to `local`)')
.option('--inline-timeout [seconds]', 'Per connection timeout when fetching remote stylesheets (defaults to 5 seconds)', parseFloat)
.option('--input-source-map [file]', 'Specifies the path of the input source map file')
.option('--remove-inlined-files', 'Remove files inlined in <source-file ...> or via `@import` statements')
.option('--skip-rebase', 'Disable URLs rebasing')
.option('--source-map', 'Enables building input\'s source map')
.option('--source-map-inline-sources', 'Enables inlining sources inside source maps')
.option('--input-source-map [file]', 'Specifies the path of the input source map file');
.option('--with-rebase', 'Enable URLs rebasing');
commands.on('--help', function () {
console.log(' Examples:\n');
console.log(' %> cleancss one.css');
console.log(' %> cleancss -o one-min.css one.css');
console.log(' %> cleancss -o merged-and-minified.css one.css two.css three.css');
console.log(' %> cleancss one.css two.css three.css | gzip -9 -c > merged-minified-and-gzipped.css.gz');
program.on('--help', function () {
console.log('');
console.log(' Formatting options:');
console.log(' %> cleancss --format beautify one.css');
console.log(' %> cleancss --format keep-breaks one.css');
console.log(' %> cleancss --format \'indentBy:1;indentWith:tab\' one.css');
console.log(' %> cleancss --format \'breaks:afterBlockBegins=on;spaces:aroundSelectorRelation=on\' one.css');
console.log(' %> # `breaks` controls where to insert breaks');
console.log(' %> # `afterAtRule` controls if a line break comes after an at-rule; e.g. `@charset`; defaults to `off` (alias to `false`)');
console.log(' %> # `afterBlockBegins` controls if a line break comes after a block begins; e.g. `@media`; defaults to `off`');
console.log(' %> # `afterBlockEnds` controls if a line break comes after a block ends, defaults to `off`');
console.log(' %> # `afterComment` controls if a line break comes after a comment; defaults to `off`');
console.log(' %> # `afterProperty` controls if a line break comes after a property; defaults to `off`');
console.log(' %> # `afterRuleBegins` controls if a line break comes after a rule begins; defaults to `off`');
console.log(' %> # `afterRuleEnds` controls if a line break comes after a rule ends; defaults to `off`');
console.log(' %> # `beforeBlockEnds` controls if a line break comes before a block ends; defaults to `off`');
console.log(' %> # `betweenSelectors` controls if a line break comes between selectors; defaults to `off`');
console.log(' %> # `indentBy` controls number of characters to indent with; defaults to `0`');
console.log(' %> # `indentWith` controls a character to indent with, can be `space` or `tab`; defaults to `space`');
console.log(' %> # `spaces` controls where to insert spaces');
console.log(' %> # `aroundSelectorRelation` controls if spaces come around selector relations; e.g. `div > a`; defaults to `off`');
console.log(' %> # `beforeBlockBegins` controls if a space comes before a block begins; e.g. `.block {`; defaults to `off`');
console.log(' %> # `beforeValue` controls if a space comes before a value; e.g. `width: 1rem`; defaults to `off`');
console.log(' %> # `wrapAt` controls maximum line length; defaults to `off`');
console.log('Examples:\n');
console.log(' %> cleancss one.css');
console.log(' %> cleancss -o one-min.css one.css');
console.log(' %> cleancss -o merged-and-minified.css one.css two.css three.css');
console.log(' %> cleancss one.css two.css three.css | gzip -9 -c > merged-minified-and-gzipped.css.gz');
console.log('');
console.log(' Level 0 optimizations:');
console.log(' %> cleancss -O0 one.css');
console.log('Formatting options:');
console.log(' %> cleancss --format beautify one.css');
console.log(' %> cleancss --format keep-breaks one.css');
console.log(' %> cleancss --format \'indentBy:1;indentWith:tab\' one.css');
console.log(' %> cleancss --format \'breaks:afterBlockBegins=on;spaces:aroundSelectorRelation=on\' one.css');
console.log(' %> cleancss --format \'breaks:afterBlockBegins=2;spaces:aroundSelectorRelation=on\' one.css');
console.log('');
console.log(' Level 1 optimizations:');
console.log(' %> cleancss -O1 one.css');
console.log(' %> cleancss -O1 removeQuotes:off;roundingPrecision:4;specialComments:1 one.css');
console.log(' %> cleancss -O1 all:off;specialComments:1 one.css');
console.log(' %> # `cleanupCharsets` controls `@charset` moving to the front of a stylesheet; defaults to `on`');
console.log(' %> # `normalizeUrls` controls URL normalzation; default to `on`');
console.log(' %> # `optimizeBackground` controls `background` property optimizatons; defaults to `on`');
console.log(' %> # `optimizeBorderRadius` controls `border-radius` property optimizatons; defaults to `on`');
console.log(' %> # `optimizeFilter` controls `filter` property optimizatons; defaults to `on`');
console.log(' %> # `optimizeFontWeight` controls `font-weight` property optimizatons; defaults to `on`');
console.log(' %> # `optimizeOutline` controls `outline` property optimizatons; defaults to `on`');
console.log(' %> # `removeEmpty` controls removing empty rules and nested blocks; defaults to `on` (since 4.1.0)');
console.log(' %> # `removeNegativePaddings` controls removing negative paddings; defaults to `on`');
console.log(' %> # `removeQuotes` controls removing quotes when unnecessary; defaults to `on`');
console.log(' %> # `removeWhitespace` controls removing unused whitespace; defaults to `on`');
console.log(' %> # `replaceMultipleZeros` contols removing redundant zeros; defaults to `on`');
console.log(' %> # `replaceTimeUnits` controls replacing time units with shorter values; defaults to `on');
console.log(' %> # `replaceZeroUnits` controls replacing zero values with units; defaults to `on`');
console.log(' %> # `roundingPrecision` rounds pixel values to `N` decimal places; `off` disables rounding; defaults to `off`');
console.log(' %> # `selectorsSortingMethod` denotes selector sorting method; can be `natural` or `standard`; defaults to `standard`');
console.log(' %> # `specialComments` denotes a number of /*! ... */ comments preserved; defaults to `all`');
console.log(' %> # `tidyAtRules` controls at-rules (e.g. `@charset`, `@import`) optimizing; defaults to `on`');
console.log(' %> # `tidyBlockScopes` controls block scopes (e.g. `@media`) optimizing; defaults to `on`');
console.log(' %> # `tidySelectors` controls selectors optimizing; defaults to `on`');
console.log('Level 0 optimizations:');
console.log(' %> cleancss -O0 one.css');
console.log('');
console.log(' Level 2 optimizations:');
console.log(' %> cleancss -O2 one.css');
console.log(' %> cleancss -O2 mergeMedia:off;restructureRules:off;mergeSemantically:on;mergeIntoShorthands:off one.css');
console.log(' %> cleancss -O2 all:off;removeDuplicateRules:on one.css');
console.log(' %> # `mergeAdjacentRules` controls adjacent rules merging; defaults to `on`');
console.log(' %> # `mergeIntoShorthands` controls merging properties into shorthands; defaults to `on`');
console.log(' %> # `mergeMedia` controls `@media` merging; defaults to `on`');
console.log(' %> # `mergeNonAdjacentRules` controls non-adjacent rule merging; defaults to `on`');
console.log(' %> # `mergeSemantically` controls semantic merging; defaults to `off`');
console.log(' %> # `overrideProperties` controls property overriding based on understandability; defaults to `on`');
console.log(' %> # `reduceNonAdjacentRules` controls non-adjacent rule reducing; defaults to `on`');
console.log(' %> # `removeDuplicateFontRules` controls duplicate `@font-face` removing; defaults to `on`');
console.log(' %> # `removeDuplicateMediaBlocks` controls duplicate `@media` removing; defaults to `on`');
console.log(' %> # `removeDuplicateRules` controls duplicate rules removing; defaults to `on`');
console.log(' %> # `removeEmpty` controls removing empty rules and nested blocks; defaults to `on` (since 4.1.0)');
console.log(' %> # `removeUnusedAtRules` controls unused at rule removing; defaults to `off` (since 4.1.0)');
console.log(' %> # `restructureRules` controls rule restructuring; defaults to `off`');
console.log(' %> # `skipProperties` controls which properties won\'t be optimized, defaults to empty list which means all will be optimized (since 4.1.0)');
console.log('Level 1 optimizations:');
console.log(' %> cleancss -O1 one.css');
console.log(' %> cleancss -O1 removeQuotes:off;roundingPrecision:4;specialComments:1 one.css');
console.log(' %> cleancss -O1 all:off;specialComments:1 one.css');
console.log('');
console.log('Level 2 optimizations:');
console.log(' %> cleancss -O2 one.css');
console.log(' %> cleancss -O2 mergeMedia:off;restructureRules:off;mergeSemantically:on;mergeIntoShorthands:off one.css');
console.log(' %> cleancss -O2 all:off;removeDuplicateRules:on one.css');

@@ -123,21 +76,10 @@ process.exit();

commands.parse(process.argv);
program.parse(process.argv);
inputOptions = program.opts();
if (commands.rawArgs.indexOf('-O0') > -1) {
commands.O0 = true;
}
if (commands.rawArgs.indexOf('-O1') > -1) {
commands.O1 = findArgumentTo('-O1', commands.rawArgs, commands.args);
}
if (commands.rawArgs.indexOf('-O2') > -1) {
commands.O2 = findArgumentTo('-O2', commands.rawArgs, commands.args);
}
// If no sensible data passed in just print help and exit
if (commands.args.length === 0) {
if (program.args.length === 0) {
fromStdin = !process.env.__DIRECT__ && !process.stdin.isTTY;
if (!fromStdin) {
commands.outputHelp();
program.outputHelp();
return 0;

@@ -147,22 +89,30 @@ }

// Now coerce commands into CleanCSS configuration...
debugMode = commands.debug;
removeInlinedFiles = commands.removeInlinedFiles;
// Now coerce arguments into CleanCSS configuration...
options = {
compatibility: commands.compatibility,
format: commands.format,
inline: typeof commands.inline == 'string' ? commands.inline : 'local',
inlineTimeout: commands.inlineTimeout * 1000,
level: commands.O0 || commands.O1 || commands.O2 ?
{ '0': commands.O0, '1': commands.O1, '2': commands.O2 } :
undefined,
output: commands.output,
rebase: commands.skipRebase ? false : true,
rebaseTo: ('output' in commands) && commands.output.length > 0 ? path.dirname(path.resolve(commands.output)) : process.cwd(),
sourceMap: commands.sourceMap,
sourceMapInlineSources: commands.sourceMapInlineSources
batch: inputOptions.batch,
compatibility: inputOptions.compatibility,
format: inputOptions.format,
inline: typeof inputOptions.inline == 'string' ? inputOptions.inline : 'local',
inlineTimeout: inputOptions.inlineTimeout * 1000,
level: { 1: true },
output: inputOptions.output,
rebase: inputOptions.withRebase ? true : false,
rebaseTo: ('output' in inputOptions) && inputOptions.output.length > 0 ? path.dirname(path.resolve(inputOptions.output)) : (inputOptions.withRebase ? process.cwd() : undefined),
sourceMap: inputOptions.sourceMap,
sourceMapInlineSources: inputOptions.sourceMapInlineSources
};
if (commands.inputSourceMap && !options.sourceMap) {
if (program.rawArgs.indexOf('-O0') > -1) {
options.level[0] = true;
}
if (program.rawArgs.indexOf('-O1') > -1) {
options.level[1] = findArgumentTo('-O1', program.rawArgs, program.args);
}
if (program.rawArgs.indexOf('-O2') > -1) {
options.level[2] = findArgumentTo('-O2', program.rawArgs, program.args);
}
if (inputOptions.inputSourceMap && !options.sourceMap) {
options.sourceMap = true;

@@ -177,11 +127,12 @@ }

var configurations = {
batchSuffix: inputOptions.batchSuffix,
beforeMinifyCallback: beforeMinifyCallback,
debugMode: debugMode,
removeInlinedFiles: removeInlinedFiles,
inputSourceMap: commands.inputSourceMap
debugMode: inputOptions.debug,
removeInlinedFiles: inputOptions.removeInlinedFiles,
inputSourceMap: inputOptions.inputSourceMap
};
// ... and do the magic!
if (commands.args.length > 0) {
minify(process, options, configurations, expandGlobs(commands.args));
if (program.args.length > 0) {
minify(process, options, configurations, expandGlobs(program.args));
} else {

@@ -240,37 +191,61 @@ stdin = process.openStdin();

cleanCss.minify(data, getSourceMapContent(configurations.inputSourceMap), function (errors, minified) {
var mapFilename;
var inputPath;
if (configurations.debugMode) {
console.error('Original: %d bytes', minified.stats.originalSize);
console.error('Minified: %d bytes', minified.stats.minifiedSize);
console.error('Efficiency: %d%', ~~(minified.stats.efficiency * 10000) / 100.0);
console.error('Time spent: %dms', minified.stats.timeSpent);
if (minified.inlinedStylesheets.length > 0) {
console.error('Inlined stylesheets:');
minified.inlinedStylesheets.forEach(function (uri) {
console.error('- %s', uri);
});
if (options.batch && !('styles' in minified)) {
for (inputPath in minified) {
processMinified(process, configurations, minified[inputPath], inputPath, toOutputPath(inputPath, configurations.batchSuffix));
}
} else {
processMinified(process, configurations, minified, null, options.output);
}
});
}
outputFeedback(minified.errors, true);
outputFeedback(minified.warnings);
function toOutputPath(inputPath, batchSuffix) {
var extensionName = path.extname(inputPath);
if (minified.errors.length > 0) {
process.exit(1);
return inputPath.replace(new RegExp(extensionName + '$'), batchSuffix + extensionName);
}
function processMinified(process, configurations, minified, inputPath, outputPath) {
var mapOutputPath;
if (configurations.debugMode) {
if (inputPath) {
console.error('File: %s', inputPath);
}
if (configurations.removeInlinedFiles) {
minified.inlinedStylesheets.forEach(fs.unlinkSync);
console.error('Original: %d bytes', minified.stats.originalSize);
console.error('Minified: %d bytes', minified.stats.minifiedSize);
console.error('Efficiency: %d%', ~~(minified.stats.efficiency * 10000) / 100.0);
console.error('Time spent: %dms', minified.stats.timeSpent);
if (minified.inlinedStylesheets.length > 0) {
console.error('Inlined stylesheets:');
minified.inlinedStylesheets.forEach(function (uri) {
console.error('- %s', uri);
});
}
if (minified.sourceMap) {
mapFilename = path.basename(options.output) + '.map';
output(process, options, minified.styles + lineBreak + '/*# sourceMappingURL=' + mapFilename + ' */');
outputMap(options, minified.sourceMap, mapFilename);
} else {
output(process, options, minified.styles);
}
});
console.error('');
}
outputFeedback(minified.errors, true);
outputFeedback(minified.warnings);
if (minified.errors.length > 0) {
process.exit(1);
}
if (configurations.removeInlinedFiles) {
minified.inlinedStylesheets.forEach(fs.unlinkSync);
}
if (minified.sourceMap) {
mapOutputPath = outputPath + '.map';
output(process, outputPath, minified.styles + lineBreak + '/*# sourceMappingURL=' + path.basename(mapOutputPath) + ' */');
outputMap(mapOutputPath, minified.sourceMap);
} else {
output(process, outputPath, minified.styles);
}
}

@@ -328,5 +303,6 @@

function output(process, options, minified) {
if (options.output) {
fs.writeFileSync(options.output, minified, 'utf8');
function output(process, outputPath, minified) {
if (outputPath) {
fs.mkdirSync(path.dirname(outputPath), {recursive: true});
fs.writeFileSync(outputPath, minified, 'utf8');
} else {

@@ -337,7 +313,6 @@ process.stdout.write(minified);

function outputMap(options, sourceMap, mapFilename) {
var mapPath = path.join(path.dirname(options.output), mapFilename);
fs.writeFileSync(mapPath, sourceMap.toString(), 'utf-8');
function outputMap(mapOutputPath, sourceMap) {
fs.writeFileSync(mapOutputPath, sourceMap.toString(), 'utf-8');
}
module.exports = cli;
{
"name": "clean-css-cli",
"version": "4.3.0",
"version": "5.0.0",
"description": "A command-line interface to clean-css CSS optimization library",

@@ -22,3 +22,3 @@ "scripts": {

},
"author": "Jakub Pawlowicz <contact@jakubpawlowicz.com> (http://twitter.com/jakubpawlowicz)",
"author": "Jakub Pawlowicz <contact@jakubpawlowicz.com>",
"license": "MIT",

@@ -33,19 +33,20 @@ "bugs": {

"index.js",
"LICENSE"
"LICENSE",
"README.md"
],
"homepage": "https://github.com/jakubpawlowicz/clean-css-cli#readme",
"dependencies": {
"clean-css": "^4.2.1",
"commander": "2.x",
"glob": "7.x"
"clean-css": "^5.0.1",
"commander": "7.x",
"glob": "^7.1.6"
},
"devDependencies": {
"http-proxy": "1.x",
"jshint": "2.x",
"jshint": "^2.12.0",
"source-map": "0.5.x",
"vows": "0.8.x"
"vows": "^0.8.3"
},
"engines": {
"node": ">= 4.0"
"node": ">= 10.0"
}
}

@@ -9,6 +9,5 @@ <h1 align="center">

[![NPM version](https://img.shields.io/npm/v/clean-css-cli.svg?style=flat)](https://www.npmjs.com/package/clean-css-cli)
[![Linux Build Status](https://img.shields.io/travis/jakubpawlowicz/clean-css-cli/master.svg?style=flat&label=Linux%20build)](https://travis-ci.org/jakubpawlowicz/clean-css)
![x86 Linux build](https://github.com/jakubpawlowicz/clean-css-cli/workflows/x86%20Linux%20build/badge.svg)
[![Dependency Status](https://img.shields.io/david/jakubpawlowicz/clean-css-cli.svg?style=flat)](https://david-dm.org/jakubpawlowicz/clean-css-cli)
[![NPM Downloads](https://img.shields.io/npm/dm/clean-css-cli.svg)](https://www.npmjs.com/package/clean-css-cli)
[![Twitter](https://img.shields.io/badge/Twitter-@cleancss-blue.svg)](https://twitter.com/cleancss)

@@ -24,4 +23,7 @@ clean-css-cli is a command-line interface to [clean-css](https://github.com/jakubpawlowicz/clean-css) - fast and efficient CSS optimizer for [Node.js](http://nodejs.org/).

- [Use](#use)
* [Important: 4.0 breaking changes](#important-40-breaking-changes)
* [What's new in version 5.0](#whats-new-in-version-50)
* [What's new in version 4.3](#whats-new-in-version-43)
* [What's new in version 4.2](#whats-new-in-version-42)
* [What's new in version 4.1](#whats-new-in-version-41)
* [What's new in version 4.0](#whats-new-in-version-40)
* [CLI options](#cli-options)

@@ -38,2 +40,3 @@ * [Compatibility modes](#compatibility-modes)

* [How to optimize multiple files?](#how-to-optimize-multiple-files)
* [How to process multiple files without concatenating them into one output file?](#how-to-process-multiple-files-without-concatenating-them-into-one-output-file)
* [How to specify a custom rounding precision?](#how-to-specify-a-custom-rounding-precision)

@@ -48,3 +51,3 @@ * [How to rebase relative image URLs?](#how-to-rebase-relative-image-urls)

clean-css-cli requires Node.js 4.0+ (tested on Linux, OS X, and Windows)
clean-css-cli requires Node.js 10.0+ (tested on Linux, OS X, and Windows)

@@ -64,4 +67,39 @@ # Install

## Important: 4.0 breaking changes
## What's new in version 5.0
clean-css-cli 5.0 introduces the following changes / features:
* adds `--batch` option (off by default) which processes input files one by one without joining them together;
* adds `--batch-suffix` option to specify what gets appended to output filename in batch mode;
* automatically creates missing output directories;
* clean-css 5.0 with loads of bugfixes;
* drops official support for Node.js 4, 6, and 8;
* `--skip-rebase` option has been removed as rebasing URLs is disabled by default now
* `--with-rebase` option is added if you really want URLs rebasing
## What's new in version 4.3
clean-css-cli 4.3 introduces the following changes / features:
* `--input-source-map` option which accepts a path to input source map file.
## What's new in version 4.2
clean-css-cli 4.2 introduces the following changes / features:
* [clean-css 4.2](https://github.com/jakubpawlowicz/clean-css#whats-new-in-version-42) as a dependency;
## What's new in version 4.1
clean-css-cli 4.1 introduces the following changes / features:
* [clean-css 4.1](https://github.com/jakubpawlowicz/clean-css#whats-new-in-version-41) as a dependency;
* `--remove-inlined-files` option for removing files inlined in <source-file ...> or via `@import` statements;
* adds glob pattern matching to source paths, see [example](#how-to-optimize-multiple-files);
* allows non-boolean compatibility options, e.g. `--compatibility selectors.mergeLimit=512`;
* extracts CLI into an importable module, so it can be reused and enhanced if needed;
* adds `beforeMinify` callback as a second argument to CLI module, see [example use case](#as-a-module).
## What's new in version 4.0
clean-css-cli 4.0 introduces some breaking changes:

@@ -83,30 +121,20 @@

## What's new in version 4.1
clean-css-cli 4.1 introduces the following changes / features:
* [clean-css 4.1](https://github.com/jakubpawlowicz/clean-css#whats-new-in-version-41) as a dependency;
* `--remove-inlined-files` option for removing files inlined in <source-file ...> or via `@import` statements;
* adds glob pattern matching to source paths, see [example](#how-to-optimize-multiple-files);
* allows non-boolean compatibility options, e.g. `--compatibility selectors.mergeLimit=512`;
* extracts CLI into an importable module, so it can be reused and enhanced if needed;
* adds `beforeMinify` callback as a second argument to CLI module, see [example use case](#as-a-module).
## CLI options
```shell
-h, --help output usage information
-v, --version output the version number
-b, --batch If enabled, optimizes input files one by one instead of joining them together
-c, --compatibility [ie7|ie8] Force compatibility mode (see Readme for advanced examples)
-d, --debug Shows debug information (minification time & compression efficiency)
-f, --format <options> Controls output formatting, see examples below
-h, --help output usage information
-o, --output [output-file] Use [output-file] as output instead of STDOUT
-O <n> [optimizations] Turn on level <n> optimizations; optionally accepts a list of fine-grained options, defaults to `1`, see examples below
-O <n> [optimizations] Turn on level <n> optimizations; optionally accepts a list of fine-grained options, defaults to `1`, IMPORTANT: the prefix is O (a capital o letter), NOT a 0 (zero, a number)
-v, --version output the version number
--inline [rules] Enables inlining for listed sources (defaults to `local`)
--inline-timeout [seconds] Per connection timeout when fetching remote stylesheets (defaults to 5 seconds)
--input-source-map [file] Specifies the path of the input source map file
--remove-inlined-files Remove files inlined in <source-file ...> or via `@import` statements
--skip-rebase Disable URLs rebasing
--source-map Enables building input's source map
--source-map-inline-sources Enables inlining sources inside source maps
--input-source-map [file] Specifies the path of the input source map file
--with-rebase Disable URLs rebasing
```

@@ -222,2 +250,4 @@

Important: The `-O` option is using the capital letter O (as in "Oscar"), not the number zero.
### Level 0 optimizations

@@ -310,8 +340,16 @@

return cleanCssCli(process, function beforeMinify(cleanCss) {
cleanCss.options.level['1'].transform = function (propertyName, propertyValue) {
if (propertyName == 'background-image' && propertyValue.indexOf('../valid/path/to') == -1) {
return propertyValue.replace('url(', 'url(../valid/path/to/');
var customPlugin = {
level1: {
value: function (propertyName, propertyValue, options) {
if (propertyName == 'background-image' && propertyValue.indexOf('../valid/path/to') == -1) {
return propertyValue.replace('url(', 'url(../valid/path/to/');
} else {
return propertyValue;
}
}
}
}
return cleanCssCli(process, function (cleanCss) {
cleanCss.options.plugins.level1Value.push(customPlugin.level1.value);
});

@@ -338,2 +376,20 @@ ```

## How to process multiple files without concatenating them into one output file?
Since clean-css-cli 5.0 you can optimize files one by one, without joining them into one output file, e.g.
```shell
cleancss --batch styles/*.css
```
By default it will pick up every single file from `styles` directory, optimize it, add a `-min` suffix to filename (before extension), and write it to disk.
You can use `--batch-suffix` option to customize the `-min` suffix, e.g.
```shell
cleancss --batch --batch-suffix '.min' styles/*.css
```
Remember you can use [glob matching](https://www.npmjs.com/package/glob#glob-primer) to match exactly the files you want.
## How to specify a custom rounding precision?

@@ -351,3 +407,3 @@

clean-css-cli will handle it automatically for you when full paths to input files are passed in and `--output` option is used, e.g
clean-css-cli will rebase paths it automatically for you when full paths to input files are passed, and `--with-rebase` & `--output` options are used, e.g

@@ -362,3 +418,3 @@ ```css

```shell
cleancss -o build/one.min.css one.css
cleancss --with-rebase -o build/one.min.css one.css
```

@@ -365,0 +421,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc