From 8df2212187441ca3897ec5c32aa76731c0050917 Mon Sep 17 00:00:00 2001 From: Damian Krzeminski Date: Mon, 17 Dec 2018 21:53:34 -0700 Subject: [PATCH 1/2] suport minify option in filter using jstransformer that removes direct dependency on uglify-js and clean-css --- packages/pug-filters/lib/run-filter.js | 26 ++++++++++++++------------ packages/pug-filters/package.json | 4 +--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/pug-filters/lib/run-filter.js b/packages/pug-filters/lib/run-filter.js index a0cec0457..43ae4ca65 100644 --- a/packages/pug-filters/lib/run-filter.js +++ b/packages/pug-filters/lib/run-filter.js @@ -1,11 +1,17 @@ 'use strict'; var jstransformer = require('jstransformer'); -var uglify = require('uglify-js'); -var CleanCSS = require('clean-css'); var resolve = require('resolve'); module.exports = filter; + +function getMinifyTransformerName(outputFormat) { + switch (outputFormat) { + case 'js': return 'uglify-js'; + case 'css': return 'clean-css'; + } +} + function filter(name, str, options, currentDirectory, funcName) { funcName = funcName || 'render'; var trPath; @@ -24,17 +30,13 @@ function filter(name, str, options, currentDirectory, funcName) { // TODO: we may want to add a way for people to separately specify "locals" var result = tr[funcName](str, options, options).body; if (options && options.minify) { - try { - switch (tr.outputFormat) { - case 'js': - result = uglify.minify(result, {fromString: true}).code; - break; - case 'css': - result = new CleanCSS().minify(result).styles; - break; + var minifyTranformer = getMinifyTransformerName(tr.outputFormat); + if (minifyTranformer) { + try { + result = filter(minifyTranformer, result, null, currentDirectory); + } catch (ex) { + // better to fail to minify than output nothing } - } catch (ex) { - // better to fail to minify than output nothing } } return result; diff --git a/packages/pug-filters/package.json b/packages/pug-filters/package.json index ab640c0ff..576380248 100644 --- a/packages/pug-filters/package.json +++ b/packages/pug-filters/package.json @@ -6,13 +6,11 @@ "pug" ], "dependencies": { - "clean-css": "^4.1.11", "constantinople": "^3.0.1", "jstransformer": "1.0.0", "pug-error": "^1.3.2", "pug-walk": "^1.1.7", - "resolve": "^1.1.6", - "uglify-js": "^2.6.1" + "resolve": "^1.1.6" }, "devDependencies": { "get-repo": "^1.0.0", From ea3b864a260cf4517e24a7707280abe583dd0590 Mon Sep 17 00:00:00 2001 From: Forbes Lindesay Date: Fri, 1 May 2020 22:21:37 +0100 Subject: [PATCH 2/2] chore: run prettier --- packages/pug-filters/lib/run-filter.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/pug-filters/lib/run-filter.js b/packages/pug-filters/lib/run-filter.js index 2b9b90c02..f80bd0c0b 100644 --- a/packages/pug-filters/lib/run-filter.js +++ b/packages/pug-filters/lib/run-filter.js @@ -7,8 +7,10 @@ module.exports = filter; function getMinifyTransformerName(outputFormat) { switch (outputFormat) { - case 'js': return 'uglify-js'; - case 'css': return 'clean-css'; + case 'js': + return 'uglify-js'; + case 'css': + return 'clean-css'; } }