Socket
Socket
Sign inDemoInstall

gulp-clean-css

Package Overview
Dependencies
Maintainers
2
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-clean-css - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

LICENSE

94

index.js
'use strict';
// vim: ts=4 sw=4 noexpandtab
var through = require('through2'),
CleanCSS = require('clean-css'),
uglifyError = require('./lib/error.js');
var path = require('path');
module.exports = function(opt) {
if (!opt) opt = {};
var applySourceMap = require('vinyl-sourcemaps-apply');
var CleanCSS = require('clean-css');
var objectAssign = require('object-assign');
var PluginError = require('gulp-util').PluginError;
var Transform = require('readable-stream/transform');
var VinylBufferStream = require('vinyl-bufferstream');
function minify(file, encoding, callback) {
/*jshint validthis:true */
module.exports = function gulpCleanCSS(options) {
options = options || {};
if (file.isNull()) {
this.push(file);
return callback();
}
return new Transform({
objectMode: true,
transform: function modifyContents(file, enc, cb) {
var run = new VinylBufferStream(function(buf, done) {
var fileOptions = objectAssign({target: file.path}, options);
if (file.isStream()) {
return callback(uglifyError('Streaming not supported'));
}
// https://github.com/jakubpawlowicz/clean-css/blob/v3.3.0/bin/cleancss#L83-L84
if (fileOptions.relativeTo === undefined && (fileOptions.root || file.path)) {
fileOptions.relativeTo = path.dirname(path.resolve(options.root || file.path));
}
var mangled;
if ((options.sourceMap === true || options.sourceMap === undefined) && file.sourceMap) {
fileOptions.sourceMap = JSON.stringify(file.sourceMap);
}
try {
mangled = new CleanCSS(opt).minify(String(file.contents));
file.contents = new Buffer(mangled);
this.push(file);
} catch (e) {
console.warn('Error caught from clean-css: ' + e.message + ' in ' + file.path + '. Returning unminifed code');
this.push(file);
return callback();
}
var cssFile;
callback();
}
if (file.path) {
cssFile = {};
cssFile[file.path] = {styles: buf.toString()};
} else {
cssFile = buf.toString();
}
return through.obj(minify);
new CleanCSS(fileOptions).minify(cssFile, function(errors, css) {
if (errors) {
done(errors.join(' '));
return;
}
if (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);
});
applySourceMap(file, map);
}
done(null, new Buffer(css.styles));
});
});
var self = this;
run(file, function(err, contents) {
if (err) {
self.emit('error', new PluginError('gulp-clean-css', err, {fileName: file.path}));
} else {
file.contents = contents;
self.push(file);
}
cb();
});
}
});
};
{
"name": "gulp-clean-css",
"version": "1.0.2",
"description": "Minify files with CleanCSS",
"author": "Radosław Mejer <radmen@gmail.com>",
"description": "Minify css with clean-css.",
"version": "2.0.0",
"author": "scniro",
"license": "MIT",
"main": "index.js",
"scripts": {
"test": "tape test/*.js"
"repository": {
"type": "git",
"url": "https://github.com/scniro/gulp-clean-css.git"
},
"files": [
"index.js"
],
"dependencies": {
"gulp-util": "~2.2.14",
"through2": "~0.4.0",
"clean-css": "~2.1.8",
"vinyl": "~0.2.3"
"clean-css": "^3.4.9",
"gulp-util": "^3.0.5",
"object-assign": "^4.0.1",
"readable-stream": "^2.0.0",
"vinyl-bufferstream": "^1.0.1",
"vinyl-sourcemaps-apply": "^0.2.0"
},
"devDependencies": {
"tape": "~2.4.2"
},
"engines": {
"node": ">= 0.10"
},
"keywords": [
"gulpplugin"
],
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/radmen/gulp-clean-css/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/radmen/gulp-clean-css.git"
"gulp": "^3.9.1"
}
}
# gulp-clean-css
> Minify files with CleanCSS
> [gulp](http://gulpjs.com/) plugin to minify CSS, using [clean-css](https://github.com/jakubpawlowicz/clean-css)
# DEPRECATED
This package is marked as deprecated. Please use [jonathanepollack/gulp-minify-css](https://github.com/jonathanepollack/gulp-minify-css) instead.
## Regarding Issues
# Installation
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](https://github.com/jakubpawlowicz/clean-css/issues). Only create a new issue if it looks like you're having a problem with the plugin itself.
## Installation
```

@@ -15,18 +16,44 @@ npm install --save-dev gulp-clean-css

# Usage
## API
```javascript
var minify = require('gulp-clean-css');
var cleanCSS = require('gulp-clean-css');
```
gulp.task('compress', function() {
return gulp.src('assets/stylesheets/*.css')
.pipe(minify())
.pipe(gulp.dest('dist'))
### cleanCSS([*options*])
*options*: `Object`
Return: `Object` ([stream.Transform](https://nodejs.org/docs/latest/api/stream.html#stream_class_stream_transform))
Options are directly passed to the [`CleanCSS` constructor](https://github.com/jakubpawlowicz/clean-css#how-to-use-clean-css-api) so all the clean-css options are available.
```javascript
var gulp = require('gulp');
var cleanCSS = require('gulp-clean-css');
gulp.task('minify-css', function() {
return gulp.src('styles/*.css')
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(gulp.dest('dist'));
});
```
# Credits
[Source Maps](http://www.html5rocks.com/tutorials/developertools/sourcemaps/) can be generated by using [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps).
This package is heavily inspired (actually it's a clone..) by [terinjokes/gulp-uglify](https://github.com/terinjokes/gulp-uglify).
```javascript
var gulp = require('gulp');
var cleanCSS = require('gulp-clean-css');
var sourcemaps = require('gulp-sourcemaps');
Also take a look at [jonathanepollack/gulp-minify-css](https://github.com/jonathanepollack/gulp-minify-css). The only reason I made this clone is the fact that Node was throwing some low-level errors..
gulp.task('minify-css', function() {
return gulp.src('./src/*.css')
.pipe(sourcemaps.init())
.pipe(cleanCSS())
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist'));
});
```
## LICENSE
[MIT](./LICENSE) © 2016 [scniro](https://github.com/scniro)
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