mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
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.
This commit is contained in:
@@ -28,7 +28,6 @@
|
||||
<script>
|
||||
var RELATIVE_PATH = "{relative_path}";
|
||||
</script>
|
||||
<script src="{relative_path}/socket.io/socket.io.js"></script>
|
||||
<!-- BEGIN clientScripts -->
|
||||
<script src="{relative_path}/{clientScripts.script}?{cache-buster}"></script>
|
||||
<!-- END clientScripts -->
|
||||
|
||||
34
src/meta.js
34
src/meta.js
@@ -250,6 +250,7 @@ var fs = require('fs'),
|
||||
jsPaths = scripts.map(function (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') {
|
||||
var matches = _.map(plugins.staticDirs, function(realPath, 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 });
|
||||
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
callback(null, [
|
||||
Meta.js.minFile
|
||||
]);
|
||||
} else {
|
||||
callback(null, scripts);
|
||||
}
|
||||
// Add socket.io client library
|
||||
Meta.js.scripts.push(path.join(__dirname, '../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js'));
|
||||
|
||||
// Add plugin scripts
|
||||
Meta.js.scripts = Meta.js.scripts.concat(plugins.clientScripts);
|
||||
|
||||
callback(null, [
|
||||
Meta.js.minFile
|
||||
]);
|
||||
});
|
||||
},
|
||||
minify: function (callback) {
|
||||
@@ -294,6 +298,22 @@ var fs = require('fs'),
|
||||
minified = uglifyjs.minify(jsPaths);
|
||||
this.cache = minified.code;
|
||||
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.cssFiles = [];
|
||||
Plugins.lessFiles = [];
|
||||
Plugins.clientScripts = [];
|
||||
|
||||
Plugins.initialized = false;
|
||||
|
||||
|
||||
@@ -45,12 +45,22 @@ var path = require('path'),
|
||||
});
|
||||
|
||||
app.get('/nodebb.min.js', function(req, res) {
|
||||
var sendCached = function() {
|
||||
return res.type('text/javascript').send(meta.js.cache);
|
||||
}
|
||||
if (meta.js.cache) {
|
||||
res.type('text/javascript').send(meta.js.cache);
|
||||
sendCached();
|
||||
} else {
|
||||
meta.js.minify(function() {
|
||||
res.type('text/javascript').send(meta.js.cache);
|
||||
});
|
||||
if (app.enabled('minification')) {
|
||||
meta.js.minify(function() {
|
||||
sendCached();
|
||||
});
|
||||
} else {
|
||||
// Compress only
|
||||
meta.js.compress(function() {
|
||||
sendCached();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user