gulp-clean-css
Advanced tools
Comparing version 1.0.2 to 2.0.0
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) |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
0
59
5818
6
4
61
1
2
+ Addedobject-assign@^4.0.1
+ Addedreadable-stream@^2.0.0
+ Addedvinyl-bufferstream@^1.0.1
+ Addedamdefine@1.0.1(transitive)
+ Addedansi-gray@0.1.1(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedansi-wrap@0.1.0(transitive)
+ Addedarray-differ@1.0.0(transitive)
+ Addedarray-uniq@1.0.3(transitive)
+ Addedbeeper@1.1.1(transitive)
+ Addedbufferstreams@1.0.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedclean-css@3.4.28(transitive)
+ Addedclone@1.0.4(transitive)
+ Addedcolor-support@1.1.3(transitive)
+ Addedcommander@2.8.1(transitive)
+ Addeddateformat@2.2.0(transitive)
+ Addedfancy-log@1.3.3(transitive)
+ Addedglogg@1.0.2(transitive)
+ Addedgraceful-readlink@1.0.1(transitive)
+ Addedgulp-util@3.0.8(transitive)
+ Addedgulplog@1.0.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhas-gulplog@0.1.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedlodash._basecopy@3.0.1(transitive)
+ Addedlodash._basetostring@3.0.1(transitive)
+ Addedlodash._basevalues@3.0.0(transitive)
+ Addedlodash._getnative@3.9.1(transitive)
+ Addedlodash._isiterateecall@3.0.9(transitive)
+ Addedlodash._reescape@3.0.0(transitive)
+ Addedlodash._reevaluate@3.0.0(transitive)
+ Addedlodash._reinterpolate@3.0.0(transitive)
+ Addedlodash._root@3.0.1(transitive)
+ Addedlodash.escape@3.2.0(transitive)
+ Addedlodash.isarguments@3.1.0(transitive)
+ Addedlodash.isarray@3.0.4(transitive)
+ Addedlodash.keys@3.1.2(transitive)
+ Addedlodash.restparam@3.6.1(transitive)
+ Addedlodash.template@3.6.2(transitive)
+ Addedlodash.templatesettings@3.1.1(transitive)
+ Addedobject-assign@3.0.0(transitive)
+ Addedparse-node-version@1.0.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedreplace-ext@0.0.1(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsource-map@0.4.40.5.7(transitive)
+ Addedsparkles@1.0.1(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedthrough2@2.0.5(transitive)
+ Addedtime-stamp@1.1.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedvinyl@0.5.3(transitive)
+ Addedvinyl-bufferstream@1.0.1(transitive)
+ Addedvinyl-sourcemaps-apply@0.2.1(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedthrough2@~0.4.0
- Removedvinyl@~0.2.3
- Removedansi-regex@0.2.1(transitive)
- Removedansi-styles@1.1.0(transitive)
- Removedarray-find-index@1.0.2(transitive)
- Removedcamelcase@2.1.1(transitive)
- Removedcamelcase-keys@2.1.0(transitive)
- Removedchalk@0.5.1(transitive)
- Removedclean-css@2.1.8(transitive)
- Removedcommander@2.1.0(transitive)
- Removedcurrently-unhandled@0.4.1(transitive)
- Removeddateformat@1.0.12(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedfind-up@1.1.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedgulp-util@2.2.20(transitive)
- Removedhas-ansi@0.1.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedindent-string@2.1.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removedlodash._escapehtmlchar@2.4.1(transitive)
- Removedlodash._escapestringchar@2.4.1(transitive)
- Removedlodash._htmlescapes@2.4.1(transitive)
- Removedlodash._isnative@2.4.1(transitive)
- Removedlodash._objecttypes@2.4.1(transitive)
- Removedlodash._reinterpolate@2.4.1(transitive)
- Removedlodash._reunescapedhtml@2.4.1(transitive)
- Removedlodash._shimkeys@2.4.1(transitive)
- Removedlodash.defaults@2.4.1(transitive)
- Removedlodash.escape@2.4.1(transitive)
- Removedlodash.isobject@2.4.1(transitive)
- Removedlodash.keys@2.4.1(transitive)
- Removedlodash.template@2.4.1(transitive)
- Removedlodash.templatesettings@2.4.1(transitive)
- Removedlodash.values@2.4.1(transitive)
- Removedloud-rejection@1.6.0(transitive)
- Removedmap-obj@1.0.1(transitive)
- Removedmeow@3.7.0(transitive)
- Removedminimist@0.2.4(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removedobject-keys@0.4.0(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@1.1.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedread-pkg@1.1.0(transitive)
- Removedread-pkg-up@1.0.1(transitive)
- Removedreadable-stream@1.0.34(transitive)
- Removedredent@1.0.0(transitive)
- Removedrepeating@2.0.1(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsemver@5.7.2(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstrip-ansi@0.3.0(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedstrip-indent@1.0.1(transitive)
- Removedsupports-color@0.2.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedthrough2@0.4.20.5.1(transitive)
- Removedtrim-newlines@1.0.0(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
- Removedvinyl@0.2.3(transitive)
- Removedxtend@2.1.23.0.0(transitive)
Updatedclean-css@^3.4.9
Updatedgulp-util@^3.0.5