diff --git a/scripts/compress-worker.js b/scripts/compress-worker.js index 0cf43ce21f143f5a9a9af75cc387babd7a4687aa..3bcb9084eefe66be2a79a346f1f10241f7a7afff 100644 --- a/scripts/compress-worker.js +++ b/scripts/compress-worker.js @@ -1,6 +1,8 @@ const +cachify = require('connect-cachify'), fs = require('fs'), jsp = require("uglify-js").parser, +logger = require('../lib/logging.js').logger, pro = require("uglify-js").uglify, uglifycss = require('uglifycss'), mkdirp = require('mkdirp'), @@ -31,7 +33,8 @@ function compressResource(staticPath, name, files, cb) { final_code = pro.split_lines(pro.gen_code(ast), 32 * 1024); // compressed code here } else if (/\.css$/.test(name)) { // compress css - final_code = uglifycss.processString(orig_code); + var cach_code = cachify_embedded(orig_code); + final_code = uglifycss.processString(cach_code); } else { return cb("can't determine content type: " + name); } @@ -78,6 +81,20 @@ function compressResource(staticPath, name, files, cb) { isBuildNeeded(); } +var static_root = path.join(__dirname, '..', 'resources/static/'); +logger.info("cachify will look in " + static_root); +// Cachify only used in compress for CSS Images, so no asserts needed +cachify.setup({}, { root: static_root}); + +function cachify_embedded (css_src) { + return css_src.replace(/url\s*\(['"](.*)\s*['"]\s*\)/g, function (str, url) { + // This will throw an error if url doesn't exist. This is good as we will + // catch typos during build. + logger.info("For " + str + " making " + url + " into " + cachify.cachify(url)); + return "url('" + cachify.cachify(url) + "')"; + }); +} + process.on('message', function(m) { var startTime = new Date;