Skip to content
Snippets Groups Projects
Commit d5634cfe authored by Austin King's avatar Austin King
Browse files

A slight tweak on https://gist.github.com/1849619 cachify CSS while compressing it. Fixes Issue 620

parent 88d35b4e
No related branches found
No related tags found
No related merge requests found
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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment