diff --git a/packages/pug-filters/lib/run-filter.js b/packages/pug-filters/lib/run-filter.js index 5c58b484c..f80bd0c0b 100644 --- a/packages/pug-filters/lib/run-filter.js +++ b/packages/pug-filters/lib/run-filter.js @@ -1,11 +1,19 @@ '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; @@ -26,17 +34,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 f0166f4d5..3d5dea9e5 100644 --- a/packages/pug-filters/package.json +++ b/packages/pug-filters/package.json @@ -6,13 +6,11 @@ "pug" ], "dependencies": { - "clean-css": "^4.2.3", "constantinople": "^4.0.1", "jstransformer": "1.0.0", "pug-error": "^1.3.3", "pug-walk": "^1.1.8", - "resolve": "^1.15.1", - "uglify-js": "^2.6.1" + "resolve": "^1.15.1" }, "devDependencies": { "get-repo": "^1.0.0",