gulp-purgecss
Advanced tools
Comparing version 0.12.0 to 0.13.0
import through from 'through2'; | ||
import gulpUtil from 'gulp-util'; | ||
import Purgecss from 'purgecss'; | ||
import glob from 'glob'; | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
var PLUGIN_NAME = 'gulp-purgecss'; | ||
var getFiles = function getFiles(contentArray) { | ||
return contentArray.reduce(function (acc, content) { | ||
return [].concat(toConsumableArray(acc), toConsumableArray(glob.sync(content))); | ||
}, []); | ||
}; | ||
var gulpPurgecss = function gulpPurgecss(options) { | ||
return through.obj(function (file, encoding, callback) { | ||
var _this = this; | ||
return through.obj(function (file, encoding, callback) { | ||
var _this = this; | ||
// empty | ||
if (file.isNull()) return callback(null, file); | ||
// buffer | ||
if (file.isBuffer()) { | ||
try { | ||
var optionsGulp = Object.assign(options, { | ||
css: [file.contents.toString()], | ||
stdin: true | ||
}); | ||
var result = new Purgecss(optionsGulp).purge()[0].css; | ||
file.contents = new Buffer(result); | ||
callback(null, file); | ||
} catch (e) { | ||
this.emit('error', new gulpUtil.PluginError(PLUGIN_NAME, e.message)); | ||
} | ||
// empty | ||
if (file.isNull()) return callback(null, file); | ||
// buffer | ||
if (file.isBuffer()) { | ||
try { | ||
var optionsGulp = Object.assign(options, { | ||
content: getFiles(options.content), | ||
css: [file.contents.toString()], | ||
stdin: true | ||
}); | ||
var result = new Purgecss(optionsGulp).purge()[0].css; | ||
file.contents = new Buffer(result); | ||
callback(null, file); | ||
} catch (e) { | ||
this.emit('error', new gulpUtil.PluginError(PLUGIN_NAME, e.message)); | ||
} | ||
} | ||
// stream | ||
if (file.isStream()) { | ||
var css = ''; | ||
file.on('readable', function (buffer) { | ||
css += buffer.read().toString(); | ||
}).on('end', function () { | ||
try { | ||
var _optionsGulp = Object.assign(options, { css: [css] }); | ||
var _result = new Purgecss(_optionsGulp).purge()[0].css; | ||
file.contents = new Buffer(_result); | ||
callback(null, file); | ||
} catch (e) { | ||
_this.emit('error', new gulpUtil.PluginError(PLUGIN_NAME, e.message)); | ||
} | ||
// stream | ||
if (file.isStream()) { | ||
var css = ''; | ||
file.on('readable', function (buffer) { | ||
css += buffer.read().toString(); | ||
}).on('end', function () { | ||
try { | ||
var _optionsGulp = Object.assign(options, { css: [css] }); | ||
var _result = new Purgecss(_optionsGulp).purge()[0].css; | ||
file.contents = new Buffer(_result); | ||
callback(null, file); | ||
} catch (e) { | ||
_this.emit('error', new gulpUtil.PluginError(PLUGIN_NAME, e.message)); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
}; | ||
export default gulpPurgecss; |
@@ -8,44 +8,62 @@ 'use strict'; | ||
var Purgecss = _interopDefault(require('purgecss')); | ||
var glob = _interopDefault(require('glob')); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
var PLUGIN_NAME = 'gulp-purgecss'; | ||
var getFiles = function getFiles(contentArray) { | ||
return contentArray.reduce(function (acc, content) { | ||
return [].concat(toConsumableArray(acc), toConsumableArray(glob.sync(content))); | ||
}, []); | ||
}; | ||
var gulpPurgecss = function gulpPurgecss(options) { | ||
return through.obj(function (file, encoding, callback) { | ||
var _this = this; | ||
return through.obj(function (file, encoding, callback) { | ||
var _this = this; | ||
// empty | ||
if (file.isNull()) return callback(null, file); | ||
// buffer | ||
if (file.isBuffer()) { | ||
try { | ||
var optionsGulp = Object.assign(options, { | ||
css: [file.contents.toString()], | ||
stdin: true | ||
}); | ||
var result = new Purgecss(optionsGulp).purge()[0].css; | ||
file.contents = new Buffer(result); | ||
callback(null, file); | ||
} catch (e) { | ||
this.emit('error', new gulpUtil.PluginError(PLUGIN_NAME, e.message)); | ||
} | ||
// empty | ||
if (file.isNull()) return callback(null, file); | ||
// buffer | ||
if (file.isBuffer()) { | ||
try { | ||
var optionsGulp = Object.assign(options, { | ||
content: getFiles(options.content), | ||
css: [file.contents.toString()], | ||
stdin: true | ||
}); | ||
var result = new Purgecss(optionsGulp).purge()[0].css; | ||
file.contents = new Buffer(result); | ||
callback(null, file); | ||
} catch (e) { | ||
this.emit('error', new gulpUtil.PluginError(PLUGIN_NAME, e.message)); | ||
} | ||
} | ||
// stream | ||
if (file.isStream()) { | ||
var css = ''; | ||
file.on('readable', function (buffer) { | ||
css += buffer.read().toString(); | ||
}).on('end', function () { | ||
try { | ||
var _optionsGulp = Object.assign(options, { css: [css] }); | ||
var _result = new Purgecss(_optionsGulp).purge()[0].css; | ||
file.contents = new Buffer(_result); | ||
callback(null, file); | ||
} catch (e) { | ||
_this.emit('error', new gulpUtil.PluginError(PLUGIN_NAME, e.message)); | ||
} | ||
// stream | ||
if (file.isStream()) { | ||
var css = ''; | ||
file.on('readable', function (buffer) { | ||
css += buffer.read().toString(); | ||
}).on('end', function () { | ||
try { | ||
var _optionsGulp = Object.assign(options, { css: [css] }); | ||
var _result = new Purgecss(_optionsGulp).purge()[0].css; | ||
file.contents = new Buffer(_result); | ||
callback(null, file); | ||
} catch (e) { | ||
_this.emit('error', new gulpUtil.PluginError(PLUGIN_NAME, e.message)); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
}; | ||
module.exports = gulpPurgecss; |
{ | ||
"name": "gulp-purgecss", | ||
"version": "0.12.0", | ||
"version": "0.13.0", | ||
"description": "Gulp plugin for purgecss", | ||
@@ -10,3 +10,4 @@ "main": "./lib/gulpPurgecss.js", | ||
"lib": "lib", | ||
"test": "__tests__" | ||
"test": "__tests__", | ||
"example": "example" | ||
}, | ||
@@ -17,3 +18,4 @@ "scripts": { | ||
"lint": "eslint -c .eslintrc src/", | ||
"prettier": "npx prettier --write --print-width 100 --tab-width 4 --no-semi --single-quote src/index.js" | ||
"prettier": | ||
"npx prettier --write --print-width 100 --tab-width 2 --no-semi --single-quote src/index.js" | ||
}, | ||
@@ -24,10 +26,3 @@ "repository": { | ||
}, | ||
"keywords": [ | ||
"gulpplugin", | ||
"purgecss", | ||
"optimize", | ||
"remove", | ||
"css", | ||
"unused" | ||
], | ||
"keywords": ["gulpplugin", "purgecss", "optimize", "remove", "css", "unused"], | ||
"author": "Ffloriel", | ||
@@ -45,5 +40,5 @@ "license": "MIT", | ||
"prettier": "^1.8.2", | ||
"rollup": "^0.51.8", | ||
"rollup": "^0.52.0", | ||
"rollup-plugin-babel": "^3.0.2", | ||
"rollup-plugin-commonjs": "^8.2.3", | ||
"rollup-plugin-commonjs": "^8.2.6", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
@@ -53,6 +48,7 @@ "vinyl": "^2.1.0" | ||
"dependencies": { | ||
"glob": "^7.1.2", | ||
"gulp-util": "^3.0.8", | ||
"purgecss": "^0.12.0", | ||
"purgecss": "^0.13.0", | ||
"through2": "^2.0.3" | ||
} | ||
} |
@@ -1,20 +0,20 @@ | ||
import babel from "rollup-plugin-babel" | ||
import commonjs from "rollup-plugin-commonjs" | ||
import resolve from "rollup-plugin-node-resolve" | ||
import babel from 'rollup-plugin-babel' | ||
import commonjs from 'rollup-plugin-commonjs' | ||
import resolve from 'rollup-plugin-node-resolve' | ||
export default { | ||
input: "src/index.js", | ||
output: [ | ||
{ | ||
file: "lib/gulpPurgecss.es.js", | ||
format: "es" | ||
}, | ||
{ | ||
file: "lib/gulpPurgecss.js", | ||
format: "cjs" | ||
} | ||
], | ||
plugins: [resolve(), commonjs(), babel()], | ||
external: ["through2", "gulp-util", "purgecss"], | ||
sourceMap: false | ||
} | ||
input: 'src/index.js', | ||
output: [ | ||
{ | ||
file: 'lib/gulpPurgecss.es.js', | ||
format: 'es' | ||
}, | ||
{ | ||
file: 'lib/gulpPurgecss.js', | ||
format: 'cjs' | ||
} | ||
], | ||
plugins: [resolve(), commonjs(), babel()], | ||
external: ['through2', 'gulp-util', 'purgecss', 'glob'], | ||
sourceMap: false | ||
} |
import through from 'through2' | ||
import gulpUtil from 'gulp-util' | ||
import Purgecss from 'purgecss' | ||
import glob from 'glob' | ||
const PLUGIN_NAME = 'gulp-purgecss' | ||
const getFiles = contentArray => | ||
contentArray.reduce((acc, content) => { | ||
return [...acc, ...glob.sync(content)] | ||
}, []) | ||
const gulpPurgecss = options => { | ||
return through.obj(function(file, encoding, callback) { | ||
// empty | ||
if (file.isNull()) return callback(null, file) | ||
// buffer | ||
if (file.isBuffer()) { | ||
try { | ||
const optionsGulp = Object.assign(options, { | ||
css: [file.contents.toString()], | ||
stdin: true | ||
}) | ||
const result = new Purgecss(optionsGulp).purge()[0].css | ||
file.contents = new Buffer(result) | ||
callback(null, file) | ||
} catch (e) { | ||
this.emit('error', new gulpUtil.PluginError(PLUGIN_NAME, e.message)) | ||
} | ||
} | ||
// stream | ||
if (file.isStream()) { | ||
var css = '' | ||
file | ||
.on('readable', buffer => { | ||
css += buffer.read().toString() | ||
}) | ||
.on('end', () => { | ||
try { | ||
const optionsGulp = Object.assign(options, { css: [css] }) | ||
const result = new Purgecss(optionsGulp).purge()[0].css | ||
file.contents = new Buffer(result) | ||
callback(null, file) | ||
} catch (e) { | ||
this.emit('error', new gulpUtil.PluginError(PLUGIN_NAME, e.message)) | ||
} | ||
}) | ||
} | ||
}) | ||
return through.obj(function(file, encoding, callback) { | ||
// empty | ||
if (file.isNull()) return callback(null, file) | ||
// buffer | ||
if (file.isBuffer()) { | ||
try { | ||
const optionsGulp = Object.assign(options, { | ||
content: getFiles(options.content), | ||
css: [file.contents.toString()], | ||
stdin: true | ||
}) | ||
const result = new Purgecss(optionsGulp).purge()[0].css | ||
file.contents = new Buffer(result) | ||
callback(null, file) | ||
} catch (e) { | ||
this.emit('error', new gulpUtil.PluginError(PLUGIN_NAME, e.message)) | ||
} | ||
} | ||
// stream | ||
if (file.isStream()) { | ||
var css = '' | ||
file | ||
.on('readable', buffer => { | ||
css += buffer.read().toString() | ||
}) | ||
.on('end', () => { | ||
try { | ||
const optionsGulp = Object.assign(options, { css: [css] }) | ||
const result = new Purgecss(optionsGulp).purge()[0].css | ||
file.contents = new Buffer(result) | ||
callback(null, file) | ||
} catch (e) { | ||
this.emit('error', new gulpUtil.PluginError(PLUGIN_NAME, e.message)) | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
export default gulpPurgecss |
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
Mixed license
License(Experimental) Package contains multiple licenses.
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
18354
23
248
4
1
+ Addedglob@^7.1.2
+ Addedpurgecss@0.13.1(transitive)
- Removedpurgecss@0.12.0(transitive)
Updatedpurgecss@^0.13.0