From 6b23dd574ea4727fb87e133ccde54c5272a381f6 Mon Sep 17 00:00:00 2001 From: Anil Mandepudi Date: Wed, 2 Nov 2016 14:57:14 -0700 Subject: [PATCH] Use postcss-clean to minify css instead of less (#5179) * use postcss-clean to minify css instead of less * alphabetical order * white space * white space * Update css.js --- package.json | 1 + src/meta/css.js | 24 +++++++++++------------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 9a596f1162..537079b392 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "passport": "^0.3.0", "passport-local": "1.0.0", "postcss": "^5.0.13", + "postcss-clean": "^1.0.0", "promise-polyfill": "^6.0.2", "prompt": "^1.0.0", "redis": "~2.6.2", diff --git a/src/meta/css.js b/src/meta/css.js index a2842c14e8..24f932f90e 100644 --- a/src/meta/css.js +++ b/src/meta/css.js @@ -8,6 +8,7 @@ var less = require('less'); var async = require('async'); var autoprefixer = require('autoprefixer'); var postcss = require('postcss'); +var clean = require('postcss-clean'); var plugins = require('../plugins'); var emitter = require('../emitter'); @@ -48,7 +49,7 @@ module.exports = function (Meta) { async.waterfall([ function (next) { - getStyleSource(plugins.cssFiles, '\n@import (less) ".', '.css', next); + getStyleSource(plugins.cssFiles, '\n@import (inline) ".', '.css', next); }, function (src, next) { source += src; @@ -65,10 +66,10 @@ module.exports = function (Meta) { var acpSource = source; - source += '\n@import (less) "..' + path.sep + '..' + path.sep + 'public/vendor/jquery/css/smoothness/jquery-ui.css";'; - source += '\n@import (less) "..' + path.sep + '..' + path.sep + 'public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.css";'; - source += '\n@import (less) "..' + path.sep + '..' + path.sep + 'node_modules/cookieconsent/build/cookieconsent.min.css";'; - source += '\n@import (less) "..' + path.sep + 'public/vendor/colorpicker/colorpicker.css";'; + source += '\n@import (inline) "..' + path.sep + '..' + path.sep + 'public/vendor/jquery/css/smoothness/jquery-ui.css";'; + source += '\n@import (inline) "..' + path.sep + '..' + path.sep + 'public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.css";'; + source += '\n@import (inline) "..' + path.sep + '..' + path.sep + 'node_modules/cookieconsent/build/cookieconsent.min.css";'; + source += '\n@import (inline) "..' + path.sep + 'public/vendor/colorpicker/colorpicker.css";'; source += '\n@import "..' + path.sep + '..' + path.sep + 'public/less/flags.less";'; source += '\n@import "..' + path.sep + '..' + path.sep + 'public/less/blacklist.less";'; source += '\n@import "..' + path.sep + '..' + path.sep + 'public/less/generics.less";'; @@ -78,9 +79,8 @@ module.exports = function (Meta) { acpSource += '\n@import "..' + path.sep + 'public/less/admin/admin";\n'; acpSource += '\n@import "..' + path.sep + 'public/less/generics.less";\n'; - acpSource += '\n@import (less) "..' + path.sep + 'public/vendor/colorpicker/colorpicker.css";\n'; - acpSource += '\n@import (less) "..' + path.sep + 'public/vendor/jquery/css/smoothness/jquery-ui.css";'; - + acpSource += '\n@import (inline) "..' + path.sep + 'public/vendor/colorpicker/colorpicker.css";\n'; + acpSource += '\n@import (inline) "..' + path.sep + 'public/vendor/jquery/css/smoothness/jquery-ui.css";'; var fromFile = nconf.get('from-file') || ''; @@ -182,8 +182,7 @@ module.exports = function (Meta) { function minify(source, paths, destination, callback) { less.render(source, { - paths: paths, - compress: true + paths: paths }, function (err, lessOutput) { if (err) { winston.error('[meta/css] Could not minify LESS/CSS: ' + err.message); @@ -193,11 +192,10 @@ module.exports = function (Meta) { return; } - postcss([ autoprefixer ]).process(lessOutput.css).then(function (result) { + postcss([ autoprefixer, clean() ]).process(lessOutput.css).then(function (result) { result.warnings().forEach(function (warn) { winston.verbose(warn.toString()); }); - Meta.css[destination] = result.css; // Save the compiled CSS in public/ so things like nginx can serve it @@ -226,4 +224,4 @@ module.exports = function (Meta) { return exists; }); } -}; \ No newline at end of file +};