Skip to content

Node.js based forum software built for the modern web

concatenating the client scripts, instead of compressing, in development mode

Julian Lam4c2a6953f188
diff --git a/src/meta.js b/src/meta.js
index 2108cc277c..2c3b6c66f3 100644
--- a/src/meta.js
+++ b/src/meta.js
@@ -299,21 +299,24 @@ var fs = require('fs'),
this.cache = minified.code;
callback();
},
- compress: function(callback) {
- var uglifyjs = require('uglify-js'),
- jsPaths = this.scripts,
- compressed;
-
+ concatenate: function(callback) {
if (process.env.NODE_ENV === 'development') {
- winston.info('Compressing client-side libraries into one file');
+ winston.info('Concatenating client-side libraries into one file');
}
- minified = uglifyjs.minify(jsPaths, {
- mangle: false,
- compress: false
+ async.map(this.scripts, function(path, next) {
+ fs.readFile(path, { encoding: 'utf-8' }, next);
+ }, function(err, contents) {
+ if (err) {
+ winston.error('[meta.js.concatenate] Could not minify javascript! Error: ' + err.message);
+ process.exit();
+ }
+
+ Meta.js.cache = contents.reduce(function(output, src) {
+ return output.length ? output + ';\n' + src : src;
+ }, '');
+ callback();
});
- this.cache = minified.code;
- callback();
}
};
diff --git a/src/routes/meta.js b/src/routes/meta.js
index 0a09074b2c..cc5683b924 100644
--- a/src/routes/meta.js
+++ b/src/routes/meta.js
@@ -57,7 +57,7 @@ var path = require('path'),
});
} else {
// Compress only
- meta.js.compress(function() {
+ meta.js.concatenate(function() {
sendCached();
});
}