mirror of
https://github.com/seejohnrun/haste-server
synced 2025-07-15 01:23:48 -07:00
Auto-compress javascript assets
This commit is contained in:
parent
d3ba2e4b5b
commit
0875ba6252
7 changed files with 28 additions and 4 deletions
20
server.js
20
server.js
|
@ -37,6 +37,26 @@ if (!config.storage.type) {
|
|||
var Store = require('./lib/' + config.storage.type + '_document_store');
|
||||
var preferredStore = new Store(config.storage);
|
||||
|
||||
// Compress the static javascript assets
|
||||
if (config.recompressStaticAssets) {
|
||||
var jsp = require("uglify-js").parser;
|
||||
var pro = require("uglify-js").uglify;
|
||||
var list = fs.readdirSync('./static');
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
var item = list[i];
|
||||
var orig_code, ast;
|
||||
if ((item.indexOf('.js') === item.length - 3) && (item.indexOf('.min.js') === -1)) {
|
||||
dest = item.substring(0, item.length - 3) + '.min' + item.substring(item.length - 3);
|
||||
orig_code = fs.readFileSync('./static/' + item, 'utf8');
|
||||
ast = jsp.parse(orig_code);
|
||||
ast = pro.ast_mangle(ast);
|
||||
ast = pro.ast_squeeze(ast);
|
||||
fs.writeFileSync('./static/' + dest, pro.gen_code(ast), 'utf8');
|
||||
winston.info('compressed ' + item + ' into ' + dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send the static documents into the preferred store, skipping expirations
|
||||
for (var name in config.documents) {
|
||||
var path = config.documents[name];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue