v1.18.x
Julian Lam 11 years ago
parent f3a78c2b6f
commit 7a993eb2ca

@ -10,31 +10,31 @@ var uglifyjs = require('uglify-js'),
/* Javascript */
Minifier.js.minify = function (scripts, callback) {
// winston.info('[meta/js] Minifying client-side libraries...');
var minified = uglifyjs.minify(scripts);
callback(minified.code);
// winston.info('[meta/js] Done.');
try {
var minified = uglifyjs.minify(scripts);
callback(minified.code);
} catch(err) {
process.send({
action: 'error',
error: err
});
}
};
Minifier.js.concatenate = function(scripts, callback) {
// winston.info('[meta/js] Concatenating client-side libraries into one file...');
async.map(scripts, function(path, next) {
fs.readFile(path, { encoding: 'utf-8' }, next);
}, function(err, contents) {
if (err) {
// winston.error('[meta/js] Could not minify javascript! Error: ' + err.message);
console.log('ERROR');
process.exit();
process.send({
action: 'error',
error: err
});
} else {
callback(contents.reduce(function(output, src) {
return output.length ? output + ';\n' + src : src;
}, ''));
}
callback(contents.reduce(function(output, src) {
return output.length ? output + ';\n' + src : src;
}, ''));
// winston.info('[meta/js] Done.');
});
};

@ -3,13 +3,13 @@
(function(ajaxify) {
ajaxify.widgets = {};
ajaxify.widgets.reposition = function(location) {
$('body [no-widget-class]').each(function() {
var $this = $(this);
if ($this.attr('no-widget-target') === location) {
$this.removeClass();
$this.addClass($this.attr('no-widget-class'));
$this.addClass($this.attr('no-widget-class'));
}
});
};

@ -7,6 +7,7 @@ var fs = require('fs'),
nconf = require('nconf'),
_ = require('underscore'),
less = require('less'),
fork = require('child_process').fork,
utils = require('./../public/src/utils'),
translator = require('./../public/src/translator'),
@ -292,6 +293,30 @@ var fs = require('fs'),
Meta.js.prepared = true;
callback();
});
},
minify: function(minify) {
// Prepare js for minification/concatenation
var minifier = fork('minifier.js');
minifier.on('message', function(payload) {
if (payload.action !== 'error') {
winston.info('[meta/js] Compilation complete');
Meta.js.cache = payload.data;
minifier.kill();
} else {
winston.error('[meta/js] Could not compile client-side scripts!');
winston.error('[meta/js] ' + payload.error.message);
minifier.kill();
process.exit();
}
});
this.prepare(function() {
minifier.send({
action: minify ? 'js.minify' : 'js.concatenate',
scripts: Meta.js.scripts
});
});
}
};

@ -7,7 +7,6 @@ var path = require('path'),
server,
winston = require('winston'),
async = require('async'),
fork = require('child_process').fork,
emailer = require('./emailer'),
db = require('./database'),
@ -90,28 +89,9 @@ if(nconf.get('ssl')) {
winston.info('Using ports 80 and 443 is not recommend; use a proxy instead. See README.md');
}
// Front-end assets
plugins.ready(function() {
// Prepare js for minification/concatenation
var minifier = fork('minifier.js');
minifier.on('message', function(payload) {
switch(payload.action) {
case 'js.minify': // Intentional fall-through
case 'js.concatenate':
winston.info('[meta/js] Compilation complete');
meta.js.cache = payload.data;
break;
}
});
meta.js.prepare(function() {
minifier.send({
action: app.enabled('minification') ? 'js.minify' : 'js.concatenate',
scripts: meta.js.scripts
});
});
// Minify CSS
meta.js.minify(app.enabled('minification'));
meta.css.minify();
});

Loading…
Cancel
Save