gulp-minify-css
Advanced tools
Comparing version 1.0.0 to 1.1.0
31
index.js
@@ -12,19 +12,2 @@ 'use strict'; | ||
function sourceMap(file, map) { | ||
map.file = path.relative(file.base, file.path); | ||
map.sources = map.sources.map(function(src) { | ||
if (src === '__stdin__.css') { | ||
return path.relative(file.base, file.path); | ||
} else if (path.resolve(src) === path.normalize(src)) { | ||
// Path is absolute so imported file had no existing source map. | ||
// Trun absolute path in to path relative to file.base. | ||
return path.relative(file.base, src); | ||
} else { | ||
return src; | ||
} | ||
}); | ||
applySourceMap(file, map); | ||
} | ||
module.exports = function gulpMinifyCSS(options) { | ||
@@ -54,5 +37,13 @@ options = options || {}; | ||
if (css.sourceMap && file.sourceMap) { | ||
// clean-css gives bad 'sources' and 'file' properties because we | ||
// pass in raw css instead of a file. So we fix those here. | ||
sourceMap(file, JSON.parse(css.sourceMap)); | ||
var map = JSON.parse(css.sourceMap); | ||
map.file = path.relative(file.base, file.path); | ||
map.sources = map.sources.map(function(src) { | ||
if (/^(https?:)?\/\//.test(src)) { | ||
return src; | ||
} | ||
return path.relative(file.base, src === '$stdin' ? file.path : src); | ||
}); | ||
applySourceMap(file, map); | ||
} | ||
@@ -59,0 +50,0 @@ |
{ | ||
"name": "gulp-minify-css", | ||
"description": "Minify css with clean-css.", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"repository": "jonathanepollack/gulp-minify-css", | ||
"author": "Jonathan Pollack <jonathan@gnobel.com> (gnobel.com)", | ||
"contributors": [ | ||
"Shinnosuke Watanabe <snnskwtnb@gmail.com> (github.com/shinnn)" | ||
], | ||
"keywords": [ | ||
@@ -41,3 +45,3 @@ "gulpplugin", | ||
"chai": "^2.1.0", | ||
"eslint": "^0.16.1", | ||
"eslint": "^0.19.0", | ||
"gulp": "^3.8.8", | ||
@@ -50,3 +54,3 @@ "gulp-sourcemaps": "^1.5.0", | ||
"mocha": "^2.2.1", | ||
"simple-bufferstream": "0.0.4", | ||
"simple-bufferstream": "1.0.0", | ||
"stream-combiner2": "^1.0.2", | ||
@@ -53,0 +57,0 @@ "vinyl": "^0.4.6" |
@@ -0,1 +1,3 @@ | ||
# gulp-minify-css | ||
[![Build Status](https://travis-ci.org/jonathanepollack/gulp-minify-css.svg?branch=master)](https://travis-ci.org/jonathanepollack/gulp-minify-css) | ||
@@ -5,66 +7,45 @@ [![Build status](https://ci.appveyor.com/api/projects/status/eidg7ju694an2i74?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/gulp-minify-css) | ||
[gulp](http://gulpjs.com/) plugin to minify CSS, using [clean-css] | ||
## Regarding Issues | ||
This is just a simple gulp plugin, which means it's nothing more than a thin wrapper around `clean-css`. If it looks like you are having CSS related issues, please contact <a href="https://github.com/GoalSmashers/clean-css">clean-css</a>. Only create a new issue if it looks like you're having a problem with the plugin itself. | ||
This is just a simple [gulp](https://github.com/gulpjs/gulp) plugin, which means it's nothing more than a thin wrapper around `clean-css`. If it looks like you are having CSS related issues, please contact [clean-css]. Only create a new issue if it looks like you're having a problem with the plugin itself. | ||
## Information | ||
## Installation | ||
<table> | ||
<tr> | ||
<td>Package</td><td>gulp-minify-css</td> | ||
</tr> | ||
<tr> | ||
<td>Description</td> | ||
<td>Minify css with <a href="https://github.com/GoalSmashers/clean-css">clean-css</a>, including optional caching.</td> | ||
</tr> | ||
<tr> | ||
<td>Node Version</td> | ||
<td>>= 0.10</td> | ||
</tr> | ||
</table> | ||
[Use npm.](https://docs.npmjs.com/cli/install) | ||
## Installion | ||
```sh | ||
``` | ||
npm install --save-dev gulp-minify-css | ||
``` | ||
## Usage | ||
## API | ||
```js | ||
var gulp = require('gulp'), | ||
minifyCSS = require('gulp-minify-css'); | ||
```javascript | ||
var minifyCss = require('gulp-minify-css'); | ||
``` | ||
### minifyCss([*options*]) | ||
*options*: `Object` | ||
Return: `Object` ([stream.Tansform](https://nodejs.org/docs/latest/api/stream.html#stream_class_stream_transform)) | ||
Options are directly passed to [clean-css](https://github.com/jakubpawlowicz/clean-css#how-to-use-clean-css-programmatically) so all clean-css options are available. | ||
```javascript | ||
var gulp = require('gulp'); | ||
var minifyCss = require('gulp-minify-css'); | ||
gulp.task('minify-css', function() { | ||
return gulp.src('./static/css/*.css') | ||
.pipe(minifyCSS({keepBreaks:true})) | ||
.pipe(gulp.dest('./dist/')) | ||
return gulp.src('styles/*.css') | ||
.pipe(minifyCss({compatibility: 'ie8'})) | ||
.pipe(gulp.dest('dist')); | ||
}); | ||
``` | ||
### Options | ||
* `advanced` - set to false to disable advanced optimizations - selector & property merging, reduction, etc. | ||
* `aggressiveMerging` - set to false to disable aggressive merging of properties. | ||
* `benchmark` - turns on benchmarking mode measuring time spent on cleaning up (run `npm run bench` to see example) | ||
* `compatibility` - enables compatibility mode, see [full README for more examples](https://github.com/jakubpawlowicz/clean-css/blob/master/README.md#how-to-set-compatibility-mode) | ||
* `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) | ||
* `keepSpecialComments` - `*` for keeping all (default), `1` for keeping first one only, `0` for removing all | ||
* `processImport` - whether to process `@import` rules | ||
* `rebase` - set to false to skip URL rebasing | ||
* `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`; `-1` disables rounding | ||
* `shorthandCompacting` - set to false to skip shorthand compacting (default is true unless sourceMap is set when it's false) | ||
[Source Maps](http://www.html5rocks.com/tutorials/developertools/sourcemaps/) can be generated by using [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps). | ||
Source: [clean-css](https://github.com/jakubpawlowicz/clean-css/blob/master/README.md) | ||
### Source maps | ||
Source maps can be generated by using [gulp-sourcemaps](https://www.npmjs.com/package/gulp-sourcemaps): | ||
```js | ||
```javascript | ||
var gulp = require('gulp'); | ||
var minifyCSS = require('gulp-minify-css'); | ||
var minifyCss = require('gulp-minify-css'); | ||
var sourcemaps = require('gulp-sourcemaps'); | ||
@@ -75,3 +56,3 @@ | ||
.pipe(sourcemaps.init()) | ||
.pipe(minifyCSS()) | ||
.pipe(minifyCss()) | ||
.pipe(sourcemaps.write()) | ||
@@ -81,6 +62,3 @@ .pipe(gulp.dest('dist')); | ||
``` | ||
#### Caveats | ||
When minifying (and import inlining) files with existing source map, be aware clean-css doesn't yet support source maps with inline source (`sourcesContent` property).. See [#397](https://github.com/GoalSmashers/clean-css/issues/397). As such ensure that incoming source maps have properly set `sourceRoot` and `soureces` values to map back to the original source files. | ||
## LICENSE | ||
@@ -110,1 +88,3 @@ | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
[clean-css]: https://github.com/jakubpawlowicz/clean-css |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
5
2
8780
52
87