mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-23 17:00:24 +01:00
closed #322 - autominifying client-side assets on load
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,6 +6,7 @@ npm-debug.log
|
|||||||
node_modules/
|
node_modules/
|
||||||
sftp-config.json
|
sftp-config.json
|
||||||
config.json
|
config.json
|
||||||
|
public/src/nodebb.min.js
|
||||||
public/config.json
|
public/config.json
|
||||||
public/css/*.css
|
public/css/*.css
|
||||||
public/themes/*
|
public/themes/*
|
||||||
|
|||||||
29
app.js
29
app.js
@@ -26,6 +26,8 @@
|
|||||||
var fs = require('fs'),
|
var fs = require('fs'),
|
||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
pkg = require('./package.json'),
|
pkg = require('./package.json'),
|
||||||
|
path = require('path'),
|
||||||
|
uglifyjs = require('uglify-js'),
|
||||||
meta;
|
meta;
|
||||||
|
|
||||||
// Runtime environment
|
// Runtime environment
|
||||||
@@ -69,6 +71,33 @@
|
|||||||
winston.info('Base Configuration OK.');
|
winston.info('Base Configuration OK.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Minify JS
|
||||||
|
var toMinify = [
|
||||||
|
'/vendor/jquery/js/jquery-ui-1.10.3.custom.min.js',
|
||||||
|
'/vendor/jquery/js/jquery.timeago.js',
|
||||||
|
'/vendor/bootstrap/js/bootstrap.min.js',
|
||||||
|
'/src/app.js',
|
||||||
|
'/vendor/requirejs/require.js',
|
||||||
|
'/vendor/bootbox/bootbox.min.js',
|
||||||
|
'/src/templates.js',
|
||||||
|
'/src/ajaxify.js',
|
||||||
|
'/src/jquery.form.js',
|
||||||
|
'/src/utils.js'
|
||||||
|
],
|
||||||
|
minified;
|
||||||
|
toMinify = toMinify.map(function (jsPath) {
|
||||||
|
return path.join(__dirname + '/public', jsPath);
|
||||||
|
});
|
||||||
|
minified = uglifyjs.minify(toMinify);
|
||||||
|
fs.writeFile(path.join(__dirname, '/public/src', 'nodebb.min.js'), minified.code, function (err) {
|
||||||
|
if (!err) {
|
||||||
|
winston.info('Minified client-side libraries');
|
||||||
|
} else {
|
||||||
|
winston.error('Problem minifying client-side libraries, exiting.');
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
meta.configs.init(function () {
|
meta.configs.init(function () {
|
||||||
// Initial setup for Redis & Reds
|
// Initial setup for Redis & Reds
|
||||||
var reds = require('reds'),
|
var reds = require('reds'),
|
||||||
|
|||||||
@@ -9,23 +9,14 @@
|
|||||||
var RELATIVE_PATH = "{relative_path}";
|
var RELATIVE_PATH = "{relative_path}";
|
||||||
</script>
|
</script>
|
||||||
<script src="http://code.jquery.com/jquery.js"></script>
|
<script src="http://code.jquery.com/jquery.js"></script>
|
||||||
<script src="{relative_path}/vendor/jquery/js/jquery-ui-1.10.3.custom.min.js"></script>
|
|
||||||
<script src="{relative_path}/vendor/jquery/js/jquery.timeago.js"></script>
|
|
||||||
<script src="{relative_path}/vendor/bootstrap/js/bootstrap.min.js"></script>
|
|
||||||
<script src="{relative_path}/socket.io/socket.io.js"></script>
|
<script src="{relative_path}/socket.io/socket.io.js"></script>
|
||||||
<script src="{relative_path}/src/app.js"></script>
|
<script src="{relative_path}/src/nodebb.min.js"></script>
|
||||||
<script src="{relative_path}/vendor/requirejs/require.js"></script>
|
|
||||||
<script src="{relative_path}/vendor/bootbox/bootbox.min.js"></script>
|
|
||||||
<script>
|
<script>
|
||||||
require.config({
|
require.config({
|
||||||
baseUrl: "{relative_path}/src/modules",
|
baseUrl: "{relative_path}/src/modules",
|
||||||
waitSeconds: 3
|
waitSeconds: 3
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<script src="{relative_path}/src/templates.js"></script>
|
|
||||||
<script src="{relative_path}/src/ajaxify.js"></script>
|
|
||||||
<script src="{relative_path}/src/jquery.form.js"></script>
|
|
||||||
<script src="{relative_path}/src/utils.js"></script>
|
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="{relative_path}/css/nodebb.css" />
|
<link rel="stylesheet" type="text/css" href="{relative_path}/css/nodebb.css" />
|
||||||
|
|
||||||
|
|||||||
@@ -48,20 +48,14 @@ var express = require('express'),
|
|||||||
metaString = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || [])),
|
metaString = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || [])),
|
||||||
templateValues = {
|
templateValues = {
|
||||||
cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
|
cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
|
||||||
title: meta.config['title'] || 'NodeBB',
|
title: meta.config.title || 'NodeBB',
|
||||||
browserTitle: meta.config['title'] || 'NodeBB',
|
browserTitle: meta.config.title || 'NodeBB',
|
||||||
csrf: options.res.locals.csrf_token,
|
csrf: options.res.locals.csrf_token,
|
||||||
relative_path: nconf.get('relative_path'),
|
relative_path: nconf.get('relative_path'),
|
||||||
meta_tags: metaString
|
meta_tags: metaString
|
||||||
};
|
};
|
||||||
|
|
||||||
// meta.build_title(options.title, (options.req.user ? options.req.user.uid : 0), function(err, title) {
|
callback(null, templates.header.parse(templateValues));
|
||||||
// if (!err) templateValues.browserTitle = title;
|
|
||||||
|
|
||||||
// callback(null, templates['header'].parse(templateValues));
|
|
||||||
// });
|
|
||||||
|
|
||||||
callback(null, templates['header'].parse(templateValues));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Middlewares
|
// Middlewares
|
||||||
|
|||||||
Reference in New Issue
Block a user