diff options
author | Stefan <stefan@stefans-entwicklerecke.de> | 2016-12-20 22:06:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-20 22:06:31 +0100 |
commit | a1ec06101747065e0ae6f252179984d9da0b5424 (patch) | |
tree | 02b1941e8ee4ae93d4964f87fefc3131b22aa68a /src/node | |
parent | db21a25eff5dfb86062508deb8f9f4aa395b30af (diff) | |
parent | 0a9d02562d7e14ecc9f9f1d929a65cc64924857a (diff) | |
download | etherpad-lite-a1ec06101747065e0ae6f252179984d9da0b5424.zip |
Merge pull request #3053 from danfuzz/fix-timeslider-lists
Fix timeslider lists / indents, but also make CSS `@import` work
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/utils/Minify.js | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/src/node/utils/Minify.js b/src/node/utils/Minify.js index ee8f5f45..80652310 100644 --- a/src/node/utils/Minify.js +++ b/src/node/utils/Minify.js @@ -1,7 +1,7 @@ /** - * This Module manages all /minified/* requests. It controls the - * minification && compression of Javascript and CSS. - */ + * This Module manages all /minified/* requests. It controls the + * minification && compression of Javascript and CSS. + */ /* * 2011 Peter 'Pita' Martischka (Primary Technology Ltd) @@ -151,7 +151,7 @@ function minify(req, res, next) } else { res.writeHead(404, {}); res.end(); - return; + return; } /* Handle static files for plugins/libraries: @@ -371,21 +371,19 @@ function requireDefinition() { function getFileCompressed(filename, contentType, callback) { getFile(filename, function (error, content) { - if (error || !content) { + if (error || !content || !settings.minify) { callback(error, content); - } else { - if (settings.minify) { - if (contentType == 'text/javascript') { - try { - content = compressJS([content]); - } catch (error) { - // silence - } - } else if (contentType == 'text/css') { - content = compressCSS([content]); - } + } else if (contentType == 'text/javascript') { + try { + content = compressJS(content); + } catch (error) { + // silence } callback(null, content); + } else if (contentType == 'text/css') { + compressCSS(filename, content, callback); + } else { + callback(null, content); } }); } @@ -400,20 +398,30 @@ function getFile(filename, callback) { } } -function compressJS(values) +function compressJS(content) { - var complete = values.join("\n"); - var ast = jsp.parse(complete); // parse code and get the initial AST + var ast = jsp.parse(content); // parse code and get the initial AST ast = pro.ast_mangle(ast); // get a new AST with mangled names ast = pro.ast_squeeze(ast); // get an AST with compression optimizations return pro.gen_code(ast); // compressed code here } -function compressCSS(values) +function compressCSS(filename, content, callback) { - var complete = values.join("\n"); - var minimized = new CleanCSS().minify(complete).styles; - return minimized; + try { + var base = path.join(ROOT_DIR, path.dirname(filename)); + new CleanCSS({relativeTo: base}).minify(content, function (errors, minified) { + if (errors) { + // On error, just yield the un-minified original. + callback(null, content); + } else { + callback(null, minified.styles); + } + }); + } catch (error) { + // On error, just yield the un-minified original. + callback(null, content); + } } exports.minify = minify; |