From 5f79864c10d7eaba634dc8183a7228533059dedd Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Fri, 10 Oct 2014 07:17:07 +0100 Subject: [PATCH] Improves handling & documentation of minification options. --- README.md | 21 +++++++++++---------- lib/clean.js | 24 +++++++++++++++++------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 5f9df6f1..d30bfef8 100644 --- a/README.md +++ b/README.md @@ -121,19 +121,20 @@ var minimized = new CleanCSS().minify(source); CleanCSS constructor accepts a hash as a parameter, i.e., `new CleanCSS(options).minify(source)` with the following options available: -* `keepSpecialComments` - `*` for keeping all (default), `1` for keeping first one only, `0` for removing all +* `benchmark` - turns on benchmarking mode measuring time spent on cleaning up (run `npm run bench` to see example) +* `compatibility` - Force compatibility mode to `ie7` or `ie8`. Defaults to not set. +* `debug` - set to true to get minification statistics under `stats` property (see `test/custom-test.js` for examples) +* `inliner` - a hash of options for `@import` inliner, see test/protocol-imports-test.js for examples * `keepBreaks` - whether to keep line breaks (default is false) -* `benchmark` - turns on benchmarking mode measuring time spent on cleaning up - (run `npm run bench` to see example) -* `root` - path to __resolve__ absolute `@import` rules and __rebase__ relative URLs -* `relativeTo` - path to __resolve__ relative `@import` rules and URLs -* `target` - path to a folder or an output file to which __rebase__ all URLs -* `processImport` - whether to process `@import` rules -* `noRebase` - whether to skip URLs rebasing +* `keepSpecialComments` - `*` for keeping all (default), `1` for keeping first one only, `0` for removing all * `noAdvanced` - set to true to disable advanced optimizations - selector & property merging, reduction, etc. +* `noAggressiveMerging` - set to true to disable aggressive merging of properties. +* `noRebase` - whether to skip URLs rebasing +* `processImport` - whether to process `@import` rules +* `relativeTo` - path to __resolve__ relative `@import` rules and URLs +* `root` - path to __resolve__ absolute `@import` rules and __rebase__ relative URLs * `roundingPrecision` - Rounding precision, defaults to 2. -* `compatibility` - Force compatibility mode to `ie7` or `ie8`. Defaults to not set. -* `debug` - set to true to get minification statistics under `stats` property (see `test/custom-test.js` for examples) +* `target` - path to a folder or an output file to which __rebase__ all URLs ### How to use clean-css with build tools? diff --git a/lib/clean.js b/lib/clean.js index 3b7ba0b2..ff72fc29 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -17,13 +17,23 @@ var UrlsProcessor = require('./text/urls-processor'); var CleanCSS = module.exports = function CleanCSS(options) { options = options || {}; - options.keepBreaks = options.keepBreaks || false; - - //active by default - if (undefined === options.processImport) - options.processImport = true; + this.options = { + benchmark: options.benchmark, + compatibility: options.compatibility, + debug: options.debug, + inliner: options.inliner, + keepBreaks: options.keepBreaks || false, + keepSpecialComments: 'keepSpecialComments' in options ? options.keepSpecialComments : '*', + noAdvanced: options.noAdvanced, + noAggressiveMerging: options.noAggressiveMerging, + noRebase: options.noRebase, + processImport: undefined === options.processImport ? true : false, + relativeTo: options.relativeTo, + root: options.root, + roundingPrecision: options.roundingPrecision, + target: options.target + }; - this.options = options; this.stats = {}; this.context = { errors: [], @@ -100,7 +110,7 @@ function minify(data) { var options = this.options; var context = this.context; - var commentsProcessor = new CommentsProcessor('keepSpecialComments' in options ? options.keepSpecialComments : '*', options.keepBreaks); + var commentsProcessor = new CommentsProcessor(options.keepSpecialComments, options.keepBreaks); var expressionsProcessor = new ExpressionsProcessor(); var freeTextProcessor = new FreeTextProcessor(); var urlsProcessor = new UrlsProcessor(); -- 2.34.1