Comparing version
@@ -39,3 +39,3 @@ #!/usr/bin/env node | ||
} | ||
write(out, nano(String(buf), opts)); | ||
write(out, nano.process(String(buf), opts)); | ||
}); |
@@ -7,2 +7,4 @@ Usage: cssnano [input] [output] {OPTIONS} | ||
--no-autoprefixer Disable removal of old vendor prefixed properties. | ||
--no-zindex Disable z-index transforms. | ||
@@ -9,0 +11,0 @@ |
@@ -0,1 +1,13 @@ | ||
# 2.0.0 | ||
* Adds removal of outdated vendor prefixes based on browser support. | ||
* Addresses an issue where relative path separators were converted to | ||
backslashes on Windows. | ||
* cssnano will now detect previous plugins and silently disable them when the | ||
functionality overlaps. This is to enable faster interoperation with cssnext. | ||
* cssnano now exports as a PostCSS plugin. The simple interface is exposed | ||
at `cssnano.process(css, opts)` instead of `cssnano(css, opts)`. | ||
* Improved URL detection when using two or more in the same declaration. | ||
* node 0.10 is no longer officially supported. | ||
# 1.4.3 | ||
@@ -2,0 +14,0 @@ |
41
index.js
@@ -6,3 +6,5 @@ 'use strict'; | ||
var processors = { | ||
pluginFilter: require('./lib/pluginFilter'), | ||
discardComments: {fn: require('postcss-discard-comments'), ns: 'comments'}, | ||
autoprefixer: {fn: require('autoprefixer-core'), ns: 'autoprefixer'}, | ||
zindex: {fn: require('postcss-zindex'), ns: 'zindex'}, | ||
@@ -35,11 +37,5 @@ discardEmpty: require('postcss-discard-empty'), | ||
module.exports = function cssnano(css, options) { | ||
if (typeof css === 'object') { | ||
options = css; | ||
css = null; | ||
} | ||
var cssnano = Postcss.plugin('cssnano', function (options) { | ||
options = options || {}; | ||
options = typeof options === 'object' ? options : {}; | ||
options.map = options.map || (options.sourcemap ? true : null); | ||
var postcss = Postcss(); | ||
@@ -61,2 +57,5 @@ var plugins = Object.keys(processors); | ||
} | ||
if (plugin === 'autoprefixer') { | ||
opts.add = false; | ||
} | ||
method = processor.fn; | ||
@@ -67,13 +66,17 @@ } | ||
if (typeof css === 'string') { | ||
var result = postcss.process(css, options); | ||
// return a css string if inline/no sourcemap. | ||
if (options.map === null || options.map === true || (options.map && options.map.inline)) { | ||
return result.css; | ||
} | ||
// otherwise return an object of css & map | ||
return result; | ||
return postcss; | ||
}); | ||
module.exports = cssnano; | ||
module.exports.process = function (css, options) { | ||
options = options || {}; | ||
options.map = options.map || (options.sourcemap ? true : null); | ||
var result = Postcss([cssnano(options)]).process(css, options); | ||
// return a css string if inline/no sourcemap. | ||
if (options.map === null || options.map === true || (options.map && options.map.inline)) { | ||
return result.css; | ||
} | ||
return postcss; | ||
}; | ||
// otherwise return an object of css & map | ||
return result; | ||
} |
{ | ||
"name": "cssnano", | ||
"version": "1.4.3", | ||
"version": "2.0.0", | ||
"description": "A modular minifier, built on top of the PostCSS ecosystem.", | ||
@@ -10,2 +10,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test-cli": "tape tests/cli.js", | ||
"test-integrations": "tape tests/integrations.js", | ||
@@ -26,2 +27,3 @@ "test-fixtures": "tape tests/fixtures.js | faucet", | ||
"dependencies": { | ||
"autoprefixer-core": "^5.2.0", | ||
"balanced-match": "^0.2.0", | ||
@@ -32,8 +34,8 @@ "css-list": "^0.1.0", | ||
"minimist": "^1.1.1", | ||
"postcss": "^4.1.8", | ||
"postcss-calc": "^4.0.1", | ||
"postcss-colormin": "^1.2.2", | ||
"postcss-convert-values": "^1.2.1", | ||
"postcss-discard-comments": "^1.1.2", | ||
"postcss-discard-duplicates": "^1.1.2", | ||
"postcss": "^4.1.11", | ||
"postcss-calc": "^4.1.0", | ||
"postcss-colormin": "^1.2.3", | ||
"postcss-convert-values": "^1.2.2", | ||
"postcss-discard-comments": "^1.2.0", | ||
"postcss-discard-duplicates": "^1.1.3", | ||
"postcss-discard-empty": "^1.1.0", | ||
@@ -44,10 +46,10 @@ "postcss-discard-unused": "^1.0.0", | ||
"postcss-merge-rules": "^1.3.0", | ||
"postcss-minify-font-weight": "^1.0.0", | ||
"postcss-minify-font-weight": "^1.0.1", | ||
"postcss-minify-selectors": "^1.4.1", | ||
"postcss-normalize-url": "^1.2.1", | ||
"postcss-pseudoelements": "^2.1.1", | ||
"postcss-reduce-idents": "^1.0.0", | ||
"postcss-single-charset": "^0.2.2", | ||
"postcss-normalize-url": "^2.0.2", | ||
"postcss-pseudoelements": "^2.2.0", | ||
"postcss-reduce-idents": "^1.0.1", | ||
"postcss-single-charset": "^0.3.0", | ||
"postcss-unique-selectors": "^1.0.0", | ||
"postcss-zindex": "^1.1.1", | ||
"postcss-zindex": "^1.1.2", | ||
"read-file-stdin": "^0.2.0", | ||
@@ -62,3 +64,3 @@ "write-file-stdout": "0.0.2" | ||
"tape": "^4.0.0", | ||
"webpack": "^1.9.10" | ||
"webpack": "^1.9.11" | ||
}, | ||
@@ -65,0 +67,0 @@ "homepage": "https://github.com/ben-eb/cssnano", |
196
README.md
@@ -1,8 +0,12 @@ | ||
# cssnano [][ci] [][npm] [][deps] [](https://gitter.im/ben-eb/cssnano?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
<h1 align="center"> | ||
<br> | ||
<img width="360" src="https://rawgit.com/ben-eb/cssnano/master/media/logo.svg" alt="cssnano"> | ||
<br> | ||
<br> | ||
<br> | ||
</h1> | ||
> A modular minifier, built on top of the [PostCSS] ecosystem. | ||
*Note that this project is still a work in progress, and needs more testing | ||
before it can be recommended to use in production. There are some optimisations | ||
that need to be further expanded upon, and others yet to be written.* | ||
[][ci] [](https://ci.appveyor.com/project/ben-eb/cssnano/branch/master) [][npm] [][deps] [](https://gitter.im/ben-eb/cssnano?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
@@ -16,160 +20,8 @@ cssnano is a modular minifier that aims to utilise small modules from the | ||
## Install | ||
For further details check out the [website](http://cssnano.co/): | ||
With [npm](https://npmjs.org/package/cssnano) do: | ||
* [Installation guide for your build process](http://cssnano.co/usage/). | ||
* [Full list of optimisations](http://cssnano.co/optimisations/). | ||
* [Customise the output (options documentation)](http://cssnano.co/options/). | ||
``` | ||
npm install cssnano | ||
``` | ||
## Usage | ||
### CLI | ||
cssnano ships with a command line app. | ||
``` | ||
cssnano main.css | ||
``` | ||
To output this to a file specify a second parameter: | ||
``` | ||
cssnano main.css main.min.css | ||
``` | ||
You can also use stdin & stdout redirections: | ||
``` | ||
cssnano < main.css > main.min.css | ||
``` | ||
To see all available options, do: | ||
``` | ||
cssnano --help | ||
``` | ||
### gulp | ||
Use [`gulp-cssnano`]. | ||
### grunt | ||
Use [`grunt-cssnano`]. | ||
### broccoli | ||
Use [`broccoli-cssnano`]. | ||
### Scripting | ||
cssnano can be used directly via its node.js API, or consumed as a PostCSS | ||
plugin. | ||
#### node.js (`nano(css, [options])`) | ||
```js | ||
var nano = require('cssnano'); | ||
var readFile = require('fs').readFileSync; | ||
var writeFile = require('fs').writeFileSync; | ||
var input = readFile('main.css', 'utf8'); | ||
writeFile('main.min.css', nano(input)); | ||
``` | ||
#### PostCSS (`nano([options])`) | ||
```js | ||
var nano = require('cssnano'); | ||
var readFile = require('fs').readFileSync; | ||
var writeFile = require('fs').writeFileSync; | ||
var postcss = require('postcss'); | ||
var input = readFile('main.css', 'utf8'); | ||
var output = postcss().use(nano()).use(/* other plugin */).process(input).css; | ||
writeFile('main.min.css', output); | ||
``` | ||
#### Options | ||
##### sourcemap | ||
Set this to `true` to generate an inline source map. | ||
##### zindex | ||
Set this to `false` to disable z-index transforms. | ||
##### calc | ||
Set this to `false` to disable calc transforms. If it is an object, it will be | ||
passed as the options to [`postcss-calc`]. | ||
##### urls | ||
Set this to `false` to disable URL normalisation. If it is an object, it will be | ||
passed as the options to [`postcss-normalize-url`]. | ||
##### idents | ||
Set this to `false` to disable custom identifier reduction. | ||
##### merge | ||
Set this to `false` to disable merging of rules. | ||
##### unused | ||
Set this to `false` to disable unused at-rule removal. | ||
##### comments | ||
If this is an object, it will be passed as the options to | ||
[`postcss-discard-comments`]. | ||
## Motivation | ||
As of this writing, there are *many* ways to minify CSS available; for the Node | ||
ecosystem alone, there are lots of [modules] that offer this functionality. | ||
However, some of these projects are buggy and others are not being maintained. | ||
Furthermore, it is difficult to contribute to such projects with large amounts | ||
of integrated code. What if we could utilise the power of modularity and split | ||
up a CSS minifier into small pieces that have single responsibility? This | ||
project's aim is, eventually, to become entirely composed of node modules that | ||
are responsible for small CSS optimisations. At present, it is composed of the | ||
following modules: | ||
* [`postcss-calc`]: Convert `calc()` functions where possible. | ||
`calc(5 * 10px)` -> `50px` | ||
* [`postcss-colormin`]: Convert colors into their smallest representation. | ||
`#ff0000` -> `red` | ||
* [`postcss-convert-values`]: Convert time/length values. | ||
`500ms` -> `.5s` | ||
* [`postcss-discard-comments`]: Discard comments, unless marked as special. | ||
* [`postcss-discard-duplicates`]: Discard duplicate rules. | ||
* [`postcss-discard-empty`]: Discard empty rules and media queries. | ||
* [`postcss-discard-unused`]: Discard unused at-rules. | ||
* [`postcss-font-family`]: Optimise whitespace/quoting of `font-family` | ||
properties. | ||
* [`postcss-merge-idents`]: Merge duplicated `@keyframes` and `@counter-style` | ||
identifiers with different names. | ||
* [`postcss-merge-rules`]: Merge adjacent rules together. | ||
* [`postcss-minify-font-weight`]: Convert `bold` -> `700` and `normal` -> `400` | ||
* [`postcss-minify-selectors`]: Optimise whitespace/quoting of selectors. | ||
* [`postcss-normalize-url`]: Optimise URL representations. | ||
* [`postcss-pseudoelements`]: Optimise double colon pseudo syntax to the single | ||
colon syntax. | ||
* [`postcss-reduce-idents`]: Rename `@keyframes`, `@counter-style` and `counter` | ||
identifiers to save space. | ||
* [`postcss-single-charset`]: Ensure that there is only one `@charset` in the | ||
CSS file. | ||
* [`postcss-unique-selectors`]: Ensure selectors are unique. | ||
* [`postcss-zindex`]: Rebase `z-index` values to save space. | ||
There are some optimisations that are not quite ready to be released as | ||
separate modules yet, and these are still integrated into this module. | ||
## Contributing | ||
@@ -184,30 +36,6 @@ | ||
[modules]: https://github.com/ben-eb/css-minifiers | ||
[PostCSS]: https://github.com/postcss/postcss | ||
[`postcss-calc`]: https://github.com/postcss/postcss-calc | ||
[`postcss-colormin`]: https://github.com/ben-eb/postcss-colormin | ||
[`postcss-convert-values`]: https://github.com/ben-eb/postcss-convert-values | ||
[`postcss-discard-comments`]: https://github.com/ben-eb/postcss-discard-comments | ||
[`postcss-discard-duplicates`]: https://github.com/ben-eb/postcss-discard-duplicates | ||
[`postcss-discard-empty`]: https://github.com/ben-eb/postcss-discard-empty | ||
[`postcss-discard-unused`]: https://github.com/ben-eb/postcss-discard-unused | ||
[`postcss-font-family`]: https://github.com/ben-eb/postcss-font-family | ||
[`postcss-merge-idents`]: https://github.com/ben-eb/postcss-merge-idents | ||
[`postcss-merge-rules`]: https://github.com/ben-eb/postcss-merge-rules | ||
[`postcss-minify-font-weight`]: https://github.com/ben-eb/postcss-minify-font-weight | ||
[`postcss-minify-selectors`]: https://github.com/ben-eb/postcss-minify-selectors | ||
[`postcss-normalize-url`]: https://github.com/ben-eb/postcss-normalize-url | ||
[`postcss-pseudoelements`]: https://github.com/axa-ch/postcss-pseudoelements | ||
[`postcss-reduce-idents`]: https://github.com/ben-eb/postcss-reduce-idents | ||
[`postcss-single-charset`]: https://github.com/hail2u/postcss-single-charset | ||
[`postcss-unique-selectors`]: https://github.com/ben-eb/postcss-unique-selectors | ||
[`postcss-zindex`]: https://github.com/ben-eb/postcss-zindex | ||
[`gulp-cssnano`]: https://github.com/ben-eb/gulp-cssnano | ||
[`grunt-cssnano`]: https://github.com/sindresorhus/grunt-cssnano | ||
[`broccoli-cssnano`]: https://github.com/sindresorhus/broccoli-cssnano | ||
[ci]: https://travis-ci.org/ben-eb/cssnano | ||
[deps]: https://gemnasium.com/ben-eb/cssnano | ||
[npm]: http://badge.fury.io/js/cssnano |
Sorry, the diff of this file is not supported yet
22
10%488
6.55%27734
-0.07%27
3.85%40
-81.13%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated
Updated
Updated