From: Jakub Pawlowicz Date: Tue, 27 Dec 2016 13:31:10 +0000 (+0100) Subject: See #801 - recommends clean-css styles concatenation. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=89250708842267128bbeee4c08735a6596e32f79;p=clean-css.git See #801 - recommends clean-css styles concatenation. Why: * There is a difference between passing in a concatenated string and letting clean-css do the job. The former will discard `@import` statements appearing not at the beginning of the string, while the latter will discard only those appearing not at the beginning of any of the files. Because of this behavior, the latter way is recommended. --- diff --git a/README.md b/README.md index 27df2a54..ff76c590 100644 --- a/README.md +++ b/README.md @@ -83,37 +83,32 @@ cleancss [options] source-file, [source-file, ...] #### Examples: -To minify a **public.css** file into **public-min.css** do: +To minify a **one.css** file into **one-min.css** do: ``` -cleancss -o public-min.css public.css +cleancss -o one-min.css one.css ``` -To minify the same **public.css** into the standard output skip the `-o` parameter: +To minify the same **one.css** into the standard output skip the `-o` parameter: ``` -cleancss public.css +cleancss one.css ``` -More likely you would like to concatenate a couple of files. -If you are on a Unix-like system: +If you would like to minify a couple of files together, pass more paths in: ```bash -cat one.css two.css three.css | cleancss -o merged-and-minified.css +cleancss -o merged-and-minified.css one.css two.css three.css ``` -On Windows: - -```bat -type one.css two.css three.css | cleancss -o merged-and-minified.css -``` - -Or even gzip the result at once: +You can also pipe results to other commands, e.g. gzip: ```bash -cat one.css two.css three.css | cleancss | gzip -9 -c > merged-minified-and-gzipped.css.gz +cleancss one.css two.css three.css | gzip -9 -c > merged-minified-and-gzipped.css.gz ``` +Please note there is a difference between passing in a concatenated string and letting clean-css do the job. The former will discard `@import` statements appearing [not at the beginning](https://developer.mozilla.org/en-US/docs/Web/CSS/@import) of the string, while the latter will discard only those appearing not at the beginning of any of the files. Because of this behavior, the latter way (see examples above) is recommended. + ### How to use clean-css API? ```js diff --git a/bin/cleancss b/bin/cleancss index 27136aa4..b936be35 100755 --- a/bin/cleancss +++ b/bin/cleancss @@ -9,8 +9,6 @@ var commands = require('commander'); var packageConfig = fs.readFileSync(path.join(path.dirname(fs.realpathSync(process.argv[1])), '../package.json')); var buildVersion = JSON.parse(packageConfig).version; -var isWindows = process.platform == 'win32'; - // Specify commander options to parse command line params correctly commands .version(buildVersion, '-v, --version') @@ -39,12 +37,8 @@ commands.on('--help', function () { console.log(' Examples:\n'); console.log(' %> cleancss one.css'); console.log(' %> cleancss -o one-min.css one.css'); - if (isWindows) { - console.log(' %> type one.css two.css three.css | cleancss -o merged-and-minified.css'); - } else { - console.log(' %> cat one.css two.css three.css | cleancss -o merged-and-minified.css'); - console.log(' %> cat one.css two.css three.css | cleancss | gzip -9 -c > merged-minified-and-gzipped.css.gz'); - } + 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(''); process.exit(); }); diff --git a/test/binary-test.js b/test/binary-test.js index ce8d4088..01d67b20 100644 --- a/test/binary-test.js +++ b/test/binary-test.js @@ -64,10 +64,10 @@ vows.describe('./bin/cleancss') assert.include(stdout, 'cleancss -o one-min.css one.css'); }, 'should output multiple files example': function (error, stdout) { - assert.include(stdout, 'cat one.css two.css three.css | cleancss -o merged-and-minified.css'); + assert.include(stdout, 'cleancss -o merged-and-minified.css one.css two.css three.css'); }, 'should output gzipping multiple files example': function (error, stdout) { - assert.include(stdout, 'cat one.css two.css three.css | cleancss | gzip -9 -c > merged-minified-and-gzipped.css.gz'); + assert.include(stdout, 'cleancss one.css two.css three.css | gzip -9 -c > merged-minified-and-gzipped.css.gz'); } }) })