mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 02:25:55 +01:00
added new --from-file flag that will load js/css from the precompiled file instead of recompiling it on startup
This commit is contained in:
@@ -14,7 +14,10 @@ var uglifyjs = require('uglify-js'),
|
||||
/* Javascript */
|
||||
Minifier.js.minify = function (scripts, relativePath, minify, callback) {
|
||||
var options = {
|
||||
compress: false
|
||||
compress: false,
|
||||
sourceMapURL: '/nodebb.min.js.map',
|
||||
outSourceMap: 'nodebb.min.js.map',
|
||||
sourceRoot: relativePath
|
||||
};
|
||||
|
||||
scripts = scripts.filter(function(file) {
|
||||
@@ -22,9 +25,6 @@ Minifier.js.minify = function (scripts, relativePath, minify, callback) {
|
||||
});
|
||||
|
||||
if (!minify) {
|
||||
options.sourceMapURL = '/nodebb.min.js.map';
|
||||
options.outSourceMap = 'nodebb.min.js.map';
|
||||
options.sourceRoot = relativePath;
|
||||
options.mangle = false;
|
||||
options.prefix = 1;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ var async = require('async'),
|
||||
};
|
||||
|
||||
Meta.reload = function(callback) {
|
||||
console.log('reloading');
|
||||
async.series([
|
||||
async.apply(plugins.clearRequireCache),
|
||||
async.apply(plugins.reload),
|
||||
@@ -40,6 +41,7 @@ var async = require('async'),
|
||||
async.parallel([
|
||||
async.apply(Meta.js.minify, false),
|
||||
async.apply(Meta.css.minify),
|
||||
async.apply(Meta.sounds.init),
|
||||
async.apply(Meta.templates.compile),
|
||||
async.apply(auth.reloadRoutes),
|
||||
function(next) {
|
||||
@@ -49,6 +51,7 @@ var async = require('async'),
|
||||
], next);
|
||||
}
|
||||
], function(err) {
|
||||
console.log('yaaa I am here', err);
|
||||
if (!err) {
|
||||
emitter.emit('nodebb:ready');
|
||||
}
|
||||
|
||||
@@ -99,6 +99,30 @@ module.exports = function(Meta) {
|
||||
});
|
||||
};
|
||||
|
||||
Meta.css.getFromFile = function(callback) {
|
||||
var cachePath = path.join(__dirname, '../../public/stylesheet.css'),
|
||||
acpCachePath = path.join(__dirname, '../../public/admin.css');
|
||||
fs.exists(cachePath, function(exists) {
|
||||
if (exists) {
|
||||
if (!cluster.isWorker || process.env.cluster_setup === 'true') {
|
||||
winston.info('[meta/css] (Experimental) Reading stylesheets from file');
|
||||
async.map([cachePath, acpCachePath], fs.readFile, function(err, files) {
|
||||
Meta.css.cache = files[0];
|
||||
Meta.css.acpCache = files[1];
|
||||
|
||||
emitter.emit('meta:css.compiled');
|
||||
callback();
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
} else {
|
||||
winston.warn('[meta/css] (Experimental) No stylesheets found on disk, re-minifying');
|
||||
Meta.css.minify.apply(Meta.css, arguments);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function minify(source, paths, destination, callback) {
|
||||
var parser = new (less.Parser)({
|
||||
paths: paths
|
||||
|
||||
@@ -208,6 +208,30 @@ module.exports = function(Meta) {
|
||||
});
|
||||
};
|
||||
|
||||
Meta.js.getFromFile = function(minify, callback) {
|
||||
var scriptPath = path.join(__dirname, '../../public/nodebb.min.js'),
|
||||
mapPath = path.join(__dirname, '../../public/nodebb.min.js.map');
|
||||
fs.exists(scriptPath, function(exists) {
|
||||
if (exists) {
|
||||
if (!cluster.isWorker || process.env.cluster_setup === 'true') {
|
||||
winston.info('[meta/js] (Experimental) Reading client-side scripts from file');
|
||||
async.map([scriptPath, mapPath], fs.readFile, function(err, files) {
|
||||
Meta.js.cache = files[0];
|
||||
Meta.js.map = files[1];
|
||||
|
||||
emitter.emit('meta:js.compiled');
|
||||
callback();
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
} else {
|
||||
winston.warn('[meta/js] (Experimental) No script file found on disk, re-minifying');
|
||||
Meta.js.minify.apply(Meta.js, arguments);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function getPluginScripts(callback) {
|
||||
plugins.fireHook('filter:scripts.get', [], function(err, scripts) {
|
||||
if (err) {
|
||||
|
||||
@@ -7,6 +7,7 @@ var path = require('path'),
|
||||
rimraf = require('rimraf'),
|
||||
mkdirp = require('mkdirp'),
|
||||
async = require('async'),
|
||||
cluster = require('cluster'),
|
||||
|
||||
plugins = require('../plugins'),
|
||||
db = require('../database');
|
||||
@@ -15,7 +16,8 @@ module.exports = function(Meta) {
|
||||
|
||||
Meta.sounds = {};
|
||||
|
||||
Meta.sounds.init = function() {
|
||||
Meta.sounds.init = function(callback) {
|
||||
if (cluster.isWorker && process.env.cluster_setup === 'true') {
|
||||
var soundsPath = path.join(__dirname, '../../public/sounds');
|
||||
|
||||
plugins.fireHook('filter:sounds.get', [], function(err, filePaths) {
|
||||
@@ -47,9 +49,18 @@ module.exports = function(Meta) {
|
||||
} else {
|
||||
winston.error('[sounds] Could not initialise sounds: ' + err.message);
|
||||
}
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Meta.sounds.getFiles = function(callback) {
|
||||
|
||||
@@ -88,7 +88,7 @@ Templates.compile = function(callback) {
|
||||
if (paths[partial] && relativePath !== partial) {
|
||||
file = file.replace(regex, fs.readFileSync(paths[partial]).toString());
|
||||
} else {
|
||||
winston.warn('[themes] Partial not loaded: ' + matches[1]);
|
||||
winston.warn('[meta/templates] Partial not loaded: ' + matches[1]);
|
||||
file = file.replace(regex, "");
|
||||
}
|
||||
}
|
||||
@@ -101,10 +101,10 @@ Templates.compile = function(callback) {
|
||||
fs.writeFile(path.join(viewsPath, relativePath), file, next);
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
winston.error('[themes] ' + err.stack);
|
||||
winston.error('[meta/templates] ' + err.stack);
|
||||
} else {
|
||||
compileIndex(viewsPath, function() {
|
||||
winston.info('[themes] Successfully compiled templates.');
|
||||
winston.info('[meta/templates] Successfully compiled templates.');
|
||||
emitter.emit('templates:compiled');
|
||||
if (callback) {
|
||||
callback();
|
||||
|
||||
@@ -46,12 +46,11 @@ if(nconf.get('ssl')) {
|
||||
|
||||
// Preparation dependent on plugins
|
||||
plugins.ready(function() {
|
||||
meta.js.minify(app.enabled('minification'));
|
||||
meta.css.minify();
|
||||
|
||||
if (cluster.isWorker && process.env.cluster_setup === 'true') {
|
||||
meta.sounds.init();
|
||||
}
|
||||
async.parallel([
|
||||
async.apply(!nconf.get('from-file') ? meta.js.minify : meta.js.getFromFile, app.enabled('minification')),
|
||||
async.apply(!nconf.get('from-file') ? meta.css.minify : meta.css.getFromFile),
|
||||
async.apply(meta.sounds.init)
|
||||
]);
|
||||
});
|
||||
|
||||
async.parallel({
|
||||
|
||||
Reference in New Issue
Block a user