bundling socket.io client library into minfile, minfile always used from this point forward, even in development mode.

Development mode will not compress the scripts, but will just concatenate.
v1.18.x
Julian Lam 11 years ago
parent 033c5d5726
commit 14d7453a23

@ -28,7 +28,6 @@
<script> <script>
var RELATIVE_PATH = "{relative_path}"; var RELATIVE_PATH = "{relative_path}";
</script> </script>
<script src="{relative_path}/socket.io/socket.io.js"></script>
<!-- BEGIN clientScripts --> <!-- BEGIN clientScripts -->
<script src="{relative_path}/{clientScripts.script}?{cache-buster}"></script> <script src="{relative_path}/{clientScripts.script}?{cache-buster}"></script>
<!-- END clientScripts --> <!-- END clientScripts -->

@ -250,6 +250,7 @@ var fs = require('fs'),
jsPaths = scripts.map(function (jsPath) { jsPaths = scripts.map(function (jsPath) {
jsPath = path.normalize(jsPath); jsPath = path.normalize(jsPath);
// The filter:scripts.get plugin will be deprecated as of v0.5.0, specify scripts in plugin.json instead
if (jsPath.substring(0, 7) === 'plugins') { if (jsPath.substring(0, 7) === 'plugins') {
var matches = _.map(plugins.staticDirs, function(realPath, mappedPath) { var matches = _.map(plugins.staticDirs, function(realPath, mappedPath) {
if (jsPath.match(mappedPath)) { if (jsPath.match(mappedPath)) {
@ -271,15 +272,18 @@ var fs = require('fs'),
} }
}); });
// Remove scripts that could not be found (remove this line at v0.5.0)
Meta.js.scripts = jsPaths.filter(function(path) { return path !== null }); Meta.js.scripts = jsPaths.filter(function(path) { return path !== null });
if (process.env.NODE_ENV !== 'development') { // Add socket.io client library
callback(null, [ Meta.js.scripts.push(path.join(__dirname, '../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js'));
Meta.js.minFile
]); // Add plugin scripts
} else { Meta.js.scripts = Meta.js.scripts.concat(plugins.clientScripts);
callback(null, scripts);
} callback(null, [
Meta.js.minFile
]);
}); });
}, },
minify: function (callback) { minify: function (callback) {
@ -294,6 +298,22 @@ var fs = require('fs'),
minified = uglifyjs.minify(jsPaths); minified = uglifyjs.minify(jsPaths);
this.cache = minified.code; this.cache = minified.code;
callback(); callback();
},
compress: function(callback) {
var uglifyjs = require('uglify-js'),
jsPaths = this.scripts,
compressed;
if (process.env.NODE_ENV === 'development') {
winston.info('Compressing client-side libraries into one file');
}
minified = uglifyjs.minify(jsPaths, {
mangle: false,
compress: false
});
this.cache = minified.code;
callback();
} }
}; };

@ -17,6 +17,7 @@ var fs = require('fs'),
Plugins.staticDirs = {}; Plugins.staticDirs = {};
Plugins.cssFiles = []; Plugins.cssFiles = [];
Plugins.lessFiles = []; Plugins.lessFiles = [];
Plugins.clientScripts = [];
Plugins.initialized = false; Plugins.initialized = false;

@ -45,12 +45,22 @@ var path = require('path'),
}); });
app.get('/nodebb.min.js', function(req, res) { app.get('/nodebb.min.js', function(req, res) {
var sendCached = function() {
return res.type('text/javascript').send(meta.js.cache);
}
if (meta.js.cache) { if (meta.js.cache) {
res.type('text/javascript').send(meta.js.cache); sendCached();
} else { } else {
meta.js.minify(function() { if (app.enabled('minification')) {
res.type('text/javascript').send(meta.js.cache); meta.js.minify(function() {
}); sendCached();
});
} else {
// Compress only
meta.js.compress(function() {
sendCached();
});
}
} }
}); });
}; };

Loading…
Cancel
Save