mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +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 */
|
/* Javascript */
|
||||||
Minifier.js.minify = function (scripts, relativePath, minify, callback) {
|
Minifier.js.minify = function (scripts, relativePath, minify, callback) {
|
||||||
var options = {
|
var options = {
|
||||||
compress: false
|
compress: false,
|
||||||
|
sourceMapURL: '/nodebb.min.js.map',
|
||||||
|
outSourceMap: 'nodebb.min.js.map',
|
||||||
|
sourceRoot: relativePath
|
||||||
};
|
};
|
||||||
|
|
||||||
scripts = scripts.filter(function(file) {
|
scripts = scripts.filter(function(file) {
|
||||||
@@ -22,9 +25,6 @@ Minifier.js.minify = function (scripts, relativePath, minify, callback) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!minify) {
|
if (!minify) {
|
||||||
options.sourceMapURL = '/nodebb.min.js.map';
|
|
||||||
options.outSourceMap = 'nodebb.min.js.map';
|
|
||||||
options.sourceRoot = relativePath;
|
|
||||||
options.mangle = false;
|
options.mangle = false;
|
||||||
options.prefix = 1;
|
options.prefix = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ var async = require('async'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
Meta.reload = function(callback) {
|
Meta.reload = function(callback) {
|
||||||
|
console.log('reloading');
|
||||||
async.series([
|
async.series([
|
||||||
async.apply(plugins.clearRequireCache),
|
async.apply(plugins.clearRequireCache),
|
||||||
async.apply(plugins.reload),
|
async.apply(plugins.reload),
|
||||||
@@ -40,6 +41,7 @@ var async = require('async'),
|
|||||||
async.parallel([
|
async.parallel([
|
||||||
async.apply(Meta.js.minify, false),
|
async.apply(Meta.js.minify, false),
|
||||||
async.apply(Meta.css.minify),
|
async.apply(Meta.css.minify),
|
||||||
|
async.apply(Meta.sounds.init),
|
||||||
async.apply(Meta.templates.compile),
|
async.apply(Meta.templates.compile),
|
||||||
async.apply(auth.reloadRoutes),
|
async.apply(auth.reloadRoutes),
|
||||||
function(next) {
|
function(next) {
|
||||||
@@ -49,6 +51,7 @@ var async = require('async'),
|
|||||||
], next);
|
], next);
|
||||||
}
|
}
|
||||||
], function(err) {
|
], function(err) {
|
||||||
|
console.log('yaaa I am here', err);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
emitter.emit('nodebb:ready');
|
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) {
|
function minify(source, paths, destination, callback) {
|
||||||
var parser = new (less.Parser)({
|
var parser = new (less.Parser)({
|
||||||
paths: paths
|
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) {
|
function getPluginScripts(callback) {
|
||||||
plugins.fireHook('filter:scripts.get', [], function(err, scripts) {
|
plugins.fireHook('filter:scripts.get', [], function(err, scripts) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ var path = require('path'),
|
|||||||
rimraf = require('rimraf'),
|
rimraf = require('rimraf'),
|
||||||
mkdirp = require('mkdirp'),
|
mkdirp = require('mkdirp'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
|
cluster = require('cluster'),
|
||||||
|
|
||||||
plugins = require('../plugins'),
|
plugins = require('../plugins'),
|
||||||
db = require('../database');
|
db = require('../database');
|
||||||
@@ -15,7 +16,8 @@ module.exports = function(Meta) {
|
|||||||
|
|
||||||
Meta.sounds = {};
|
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');
|
var soundsPath = path.join(__dirname, '../../public/sounds');
|
||||||
|
|
||||||
plugins.fireHook('filter:sounds.get', [], function(err, filePaths) {
|
plugins.fireHook('filter:sounds.get', [], function(err, filePaths) {
|
||||||
@@ -47,9 +49,18 @@ module.exports = function(Meta) {
|
|||||||
} else {
|
} else {
|
||||||
winston.error('[sounds] Could not initialise sounds: ' + err.message);
|
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) {
|
Meta.sounds.getFiles = function(callback) {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ Templates.compile = function(callback) {
|
|||||||
if (paths[partial] && relativePath !== partial) {
|
if (paths[partial] && relativePath !== partial) {
|
||||||
file = file.replace(regex, fs.readFileSync(paths[partial]).toString());
|
file = file.replace(regex, fs.readFileSync(paths[partial]).toString());
|
||||||
} else {
|
} else {
|
||||||
winston.warn('[themes] Partial not loaded: ' + matches[1]);
|
winston.warn('[meta/templates] Partial not loaded: ' + matches[1]);
|
||||||
file = file.replace(regex, "");
|
file = file.replace(regex, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,10 +101,10 @@ Templates.compile = function(callback) {
|
|||||||
fs.writeFile(path.join(viewsPath, relativePath), file, next);
|
fs.writeFile(path.join(viewsPath, relativePath), file, next);
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
winston.error('[themes] ' + err.stack);
|
winston.error('[meta/templates] ' + err.stack);
|
||||||
} else {
|
} else {
|
||||||
compileIndex(viewsPath, function() {
|
compileIndex(viewsPath, function() {
|
||||||
winston.info('[themes] Successfully compiled templates.');
|
winston.info('[meta/templates] Successfully compiled templates.');
|
||||||
emitter.emit('templates:compiled');
|
emitter.emit('templates:compiled');
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
|
|||||||
@@ -46,12 +46,11 @@ if(nconf.get('ssl')) {
|
|||||||
|
|
||||||
// Preparation dependent on plugins
|
// Preparation dependent on plugins
|
||||||
plugins.ready(function() {
|
plugins.ready(function() {
|
||||||
meta.js.minify(app.enabled('minification'));
|
async.parallel([
|
||||||
meta.css.minify();
|
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),
|
||||||
if (cluster.isWorker && process.env.cluster_setup === 'true') {
|
async.apply(meta.sounds.init)
|
||||||
meta.sounds.init();
|
]);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
|
|||||||
Reference in New Issue
Block a user